01: package org.objectweb.celtix.bus.workqueue;
02:
03: import org.objectweb.celtix.bus.management.jmx.export.annotation.ManagedAttribute;
04: import org.objectweb.celtix.bus.management.jmx.export.annotation.ManagedOperation;
05: import org.objectweb.celtix.bus.management.jmx.export.annotation.ManagedResource;
06: import org.objectweb.celtix.management.Instrumentation;
07: import org.objectweb.celtix.workqueue.WorkQueueManager.ThreadingModel;
08:
09: @ManagedResource(componentName="WorkQueue",description="The Celtix bus internal thread pool for manangement ",currencyTimeLimit=15,persistPolicy="OnUpdate",persistPeriod=200)
10: public class WorkQueueInstrumentation implements Instrumentation {
11: private static final String INSTRUMENTED_NAME = "Bus.WorkQueue";
12:
13: private String objectName;
14: private WorkQueueManagerImpl wqManager;
15: private AutomaticWorkQueueImpl aWorkQueue;
16:
17: public WorkQueueInstrumentation(WorkQueueManagerImpl wq) {
18: wqManager = wq;
19: objectName = ",name=WorkQueue";
20: if (wqManager.autoQueue != null
21: && AutomaticWorkQueueImpl.class
22: .isAssignableFrom(wqManager.autoQueue
23: .getClass())) {
24: aWorkQueue = (AutomaticWorkQueueImpl) wqManager.autoQueue;
25: }
26: }
27:
28: @ManagedOperation(currencyTimeLimit=30)
29: public void shutdown(boolean processRemainingWorkItems) {
30: wqManager.shutdown(processRemainingWorkItems);
31: }
32:
33: @ManagedAttribute(description="The thread pool work model",defaultValue="SINGLE_THREADED",persistPolicy="OnUpdate")
34: public String getThreadingModel() {
35: return wqManager.getThreadingModel().toString();
36: }
37:
38: public void setThreadingModel(String model) {
39: if (model.compareTo("SINGLE_THREADED") == 0) {
40: wqManager.setThreadingModel(ThreadingModel.SINGLE_THREADED);
41: }
42: if (model.compareTo("MULTI_THREADED") == 0) {
43: wqManager.setThreadingModel(ThreadingModel.MULTI_THREADED);
44: }
45: }
46:
47: @ManagedAttribute(description="The WorkQueueMaxSize",persistPolicy="OnUpdate")
48: public long getWorkQueueMaxSize() {
49: return aWorkQueue.getMaxSize();
50: }
51:
52: @ManagedAttribute(description="The WorkQueue Current size",persistPolicy="OnUpdate")
53: public long getWorkQueueSize() {
54: return aWorkQueue.getSize();
55: }
56:
57: @ManagedAttribute(description="The WorkQueue has nothing to do",persistPolicy="OnUpdate")
58: public boolean isEmpty() {
59: return aWorkQueue.isEmpty();
60: }
61:
62: @ManagedAttribute(description="The WorkQueue is very busy")
63: public boolean isFull() {
64: return aWorkQueue.isFull();
65: }
66:
67: @ManagedAttribute(description="The WorkQueue HighWaterMark",persistPolicy="OnUpdate")
68: public int getHighWaterMark() {
69: return aWorkQueue.getHighWaterMark();
70: }
71:
72: public void setHighWaterMark(int hwm) {
73: aWorkQueue.setHighWaterMark(hwm);
74: }
75:
76: @ManagedAttribute(description="The WorkQueue LowWaterMark",persistPolicy="OnUpdate")
77: public int getLowWaterMark() {
78: return aWorkQueue.getLowWaterMark();
79: }
80:
81: public void setLowWaterMark(int lwm) {
82: aWorkQueue.setLowWaterMark(lwm);
83: }
84:
85: public Object getComponent() {
86: return wqManager;
87: }
88:
89: public String getInstrumentationName() {
90: return INSTRUMENTED_NAME;
91: }
92:
93: public String getUniqueInstrumentationName() {
94: return objectName;
95: }
96:
97: }
|