1 package org.oddjob.jmx.server; 2 3 import javax.management.MBeanAttributeInfo ; 4 import javax.management.MBeanException ; 5 import javax.management.MBeanNotificationInfo ; 6 import javax.management.MBeanOperationInfo ; 7 import javax.management.MBeanParameterInfo ; 8 import javax.management.Notification ; 9 import javax.management.ReflectionException ; 10 11 13 public class RunnableInfo implements InterfaceInfo { 14 15 public Class interfaceClass() { 16 return Runnable .class; 17 } 18 19 public MBeanAttributeInfo [] getMBeanAttributeInfo() { 20 return new MBeanAttributeInfo [0]; 21 } 22 23 public MBeanOperationInfo [] getMBeanOperationInfo() { 24 return new MBeanOperationInfo [] { 25 new MBeanOperationInfo ("run", "Execute the job.", 26 new MBeanParameterInfo [0], Void.TYPE.getName(), 27 MBeanOperationInfo.ACTION) 28 }; 29 } 30 31 public MBeanNotificationInfo [] getMBeanNotificationInfo() { 32 return new MBeanNotificationInfo [0]; 33 } 34 35 36 public InterfaceHandler attach(Object target, OddjobMBean ojmb) { 37 return new RunnableHandler((Runnable ) target, ojmb); 38 } 39 40 class RunnableHandler implements InterfaceHandler { 41 42 private final Runnable runnable; 43 private final OddjobMBean ojmb; 44 45 RunnableHandler(Runnable runnable, OddjobMBean ojmb) { 46 this.runnable = runnable; 47 this.ojmb = ojmb; 48 } 49 50 public Object invoke(String actionName, Object [] params, String [] signature) throws MBeanException , ReflectionException { 51 if ("run".equals(actionName) 52 && signature.length == 0) { 53 ojmb.getContext().getThreadManager().run( 54 runnable, "run invoked by client."); 55 return null; 56 } 57 else { 58 throw new ReflectionException ( 59 new IllegalStateException ("invoked for an unknown method."), 60 actionName); 61 } 62 } 63 64 public Notification [] getLastNotifications() { 65 return null; 66 } 67 68 public void destroy() { 69 } 70 } 71 } | Popular Tags |