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