1 22 package org.jboss.varia.scheduler; 23 24 import java.util.Date ; 25 26 import javax.management.InstanceNotFoundException ; 27 import javax.management.JMException ; 28 import javax.management.MBeanException ; 29 import javax.management.ObjectName ; 30 import javax.management.ReflectionException ; 31 import javax.management.MBeanServerInvocationHandler ; 32 33 import org.jboss.system.ServiceMBeanSupport; 34 35 48 public abstract class AbstractScheduleProvider extends ServiceMBeanSupport 49 implements AbstractScheduleProviderMBean 50 { 51 52 private ObjectName scheduleManagerName = ScheduleManagerMBean.OBJECT_NAME; 53 private ScheduleManagerMBean manager; 54 55 59 62 public AbstractScheduleProvider() 63 { 64 } 65 66 70 75 public ObjectName getScheduleManagerName() 76 { 77 return scheduleManagerName; 78 } 79 80 85 public void setScheduleManagerName(ObjectName scheduleManagerName) 86 { 87 this.scheduleManagerName = scheduleManagerName; 88 } 89 90 94 99 public abstract void startProviding() throws Exception ; 100 101 107 public abstract void stopProviding(); 108 109 113 128 protected int addSchedule( 129 ObjectName pTarget, String pMethodName, String [] pMethodSignature, 130 Date pStart, long pPeriod, int pRepetitions) throws JMException 131 { 132 return manager.addSchedule(serviceName, 133 pTarget, 134 pMethodName, 135 pMethodSignature, 136 pStart, 137 pPeriod, 138 pRepetitions); 139 } 140 141 146 protected void removeSchedule(int pID) throws JMException 147 { 148 manager.removeSchedule(pID); 149 } 150 151 155 165 protected void startService() throws Exception 166 { 167 this.manager = (ScheduleManagerMBean)MBeanServerInvocationHandler.newProxyInstance( 168 getServer(), scheduleManagerName, ScheduleManagerMBean.class, false); 169 startScheduleProviderService(); 170 } 171 172 182 protected void stopService() throws Exception 183 { 184 stopScheduleProviderService(); 185 } 186 187 190 protected void startScheduleProviderService() 191 throws InstanceNotFoundException , MBeanException , ReflectionException 192 { 193 manager.registerProvider(serviceName.toString()); 194 } 195 196 199 protected void stopScheduleProviderService() 200 throws InstanceNotFoundException , MBeanException , ReflectionException 201 { 202 manager.unregisterProvider(serviceName.toString()); 203 } 204 205 } 206 | Popular Tags |