This class manages a list of dated timer notifications.
A method allows users to add/remove as many notifications as required.
When a timer notification is emitted by the timer and becomes obsolete,
it is automatically removed from the list of timer notifications.
Additional timer notifications can be added into regularly repeating notifications.
Note
Timer class is loaded.
Listeners may receive untimely notifications
if their host has a different system date.
To avoid such problems, synchronize the system date of all host machines where timing is needed.
java.util.Timer . In order to use fixed-rate execution, use the
overloaded addNotification(String, String, Object, Date, long, long, boolean) method.
NotificationBroadcasterSupport.
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private volatile int | counterID
The notification counter ID. Used to keep the max key value inserted into the timer table. |
| private static final int | |
| private transient boolean | isActive
Timer state. |
| public static final long | ONE_DAY
Number of milliseconds in one day. |
| public static final long | ONE_HOUR
Number of milliseconds in one hour. |
| public static final long | ONE_MINUTE
Number of milliseconds in one minute. |
| public static final long | ONE_SECOND
Number of milliseconds in one second. |
| public static final long | ONE_WEEK
Number of milliseconds in one week. |
| private boolean | sendPastNotifications
Past notifications sending on/off flag value. |
| private transient long | sequenceNumber
Timer sequence number. |
| private Timer | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private final Map | timerTable
Table containing all the timer notifications of this timer, with the associated date, period and number of occurrences. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized Integer | Returns: The identifier of the new created timer notification.The timer notification type. type, String The timer notification detailed message. message, Object The timer notification user data object. userData, Date The date when the notification occurs. date, long The period of the timer notification (in milliseconds). period, long The total number the timer notification will be emitted. nbOccurences, boolean If fixedRate)true and if the notification is periodic, the notification
is scheduled with a fixed-rate execution scheme. If
false and if the notification is periodic, the notification
is scheduled with a fixed-delay execution scheme. Ignored if the
notification is not periodic.Implements javax. Creates a new timer notification with the specified |
| public synchronized Integer | Returns: The identifier of the new created timer notification.The timer notification type. type, String The timer notification detailed message. message, Object The timer notification user data object. userData, Date The date when the notification occurs. date, long The period of the timer notification (in milliseconds). period, long The total number the timer notification will be emitted. nbOccurences)Implements javax. Creates a new timer notification with the specified |
| public synchronized Integer | Returns: The identifier of the new created timer notification.The timer notification type. type, String The timer notification detailed message. message, Object The timer notification user data object. userData, Date The date when the notification occurs. date, long The period of the timer notification (in milliseconds). period)Implements javax. Creates a new timer notification with the specified |
| public synchronized Integer | Returns: The identifier of the new created timer notification.The timer notification type. type, String The timer notification detailed message. message, Object The timer notification user data object. userData, Date The date when the notification occurs. date)Implements javax. Creates a new timer notification with the specified |
| public synchronized Vector | Returns: A vector ofInteger objects containing all the timer notification identifiers.
The vector is empty if there is no timer notification registered for this timer MBean. Implements javax. Gets all timer notification identifiers registered into the list of notifications. |
| public synchronized Date | Returns: A copy of the date or null if the identifier is not mapped to any timer notification registered for this timer MBean.The timer notification identifier. id)Implements javax. Gets a copy of the date associated to a timer notification. |
| public synchronized Boolean | Returns: A copy of the flag indicating whether a periodic notification is executed at fixed-delay or at fixed-rate.The timer notification identifier. id)Implements javax. Gets a copy of the flag indicating whether a periodic notification is executed at fixed-delay or at fixed-rate. |
| public synchronized int | Returns: The number of timer notifications.Implements javax. Gets the number of timer notifications registered into the list of notifications. |
| public synchronized Long | Returns: A copy of the remaining number of occurrences or null if the identifier is not mapped to any timer notification registered for this timer MBean.The timer notification identifier. id)Implements javax. Gets a copy of the remaining number of occurrences associated to a timer notification. |
| public synchronized Vector | Returns: A vector ofInteger objects containing all the identifiers of
timer notifications with the specified type.
The vector is empty if there is no timer notifications registered for this timer MBean with the specified type.The timer notification type. type)Implements javax. Gets all the identifiers of timer notifications corresponding to the specified type. |
| public synchronized MBeanNotificationInfo[] | getNotificationInfo()
Overrides javax. Implements javax. Returns an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type. |
| public synchronized String | Returns: The timer notification detailed message or null if the identifier is not mapped to any timer notification registered for this timer MBean.The timer notification identifier. id)Implements javax. Gets the timer notification detailed message corresponding to the specified identifier. |
| public synchronized String | Returns: The timer notification type or null if the identifier is not mapped to any timer notification registered for this timer MBean.The timer notification identifier. id)Implements javax. Gets the timer notification type corresponding to the specified identifier. |
| public synchronized Object | Returns: The timer notification user data object or null if the identifier is not mapped to any timer notification registered for this timer MBean.The timer notification identifier. id)Implements javax. Gets the timer notification user data object corresponding to the specified identifier. |
| public synchronized Long | Returns: A copy of the period or null if the identifier is not mapped to any timer notification registered for this timer MBean.The timer notification identifier. id)Implements javax. Gets a copy of the period (in milliseconds) associated to a timer notification. |
| public boolean | Returns: The past notifications sending on/off flag value.Implements javax. Gets the flag indicating whether or not the timer sends past notifications. |
| public boolean | Returns: true if the timer MBean is active, false otherwise.Implements javax. Tests whether the timer MBean is active. |
| public synchronized boolean | Returns: true if the list of timer notifications is empty, false otherwise.Implements javax. Tests whether the list of timer notifications is empty. |
| pack-priv void | notifyAlarmClock(TimerAlarmClockNotification
The TimerAlarmClock notification. notification)This method is called by the timer each time the TimerAlarmClock has exceeded its timeout. |
| public void | postDeregister()
Implements javax. Allows the timer MBean to perform any operations needed after having been unregistered by the MBean server. |
| public void | postRegister(Boolean registrationDone)
Implements javax. Allows the timer MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed. |
| public void | preDeregister()
Implements javax. Allows the timer MBean to perform any operations it needs before being unregistered by the MBean server. |
| public ObjectName | Returns: The name of the timer MBean registered.The MBean server in which the timer MBean will be registered. server, ObjectName The object name of the timer MBean. name)Implements javax. Allows the timer MBean to perform any operations it needs before being registered in the MBean server. |
| public synchronized void | removeAllNotifications()
Implements javax. Removes all the timer notifications from the list of notifications and resets the counter used to update the timer notification identifiers. |
| public synchronized void | removeNotification(Integer
The timer notification identifier. id)Implements javax. Removes the timer notification corresponding to the specified identifier from the list of notifications. |
| public synchronized void | removeNotifications(String
The timer notification type. type)Implements javax. Removes all the timer notifications corresponding to the specified type from the list of notifications. |
| pack-priv void | sendNotification(Date
The notification emission date. timeStamp, TimerNotification The timer notification to send. notification)This method is used by the timer MBean to update and send a timer notification to all the listeners registered for this kind of notification. |
| private synchronized void | sendPastNotifications(Date
The current date. currentDate, boolean The flag indicating if past notifications must be sent or not. currentFlag)Sends or not past notifications depending on the specified flag. |
| public void | setSendPastNotifications(boolean
The past notifications sending on/off flag value. value)Implements javax. Sets the flag indicating whether the timer sends past notifications or not. |
| public synchronized void | |
| public synchronized void | |
| private synchronized void | updateTimerTable(Integer
The timer notification identifier to update. notifID)If the timer notification is not periodic, it is removed from the list of notifications. |
| ALARM_CLOCK_INDEX | back to summary |
|---|---|
| private static final int ALARM_CLOCK_INDEX | |
| counterID | back to summary |
|---|---|
| private volatile int counterID The notification counter ID. Used to keep the max key value inserted into the timer table. | |
| FIXED_RATE_INDEX | back to summary |
|---|---|
| private static final int FIXED_RATE_INDEX | |
| isActive | back to summary |
|---|---|
| private transient boolean isActive Timer state.
The default value is set to | |
| ONE_DAY | back to summary |
|---|---|
| public static final long ONE_DAY Number of milliseconds in one day.
Useful constant for the | |
| ONE_HOUR | back to summary |
|---|---|
| public static final long ONE_HOUR Number of milliseconds in one hour.
Useful constant for the | |
| ONE_MINUTE | back to summary |
|---|---|
| public static final long ONE_MINUTE Number of milliseconds in one minute.
Useful constant for the | |
| ONE_SECOND | back to summary |
|---|---|
| public static final long ONE_SECOND Number of milliseconds in one second.
Useful constant for the | |
| ONE_WEEK | back to summary |
|---|---|
| public static final long ONE_WEEK Number of milliseconds in one week.
Useful constant for the | |
| sendPastNotifications | back to summary |
|---|---|
| private boolean sendPastNotifications Past notifications sending on/off flag value.
This attribute is used to specify if the timer has to send past notifications after start.
| |
| sequenceNumber | back to summary |
|---|---|
| private transient long sequenceNumber Timer sequence number. The default value is set to 0. | |
| timer | back to summary |
|---|---|
| private Timer timer | |
| TIMER_DATE_INDEX | back to summary |
|---|---|
| private static final int TIMER_DATE_INDEX | |
| TIMER_NB_OCCUR_INDEX | back to summary |
|---|---|
| private static final int TIMER_NB_OCCUR_INDEX | |
| TIMER_NOTIF_INDEX | back to summary |
|---|---|
| private static final int TIMER_NOTIF_INDEX | |
| TIMER_PERIOD_INDEX | back to summary |
|---|---|
| private static final int TIMER_PERIOD_INDEX | |
| timerTable | back to summary |
|---|---|
| private final Map<Integer, Object[]> timerTable Table containing all the timer notifications of this timer, with the associated date, period and number of occurrences. | |
| Timer | back to summary |
|---|---|
| public Timer() Default constructor. | |
| addNotification | back to summary |
|---|---|
| public synchronized Integer addNotification(String type, String message, Object userData, Date date, long period, long nbOccurences, boolean fixedRate) throws IllegalArgumentException Implements javax. Creates a new timer notification with the specified
If the timer notification to be inserted has a date that is before the current date,
the method behaves as if the specified date were the current date. Note that once the timer notification has been added into the list of notifications, its associated date, period and number of occurrences cannot be updated.
In the case of a periodic notification, the value of parameter fixedRate is used to
specify the execution scheme, as specified in
| |
| addNotification | back to summary |
|---|---|
| public synchronized Integer addNotification(String type, String message, Object userData, Date date, long period, long nbOccurences) throws IllegalArgumentException Implements javax. Creates a new timer notification with the specified
If the timer notification to be inserted has a date that is before the current date,
the method behaves as if the specified date were the current date. Note that once the timer notification has been added into the list of notifications, its associated date, period and number of occurrences cannot be updated.
In the case of a periodic notification, uses a fixed-delay execution scheme, as specified in
| |
| addNotification | back to summary |
|---|---|
| public synchronized Integer addNotification(String type, String message, Object userData, Date date, long period) throws IllegalArgumentException Implements javax. Creates a new timer notification with the specified
The timer notification will repeat continuously using the timer period using a fixed-delay
execution scheme, as specified in If the timer notification to be inserted has a date that is before the current date, the method behaves as if the specified date were the current date. The first notification is delivered immediately and the subsequent ones are spaced as specified by the period parameter.
| |
| addNotification | back to summary |
|---|---|
| public synchronized Integer addNotification(String type, String message, Object userData, Date date) throws IllegalArgumentException Implements javax. Creates a new timer notification with the specified The timer notification will be handled once at the specified date. If the timer notification to be inserted has a date that is before the current date, the method behaves as if the specified date were the current date and the notification is delivered immediately.
| |
| getAllNotificationIDs | back to summary |
|---|---|
| public synchronized Vector Implements javax. Gets all timer notification identifiers registered into the list of notifications. | |
| getDate | back to summary |
|---|---|
| public synchronized Date getDate(Integer id) Implements javax. Gets a copy of the date associated to a timer notification. | |
| getFixedRate | back to summary |
|---|---|
| public synchronized Boolean getFixedRate(Integer id) Implements javax. Gets a copy of the flag indicating whether a periodic notification is executed at fixed-delay or at fixed-rate. | |
| getNbNotifications | back to summary |
|---|---|
| public synchronized int getNbNotifications() Implements javax. Gets the number of timer notifications registered into the list of notifications.
| |
| getNbOccurences | back to summary |
|---|---|
| public synchronized Long getNbOccurences(Integer id) Implements javax. Gets a copy of the remaining number of occurrences associated to a timer notification. | |
| getNotificationIDs | back to summary |
|---|---|
| public synchronized Vector Implements javax. Gets all the identifiers of timer notifications corresponding to the specified type. | |
| getNotificationInfo | back to summary |
|---|---|
| public synchronized MBeanNotificationInfo[] getNotificationInfo() Overrides javax. Implements javax. Doc from javax. Returns an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type. It is not illegal for the MBean to send notifications not described in this array. However, some clients of the MBean server may depend on the array being complete for their correct functioning. | |
| getNotificationMessage | back to summary |
|---|---|
| public synchronized String getNotificationMessage(Integer id) Implements javax. Gets the timer notification detailed message corresponding to the specified identifier. | |
| getNotificationType | back to summary |
|---|---|
| public synchronized String getNotificationType(Integer id) Implements javax. Gets the timer notification type corresponding to the specified identifier. | |
| getNotificationUserData | back to summary |
|---|---|
| public synchronized Object getNotificationUserData(Integer id) Implements javax. Gets the timer notification user data object corresponding to the specified identifier. | |
| getPeriod | back to summary |
|---|---|
| public synchronized Long getPeriod(Integer id) Implements javax. Gets a copy of the period (in milliseconds) associated to a timer notification. | |
| getSendPastNotifications | back to summary |
|---|---|
| public boolean getSendPastNotifications() Implements javax. Gets the flag indicating whether or not the timer sends past notifications.
| |
| isActive | back to summary |
|---|---|
| public boolean isActive() Implements javax. Tests whether the timer MBean is active.
A timer MBean is marked active when the
| |
| isEmpty | back to summary |
|---|---|
| public synchronized boolean isEmpty() Implements javax. Tests whether the list of timer notifications is empty.
| |
| notifyAlarmClock | back to summary |
|---|---|
| pack-priv void notifyAlarmClock(TimerAlarmClockNotification notification) This method is called by the timer each time the TimerAlarmClock has exceeded its timeout.
| |
| postDeregister | back to summary |
|---|---|
| public void postDeregister() Implements javax. Allows the timer MBean to perform any operations needed after having been unregistered by the MBean server. Not used in this context. | |
| postRegister | back to summary |
|---|---|
| public void postRegister(Boolean registrationDone) Implements javax. Allows the timer MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed. Not used in this context. | |
| preDeregister | back to summary |
|---|---|
| public void preDeregister() throws Exception Implements javax. Allows the timer MBean to perform any operations it needs before being unregistered by the MBean server. Stops the timer.
| |
| preRegister | back to summary |
|---|---|
| public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception Implements javax. Allows the timer MBean to perform any operations it needs before being registered in the MBean server. Not used in this context.
| |
| removeAllNotifications | back to summary |
|---|---|
| public synchronized void removeAllNotifications() Implements javax. Removes all the timer notifications from the list of notifications and resets the counter used to update the timer notification identifiers. | |
| removeNotification | back to summary |
|---|---|
| public synchronized void removeNotification(Integer id) throws InstanceNotFoundException Implements javax. Removes the timer notification corresponding to the specified identifier from the list of notifications.
| |
| removeNotifications | back to summary |
|---|---|
| public synchronized void removeNotifications(String type) throws InstanceNotFoundException Implements javax. Removes all the timer notifications corresponding to the specified type from the list of notifications.
| |
| sendNotification | back to summary |
|---|---|
| pack-priv void sendNotification(Date timeStamp, TimerNotification notification) This method is used by the timer MBean to update and send a timer notification to all the listeners registered for this kind of notification.
| |
| sendPastNotifications | back to summary |
|---|---|
| private synchronized void sendPastNotifications(Date currentDate, boolean currentFlag) Sends or not past notifications depending on the specified flag.
| |
| setSendPastNotifications | back to summary |
|---|---|
| public void setSendPastNotifications(boolean value) Implements javax. Sets the flag indicating whether the timer sends past notifications or not.
| |
| start | back to summary |
|---|---|
| public synchronized void start() Implements javax. Starts the timer.
If there is one or more timer notifications before the time in the list of notifications, the notification
is sent according to the | |
| stop | back to summary |
|---|---|
| public synchronized void stop() Implements javax. Stops the timer. | |
| updateTimerTable | back to summary |
|---|---|
| private synchronized void updateTimerTable(Integer notifID) If the timer notification is not periodic, it is removed from the list of notifications. If the timer period of the timer notification has a non null periodicity, the date of the timer notification is updated by adding the periodicity. The associated TimerAlarmClock is updated by setting its timeout to the period value. If the timer period has a defined number of occurrences, the timer notification is updated if the number of occurrences has not yet been reached. Otherwise it is removed from the list of notifications.
| |