1 22 package org.jboss.monitor.services; 23 24 import java.util.Date ; 25 26 import javax.management.InstanceNotFoundException ; 27 import javax.management.MBeanServerInvocationHandler ; 28 import javax.management.ObjectName ; 29 import javax.management.timer.TimerMBean ; 30 31 import org.jboss.system.ServiceMBeanSupport; 32 import org.jboss.util.Strings; 33 34 41 public class TimerService extends ServiceMBeanSupport 42 implements TimerServiceMBean 43 { 44 46 47 private String notificationType; 48 49 50 private String notificationMessage; 51 52 53 private String timerPeriodString; 54 55 56 private long repeatitions; 57 58 59 private boolean fixedRate; 60 61 62 private ObjectName timerObjectName; 63 64 65 private long timerPeriod; 66 67 68 private TimerMBean timerProxy; 69 70 71 private Integer id; 72 73 75 78 public TimerService() 79 { 80 } 82 83 85 88 public void setNotificationType(String type) 89 { 90 this.notificationType = type; 91 } 92 93 96 public String getNotificationType() 97 { 98 return notificationType; 99 } 100 101 104 public void setNotificationMessage(String message) 105 { 106 this.notificationMessage = message; 107 } 108 109 112 public String getNotificationMessage() 113 { 114 return notificationMessage; 115 } 116 117 120 public void setTimerPeriod(String timerPeriod) 121 { 122 this.timerPeriod = Strings.parsePositiveTimePeriod(timerPeriod); 123 this.timerPeriodString = timerPeriod; 124 } 125 126 129 public String getTimerPeriod() 130 { 131 return this.timerPeriodString; 132 } 133 134 137 public void setRepeatitions(long repeatitions) 138 { 139 this.repeatitions = repeatitions; 140 } 141 142 145 public long getRepeatitions() 146 { 147 return repeatitions; 148 } 149 150 153 public void setFixedRate(boolean fixedRate) 154 { 155 this.fixedRate = fixedRate; 156 } 157 158 161 public boolean getFixedRate() 162 { 163 return fixedRate; 164 } 165 166 169 public void setTimerMBean(ObjectName timerMBean) 170 { 171 this.timerProxy = (TimerMBean )MBeanServerInvocationHandler 172 .newProxyInstance(getServer(), timerMBean, TimerMBean .class, false); 173 this.timerObjectName = timerMBean; 174 } 175 176 179 public ObjectName getTimerMBean() 180 { 181 return timerObjectName; 182 } 183 184 186 189 public void startService() throws Exception 190 { 191 if (timerProxy != null) 192 { 193 id = timerProxy.addNotification( 194 notificationType, 195 notificationMessage, 196 null, new Date (), timerPeriod, 199 repeatitions, 200 fixedRate); 201 202 log.debug("Added timer notification(" + id 203 + ") : type=" + notificationType 204 + ", message=" + notificationMessage 205 + ", period=" + timerPeriodString 206 + ", repeatitions=" + repeatitions 207 + ", fixedRate=" + fixedRate 208 + ", to timer '" + timerObjectName + "'"); 209 } 210 else 211 { 212 log.warn("TimerMBean not set"); 213 } 214 } 215 216 219 public void stopService() 220 { 221 if (id != null) 222 { 223 try 224 { 225 timerProxy.removeNotification(id); 226 log.debug("Removed timer notification(" + id + ") from timer '" + timerObjectName + "'"); 227 } 228 catch (InstanceNotFoundException ignore) 229 { 230 } 233 id = null; 234 } 235 } 236 237 } 238 | Popular Tags |