1. /*
  2. * @(#)TimerMBean.java 4.25 04/02/10
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.management.timer;
  8. // java imports
  9. //
  10. import java.util.Date;
  11. import java.util.Enumeration;
  12. import java.util.Vector;
  13. // NPCTE fix for bugId 4464388, esc 0, MR , to be added after modification of jmx spec
  14. //import java.io.Serializable;
  15. // end of NPCTE fix for bugId 4464388
  16. // jmx imports
  17. //
  18. import javax.management.InstanceNotFoundException;
  19. /**
  20. * Exposes the management interface of the timer MBean.
  21. *
  22. * @version 4.25 02/10/04
  23. * @author Sun Microsystems, Inc
  24. *
  25. * @since 1.5
  26. */
  27. public interface TimerMBean {
  28. /**
  29. * Starts the timer.
  30. * <P>
  31. * If there is one or more timer notifications before the time in the list of notifications, the notification
  32. * is sent according to the <CODE>sendPastNotifications</CODE> flag and then, updated
  33. * according to its period and remaining number of occurrences.
  34. * If the timer notification date remains earlier than the current date, this notification is just removed
  35. * from the list of notifications.
  36. */
  37. public void start();
  38. /**
  39. * Stops the timer.
  40. */
  41. public void stop();
  42. /**
  43. * Creates a new timer notification with the specified <CODE>type</CODE>, <CODE>message</CODE>
  44. * and <CODE>userData</CODE> and inserts it into the list of notifications with a given date,
  45. * period and number of occurrences.
  46. * <P>
  47. * If the timer notification to be inserted has a date that is before the current date,
  48. * the method behaves as if the specified date were the current date. <BR>
  49. * For once-off notifications, the notification is delivered immediately. <BR>
  50. * For periodic notifications, the first notification is delivered immediately and the
  51. * subsequent ones are spaced as specified by the period parameter.
  52. * <P>
  53. * Note that once the timer notification has been added into the list of notifications,
  54. * its associated date, period and number of occurrences cannot be updated.
  55. * <P>
  56. * In the case of a periodic notification, the value of parameter <i>fixedRate</i> is used to
  57. * specify the execution scheme, as specified in {@link java.util.Timer}.
  58. *
  59. * @param type The timer notification type.
  60. * @param message The timer notification detailed message.
  61. * @param userData The timer notification user data object.
  62. * @param date The date when the notification occurs.
  63. * @param period The period of the timer notification (in milliseconds).
  64. * @param nbOccurences The total number the timer notification will be emitted.
  65. * @param fixedRate If <code>true</code> and if the notification is periodic, the notification
  66. * is scheduled with a <i>fixed-rate</i> execution scheme. If
  67. * <code>false</code> and if the notification is periodic, the notification
  68. * is scheduled with a <i>fixed-delay</i> execution scheme. Ignored if the
  69. * notification is not periodic.
  70. *
  71. * @return The identifier of the new created timer notification.
  72. *
  73. * @exception java.lang.IllegalArgumentException The period or the number of occurrences is negative
  74. *
  75. * @see #addNotification(String, String, Object, Date, long, long)
  76. */
  77. // NPCTE fix for bugId 4464388, esc 0, MR, to be added after modification of jmx spec
  78. // public synchronized Integer addNotification(String type, String message, Serializable userData,
  79. // Date date, long period, long nbOccurences)
  80. // end of NPCTE fix for bugId 4464388
  81. public Integer addNotification(String type, String message, Object userData,
  82. Date date, long period, long nbOccurences, boolean fixedRate)
  83. throws java.lang.IllegalArgumentException;
  84. /**
  85. * Creates a new timer notification with the specified <CODE>type</CODE>, <CODE>message</CODE>
  86. * and <CODE>userData</CODE> and inserts it into the list of notifications with a given date,
  87. * period and number of occurrences.
  88. * <P>
  89. * If the timer notification to be inserted has a date that is before the current date,
  90. * the method behaves as if the specified date were the current date. <BR>
  91. * For once-off notifications, the notification is delivered immediately. <BR>
  92. * For periodic notifications, the first notification is delivered immediately and the
  93. * subsequent ones are spaced as specified by the period parameter.
  94. * <P>
  95. * Note that once the timer notification has been added into the list of notifications,
  96. * its associated date, period and number of occurrences cannot be updated.
  97. * <P>
  98. * In the case of a periodic notification, uses a <i>fixed-delay</i> execution scheme, as specified in
  99. * {@link java.util.Timer}. In order to use a <i>fixed-rate</i> execution scheme, use
  100. * {@link #addNotification(String, String, Object, Date, long, long, boolean)} instead.
  101. *
  102. * @param type The timer notification type.
  103. * @param message The timer notification detailed message.
  104. * @param userData The timer notification user data object.
  105. * @param date The date when the notification occurs.
  106. * @param period The period of the timer notification (in milliseconds).
  107. * @param nbOccurences The total number the timer notification will be emitted.
  108. *
  109. * @return The identifier of the new created timer notification.
  110. *
  111. * @exception java.lang.IllegalArgumentException The period or the number of occurrences is negative
  112. *
  113. * @see #addNotification(String, String, Object, Date, long, long, boolean)
  114. */
  115. // NPCTE fix for bugId 4464388, esc 0, MR , to be added after modification of jmx spec
  116. // public synchronized Integer addNotification(String type, String message, Serializable userData,
  117. // Date date, long period)
  118. // end of NPCTE fix for bugId 4464388 */
  119. public Integer addNotification(String type, String message, Object userData,
  120. Date date, long period, long nbOccurences)
  121. throws java.lang.IllegalArgumentException;
  122. /**
  123. * Creates a new timer notification with the specified <CODE>type</CODE>, <CODE>message</CODE>
  124. * and <CODE>userData</CODE> and inserts it into the list of notifications with a given date
  125. * and period and a null number of occurrences.
  126. * <P>
  127. * The timer notification will repeat continuously using the timer period using a <i>fixed-delay</i>
  128. * execution scheme, as specified in {@link java.util.Timer}. In order to use a <i>fixed-rate</i>
  129. * execution scheme, use {@link #addNotification(String, String, Object, Date, long, long,
  130. * boolean)} instead.
  131. * <P>
  132. * If the timer notification to be inserted has a date that is before the current date,
  133. * the method behaves as if the specified date were the current date. The
  134. * first notification is delivered immediately and the subsequent ones are
  135. * spaced as specified by the period parameter.
  136. *
  137. * @param type The timer notification type.
  138. * @param message The timer notification detailed message.
  139. * @param userData The timer notification user data object.
  140. * @param date The date when the notification occurs.
  141. * @param period The period of the timer notification (in milliseconds).
  142. *
  143. * @return The identifier of the new created timer notification.
  144. *
  145. * @exception java.lang.IllegalArgumentException The period is negative or
  146. * the date notification is before the current date.
  147. */
  148. // NPCTE fix for bugId 4464388, esc 0, MR , to be added after modification of jmx spec
  149. // public synchronized Integer addNotification(String type, String message, Serializable userData,
  150. // Date date, long period)
  151. // end of NPCTE fix for bugId 4464388 */
  152. public Integer addNotification(String type, String message, Object userData,
  153. Date date, long period)
  154. throws java.lang.IllegalArgumentException;
  155. /**
  156. * Creates a new timer notification with the specified <CODE>type</CODE>, <CODE>message</CODE>
  157. * and <CODE>userData</CODE> and inserts it into the list of notifications with a given date
  158. * and a null period and number of occurrences.
  159. * <P>
  160. * The timer notification will be handled once at the specified date.
  161. * <P>
  162. * If the timer notification to be inserted has a date that is before the current date,
  163. * the method behaves as if the specified date were the current date and the
  164. * notification is delivered immediately.
  165. *
  166. * @param type The timer notification type.
  167. * @param message The timer notification detailed message.
  168. * @param userData The timer notification user data object.
  169. * @param date The date when the notification occurs.
  170. *
  171. * @return The identifier of the new created timer notification.
  172. *
  173. * @exception java.lang.IllegalArgumentException The date notification is before the current date.
  174. */
  175. // NPCTE fix for bugId 4464388, esc 0, MR, to be added after modification of jmx spec
  176. // public synchronized Integer addNotification(String type, String message, Serializable userData, Date date)
  177. // throws java.lang.IllegalArgumentException {
  178. // end of NPCTE fix for bugId 4464388
  179. public Integer addNotification(String type, String message, Object userData, Date date)
  180. throws java.lang.IllegalArgumentException;
  181. /**
  182. * Removes the timer notification corresponding to the specified identifier from the list of notifications.
  183. *
  184. * @param id The timer notification identifier.
  185. *
  186. * @exception InstanceNotFoundException The specified identifier does not correspond to any timer notification
  187. * in the list of notifications of this timer MBean.
  188. */
  189. public void removeNotification(Integer id) throws InstanceNotFoundException;
  190. /**
  191. * Removes all the timer notifications corresponding to the specified type from the list of notifications.
  192. *
  193. * @param type The timer notification type.
  194. *
  195. * @exception InstanceNotFoundException The specified type does not correspond to any timer notification
  196. * in the list of notifications of this timer MBean.
  197. */
  198. public void removeNotifications(String type) throws InstanceNotFoundException;
  199. /**
  200. * Removes all the timer notifications from the list of notifications
  201. * and resets the counter used to update the timer notification identifiers.
  202. */
  203. public void removeAllNotifications();
  204. // GETTERS AND SETTERS
  205. //--------------------
  206. /**
  207. * Gets the number of timer notifications registered into the list of notifications.
  208. *
  209. * @return The number of timer notifications.
  210. */
  211. public int getNbNotifications();
  212. /**
  213. * Gets all timer notification identifiers registered into the list of notifications.
  214. *
  215. * @return A vector of <CODE>Integer</CODE> objects containing all the timer notification identifiers.
  216. * <BR>The vector is empty if there is no timer notification registered for this timer MBean.
  217. */
  218. public Vector getAllNotificationIDs();
  219. /**
  220. * Gets all the identifiers of timer notifications corresponding to the specified type.
  221. *
  222. * @param type The timer notification type.
  223. *
  224. * @return A vector of <CODE>Integer</CODE> objects containing all the identifiers of
  225. * timer notifications with the specified <CODE>type</CODE>.
  226. * <BR>The vector is empty if there is no timer notifications registered for this timer MBean
  227. * with the specified <CODE>type</CODE>.
  228. */
  229. public Vector getNotificationIDs(String type);
  230. /**
  231. * Gets the timer notification type corresponding to the specified identifier.
  232. *
  233. * @param id The timer notification identifier.
  234. *
  235. * @return The timer notification type or null if the identifier is not mapped to any
  236. * timer notification registered for this timer MBean.
  237. */
  238. public String getNotificationType(Integer id);
  239. /**
  240. * Gets the timer notification detailed message corresponding to the specified identifier.
  241. *
  242. * @param id The timer notification identifier.
  243. *
  244. * @return The timer notification detailed message or null if the identifier is not mapped to any
  245. * timer notification registered for this timer MBean.
  246. */
  247. public String getNotificationMessage(Integer id);
  248. /**
  249. * Gets the timer notification user data object corresponding to the specified identifier.
  250. *
  251. * @param id The timer notification identifier.
  252. *
  253. * @return The timer notification user data object or null if the identifier is not mapped to any
  254. * timer notification registered for this timer MBean.
  255. */
  256. // NPCTE fix for bugId 4464388, esc 0 , MR , 03 sept 2001 , to be added after modification of jmx spec
  257. //public Serializable getNotificationUserData(Integer id);
  258. // end of NPCTE fix for bugId 4464388
  259. public Object getNotificationUserData(Integer id);
  260. /**
  261. * Gets a copy of the date associated to a timer notification.
  262. *
  263. * @param id The timer notification identifier.
  264. *
  265. * @return A copy of the date or null if the identifier is not mapped to any
  266. * timer notification registered for this timer MBean.
  267. */
  268. public Date getDate(Integer id);
  269. /**
  270. * Gets a copy of the period (in milliseconds) associated to a timer notification.
  271. *
  272. * @param id The timer notification identifier.
  273. *
  274. * @return A copy of the period or null if the identifier is not mapped to any
  275. * timer notification registered for this timer MBean.
  276. */
  277. public Long getPeriod(Integer id);
  278. /**
  279. * Gets a copy of the remaining number of occurrences associated to a timer notification.
  280. *
  281. * @param id The timer notification identifier.
  282. *
  283. * @return A copy of the remaining number of occurrences or null if the identifier is not mapped to any
  284. * timer notification registered for this timer MBean.
  285. */
  286. public Long getNbOccurences(Integer id);
  287. /**
  288. * Gets a copy of the flag indicating whether a periodic notification is
  289. * executed at <i>fixed-delay</i> or at <i>fixed-rate</i>.
  290. *
  291. * @param id The timer notification identifier.
  292. *
  293. * @return A copy of the flag indicating whether a periodic notification is
  294. * executed at <i>fixed-delay</i> or at <i>fixed-rate</i>.
  295. */
  296. public Boolean getFixedRate(Integer id);
  297. /**
  298. * Gets the flag indicating whether or not the timer sends past notifications.
  299. *
  300. * @return The past notifications sending on/off flag value.
  301. *
  302. * @see #setSendPastNotifications
  303. */
  304. public boolean getSendPastNotifications();
  305. /**
  306. * Sets the flag indicating whether the timer sends past notifications or not.
  307. *
  308. * @param value The past notifications sending on/off flag value.
  309. *
  310. * @see #getSendPastNotifications
  311. */
  312. public void setSendPastNotifications(boolean value);
  313. /**
  314. * Tests whether the timer MBean is active.
  315. * A timer MBean is marked active when the {@link #start start} method is called.
  316. * It becomes inactive when the {@link #stop stop} method is called.
  317. *
  318. * @return <CODE>true</CODE> if the timer MBean is active, <CODE>false</CODE> otherwise.
  319. */
  320. public boolean isActive();
  321. /**
  322. * Tests whether the list of timer notifications is empty.
  323. *
  324. * @return <CODE>true</CODE> if the list of timer notifications is empty, <CODE>false</CODE> otherwise.
  325. */
  326. public boolean isEmpty();
  327. }