1 package lv.id.jc.piglatin.actuator;
2
3 import java.util.Map;
4 import java.util.concurrent.atomic.AtomicInteger;
5
6 import org.springframework.beans.factory.annotation.Qualifier;
7 import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
8 import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
9 import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
10 import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
11 import org.springframework.stereotype.Component;
12
13
14
15
16
17 @Component
18 @Endpoint(id = "counter")
19 public class TranslationCountEndpoint {
20
21 private final AtomicInteger counterService;
22
23 public TranslationCountEndpoint(@Qualifier("translationCounter") AtomicInteger counterService) {
24 this.counterService = counterService;
25 }
26
27
28
29
30
31
32
33 @ReadOperation
34 public Map<String, Integer> count() {
35 return Map.of("count", counterService.get());
36 }
37
38
39
40
41
42
43
44
45 @WriteOperation
46 public Map<String, Integer> set(int count) {
47 counterService.set(count);
48 return count();
49 }
50
51
52
53
54 @DeleteOperation
55 public void reset() {
56 counterService.set(0);
57 }
58 }