-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDIBean.java
47 lines (35 loc) · 1.33 KB
/
CDIBean.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.eg.jmx;
import com.eg.jmx.MBean;
import net.gescobar.jmx.annotation.Description;
import net.gescobar.jmx.annotation.DescriptorFields;
import net.gescobar.jmx.annotation.Impact;
import net.gescobar.jmx.annotation.ManagedAttribute;
import net.gescobar.jmx.annotation.ManagedOperation;
import javax.enterprise.context.ApplicationScoped;
import java.util.concurrent.atomic.AtomicLong;
@ApplicationScoped
@MBean(type = "CDI")
@Description("A simple CDI bean")
public class CDIBean {
private AtomicLong counter = new AtomicLong(0);
@ManagedAttribute(writable = true, readable = true, description = "The internal counter.")
public long getCounter() {
return counter.get();
}
public void setCounter(long value) {
counter.set(value);
}
@ManagedOperation(description = "Increments and returns the new counter value.", impact = Impact.ACTION_INFO)
public long increment() {
return counter.incrementAndGet();
}
@ManagedOperation(description = "Decrements and returns the new counter value.", impact = Impact.ACTION_INFO)
public long decrement() {
return counter.decrementAndGet();
}
@ManagedOperation(description = "Add a delta and return the new counter value.", impact = Impact.ACTION_INFO)
@DescriptorFields({"p0=delta;The delta to subtract."})
public long addAndGet(long delta) {
return counter.addAndGet(delta);
}
}