1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.starter.actuate;
20
21 import java.util.Map;
22 import org.apache.syncope.core.persistence.api.dao.EntityCacheDAO;
23 import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
24 import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
25 import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
26 import org.springframework.boot.actuate.endpoint.annotation.Selector;
27 import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
28 import org.springframework.http.HttpStatus;
29 import org.springframework.web.server.ResponseStatusException;
30
31 @Endpoint(id = "entityCache")
32 public class EntityCacheEndpoint {
33
34 protected final EntityCacheDAO entityCacheDAO;
35
36 public EntityCacheEndpoint(final EntityCacheDAO entityCacheDAO) {
37 this.entityCacheDAO = entityCacheDAO;
38 }
39
40 @ReadOperation
41 public Map<String, Object> statistics() {
42 return entityCacheDAO.getStatistics();
43 }
44
45 @WriteOperation
46 public void statistics(final @Selector String operation) {
47 switch (operation) {
48 case "enable":
49 case "ENABLE":
50 entityCacheDAO.enableStatistics();
51 break;
52
53 case "disable":
54 case "DISABLE":
55 entityCacheDAO.disableStatistics();
56 break;
57
58 case "reset":
59 case "RESET":
60 entityCacheDAO.resetStatistics();
61 break;
62
63 default:
64 throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Unsupported Operation: " + operation);
65 }
66 }
67
68 @DeleteOperation
69 public void clearCache() {
70 entityCacheDAO.clearCache();
71 }
72 }