Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.management.timer
Class Timer

    java.lang.Object
      |
      +--javax.management.NotificationBroadcasterSupport
            |
            +--javax.management.timer.Timer

public class Timer
extends NotificationBroadcasterSupport
implements TimerMBean, java.io.Serializable

This class provides the implementation of the Timer MBean. The Timer MBean sends out an alarm at a specified time that wakes up all the listeners registered to receive timer notifications.

This class manages a list of dated timer notifications. A method allows users to add/remove as many notifications as required. Added timer notifications can be made into regularly repeating notifications.

Note:

All notifications before the time when the `addNotification` method is called are ignored irrespective of the `sendPastNotifications` flag.

See Also:
  Serialized Form

Field Summary
`static long` | `ONE_DAY` Number of milliseconds in one day.
`static long` | `ONE_HOUR` Number of milliseconds in one hour.
`static long` | `ONE_MINUTE` Number of milliseconds in one minute.
`static long` | `ONE_SECOND` Number of milliseconds in one second.
`static long` | `ONE_WEEK` Number of milliseconds in one week.

Constructor Summary
`Timer()` Default constructor.

Method Summary
`void` | `addNotification(Notification notification, java.util.Date date)` Inserts the specified timer notification into the list of notifications with a given date and a null period and number of repetitions.
`void` | `addNotification(Notification notification, java.util.Date date, long periodInMillis)` Inserts the specified timer notification into the list of notifications with a given date and period and a null number of repetitions.
`void` | `addNotification(Notification notification, java.util.Date date, long periodInMillis, long nbRepetitions)` Inserts the specified timer notification into the list of notifications with a given date, period and number of repetitions.
`java.util.Date` | `getDate(int index)` Gets a copy of the date of the timer notification at the specified index.
`java.util.Date` | `getDate(Notification notification)` Gets a copy of the date of the specified timer notification.
`int` | `getNbNotifications()` Gets the number of notifications registered into the list of notifications.
`java.lang.Long` | `getNbRepetitions(int index)` Gets a copy of the remaining number of repetitions of the timer notification at the specified index.
`java.lang.Long` | `getNbRepetitions(Notification notification)` Gets a copy of the remaining number of repetitions of the specified timer notification.
`Notification[]` | `getNotifications()` Gets all the notifications registered into the list of notifications.
`java.lang.Long` | `getPeriodInMillis(int index)` Gets a copy of the period in milliseconds of the timer notification at the specified index.
`java.lang.Long` | `getPeriodInMillis(Notification notification)` Gets a copy of the period in milliseconds of the specified timer notification.
`boolean` | `getSendPastNotifications()` Gets the flag indicating if the Timer sends past notifications or not.
`boolean` | `isActive()` Tests if the Timer MBean is active.
`boolean` | `isEmpty()` Tests if the list of notifications is empty.
`void` | `removeAllNotifications()` Removes all the notifications from the list of notifications.
`void` | `removeNotification(int index)` Removes the timer notification at the specified index from the list of notifications.
`void` | `removeNotification(Notification notification)` Removes the specified timer notification from the list of notifications.
`void` | `setSendPastNotifications(boolean value)` Sets the flag indicating if the Timer sends past notifications or not.
`void` | `start()` Starts the Timer.
`void` | `stop()` Stops the Timer.

Methods inherited from class javax.management.NotificationBroadcasterSupport
`addNotificationListener, getNotificationInfo, removeNotificationListener, sendNotification`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### ONE_SECOND

    public static final long ONE_SECOND

  Number of milliseconds in one second. Useful constant for the `addNotification` method.

### ONE_MINUTE

    public static final long ONE_MINUTE

  Number of milliseconds in one minute. Useful constant for the `addNotification` method.

### ONE_HOUR

    public static final long ONE_HOUR

  Number of milliseconds in one hour. Useful constant for the `addNotification` method.

### ONE_DAY

    public static final long ONE_DAY

  Number of milliseconds in one day. Useful constant for the `addNotification` method.

### ONE_WEEK

    public static final long ONE_WEEK

  Number of milliseconds in one week. Useful constant for the `addNotification` method.

Constructor Detail

### Timer

    public Timer()

  Default constructor.

Method Detail

### start

    public void start()

  Starts the Timer.
  Specified by:
    start in interface TimerMBean

### stop

    public void stop()

  Stops the Timer.
  Specified by:
    stop in interface TimerMBean

### addNotification

    public void addNotification(Notification notification,
                                java.util.Date date,
                                long periodInMillis,
                                long nbRepetitions)
                         throws InstanceAlreadyExistsException,
                                java.lang.IllegalArgumentException

  Inserts the specified timer notification into the list of notifications with a given date, period and number of repetitions.

  If the timer notification to be inserted has a date that is before the current date, the method attempts to update the notification using the defined period. If the defined period is null then the method generates an exception.

  If the timer notification has a non null period, the date of the notification is updated by adding the period until the notification date is later than the current date. Then the timer notification is inserted into the list of notifications.

  If the specified number of repetitions is non null, the previous mechanism is employed. The number of times that the period is added is limited to the specified number of repetitions. If the notification date remains earlier than the current date, an exception is generated.

  A specified timer notification can be added only once.

  Note that once the timer notification has been added into the list of notifications, its associated date, period and number of repetitions cannot be updated.

  Specified by:
    addNotification in interface TimerMBean
  Parameters:
    `notification` - The timer notification to be added.
    `date` - The date when the notification occurs.
    `periodInMillis` - The period of the timer notification.
    `nbRepetitions` - The number of repetitions of the timer notification.
  Throws:
    InstanceAlreadyExistsException - The timer notification to add is already in the list of notifications.
    java.lang.IllegalArgumentException - The period or the number of repetitions is negative or the date notification is before the current date.

### addNotification

    public void addNotification(Notification notification,
                                java.util.Date date,
                                long periodInMillis)
                         throws InstanceAlreadyExistsException,
                                java.lang.IllegalArgumentException

  Inserts the specified timer notification into the list of notifications with a given date and period and a null number of repetitions.

  The timer notification will repeat continuously using the timer period.

  Specified by:
    addNotification in interface TimerMBean
  Parameters:
    `notification` - The timer notification to be added.
    `date` - The date when the notification occurs.
    `periodInMillis` - The period of the timer notification.
  Throws:
    InstanceAlreadyExistsException - The timer notification to add is already in the list of notifications.
    java.lang.IllegalArgumentException - The period is negative or the date notification is before the current date.

### addNotification

    public void addNotification(Notification notification,
                                java.util.Date date)
                         throws InstanceAlreadyExistsException,
                                java.lang.IllegalArgumentException

  Inserts the specified timer notification into the list of notifications with a given date and a null period and number of repetitions.

  The timer notification will be handled once at the specified date.

  Specified by:
    addNotification in interface TimerMBean
  Parameters:
    `notification` - The timer notification to be added.
    `date` - The date when the notification occurs.
  Throws:
    InstanceAlreadyExistsException - The timer notification to add is already in the list of notifications.
    java.lang.IllegalArgumentException - The date notification is before the current date.

### removeNotification

    public void removeNotification(Notification notification)
                            throws InstanceNotFoundException

  Removes the specified timer notification from the list of notifications. If the object is found in this list, each component in the list with an index greater or equal to the object's index is shifted downward to have an index one smaller than the value it had previously.
  Specified by:
    removeNotification in interface TimerMBean
  Parameters:
    `notification` - The timer notification to be removed.
  Throws:
    InstanceNotFoundException - The timer notification to remove is not in the list of notifications.

### removeNotification

    public void removeNotification(int index)
                            throws InstanceNotFoundException

  Removes the timer notification at the specified index from the list of notifications. Each component in this list with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously.
  Specified by:
    removeNotification in interface TimerMBean
  Parameters:
    `index` - The index of the timer notification to remove.
  Throws:
    InstanceNotFoundException - The index is invalid.

### removeAllNotifications

    public void removeAllNotifications()

  Removes all the notifications from the list of notifications.
  Specified by:
    removeAllNotifications in interface TimerMBean

### getNotifications

    public Notification[] getNotifications()

  Gets all the notifications registered into the list of notifications.
  Specified by:
    getNotifications in interface TimerMBean
  Returns:
    An array containing all the notifications registered into the list of notifications.

### getDate

    public java.util.Date getDate(Notification notification)

  Gets a copy of the date of the specified timer notification.
  Specified by:
    getDate in interface TimerMBean
  Parameters:
    `notification` - The timer notification.
  Returns:
    A copy of the date of the specified timer notification or null if the specified timer notification is not in the list of notifications.

### getDate

    public java.util.Date getDate(int index)

  Gets a copy of the date of the timer notification at the specified index.
  Specified by:
    getDate in interface TimerMBean
  Parameters:
    `index` - The index of the timer notification.
  Returns:
    A copy of the date at the specified index in the list of notifications or null if the specified index is invalid.

### getPeriodInMillis

    public java.lang.Long getPeriodInMillis(Notification notification)

  Gets a copy of the period in milliseconds of the specified timer notification.
  Specified by:
    getPeriodInMillis in interface TimerMBean
  Parameters:
    `notification` - The timer notification.
  Returns:
    A copy of the period of the specified timer notification or null if the specified timer notification is not in the list of notifications.

### getPeriodInMillis

    public java.lang.Long getPeriodInMillis(int index)

  Gets a copy of the period in milliseconds of the timer notification at the specified index.
  Specified by:
    getPeriodInMillis in interface TimerMBean
  Parameters:
    `index` - The index of the timer notification.
  Returns:
    A copy of the period at the specified index in the list of notifications or null if the specified index is invalid.

### getNbRepetitions

    public java.lang.Long getNbRepetitions(Notification notification)

  Gets a copy of the remaining number of repetitions of the specified timer notification.
  Specified by:
    getNbRepetitions in interface TimerMBean
  Parameters:
    `notification` - The timer notification.
  Returns:
    A copy of the remaining number of repetitions of the specified timer notification or null if the specified timer notification is not in the list of notifications.

### getNbRepetitions

    public java.lang.Long getNbRepetitions(int index)

  Gets a copy of the remaining number of repetitions of the timer notification at the specified index.
  Specified by:
    getNbRepetitions in interface TimerMBean
  Parameters:
    `index` - The index of the timer notification.
  Returns:
    A copy of the remaining number of repetitions at the specified index in the list of notifications or null if the specified index is invalid.

### getNbNotifications

    public int getNbNotifications()

  Gets the number of notifications registered into the list of notifications.
  Specified by:
    getNbNotifications in interface TimerMBean
  Returns:
    The number of notifications.

### getSendPastNotifications

    public boolean getSendPastNotifications()

  Gets the flag indicating if the Timer sends past notifications or not.
  Specified by:
    getSendPastNotifications in interface TimerMBean
  Returns:
    The past notifications sending on/off flag value.

### setSendPastNotifications

    public void setSendPastNotifications(boolean value)

  Sets the flag indicating if the Timer sends past notifications or not.
  Specified by:
    setSendPastNotifications in interface TimerMBean
  Parameters:
    `value` - The past notifications sending on/off flag value.

### isActive

    public boolean isActive()

  Tests if the Timer MBean is active. A Timer MBean is marked active when the start method is called. It becomes inactive when the stop method is called.
  Specified by:
    isActive in interface TimerMBean
  Returns:
    True if the Timer MBean is active, false otherwise.

### isEmpty

    public boolean isEmpty()

  Tests if the list of notifications is empty.
  Specified by:
    isEmpty in interface TimerMBean
  Returns:
    True if the list of notifications is empty, false otherwise.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD