org.jboss.mx.timer
Class JBossTimer

java.lang.Object
  extended by javax.management.NotificationBroadcasterSupport
      extended by org.jboss.mx.timer.JBossTimer
All Implemented Interfaces:
MBeanRegistration, NotificationBroadcaster, NotificationEmitter, TimerMBean, JBossTimerMBean

public class JBossTimer
extends NotificationBroadcasterSupport
implements JBossTimerMBean, MBeanRegistration

A clone of the JBossMX javax.management.timer.Timer service. There are indications that the jdk5 javax.management.timer.Timer uses internally a single-threaded implementation for executing scheduled tasks, so scheduling of multiple tasks is affected when moving from jdk1.4 and the jboss implementation of Timer, to a jdk5 runtime. The JBossMX Timer implementation in contrast uses a dynamically extensible thread pool to execute scheduled tasks. Since we don't control the jdk5 implementation, we've cloned the jboss timer so it can be used as a drop-in replacement of the jdk JMX Timer. The two classes *should* be kept in sync, or instead change our javax.management.timer.Timer to delegate to this class.

Version:
$Revision: 85945 $
Author:
Adrian Brock, Dimitris Andreadis
See Also:
Timer

Field Summary
static long ONE_DAY
          The number of milliseconds in one day.
static long ONE_HOUR
          The number of milliseconds in one hour.
static long ONE_MINUTE
          The number of milliseconds in one minute.
static long ONE_SECOND
          The number of milliseconds in one second.
static long ONE_WEEK
          The number of milliseconds in one week.
 
Constructor Summary
JBossTimer()
           
 
Method Summary
 Integer addNotification(String type, String message, Object userData, Date date)
           
 Integer addNotification(String type, String message, Object userData, Date date, long period)
           
 Integer addNotification(String type, String message, Object userData, Date date, long period, long occurences)
           
 Integer addNotification(String type, String message, Object userData, Date date, long period, long nbOccurences, boolean fixedRate)
          Creates a new timer notification with the specified type, message and userData and inserts it into the list of notifications with a given date, period and number of occurences.
 Vector getAllNotificationIDs()
           
 Date getDate(Integer id)
           
 Boolean getFixedRate(Integer id)
          Gets a copy of the flag indicating whether a peridic notification is executed at fixed-delay or at fixed-rate.
 int getNbNotifications()
           
 Long getNbOccurences(Integer id)
           
 Vector getNotificationIDs(String type)
           
 String getNotificationMessage(Integer id)
           
 String getNotificationType(Integer id)
           
 Object getNotificationUserData(Integer id)
           
 Long getPeriod(Integer id)
           
 boolean getSendPastNotifications()
           
 boolean isActive()
           
 boolean isEmpty()
           
 void postDeregister()
           
 void postRegister(Boolean registrationDone)
           
 void preDeregister()
           
 ObjectName preRegister(MBeanServer server, ObjectName objectName)
           
 void removeAllNotifications()
           
 void removeNotification(Integer id)
           
 void removeNotifications(String type)
           
 void setSendPastNotifications(boolean value)
           
 void start()
           
 void stop()
           
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, 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
The number of milliseconds in one second.

See Also:
Constant Field Values

ONE_MINUTE

public static final long ONE_MINUTE
The number of milliseconds in one minute.

See Also:
Constant Field Values

ONE_HOUR

public static final long ONE_HOUR
The number of milliseconds in one hour.

See Also:
Constant Field Values

ONE_DAY

public static final long ONE_DAY
The number of milliseconds in one day.

See Also:
Constant Field Values

ONE_WEEK

public static final long ONE_WEEK
The number of milliseconds in one week.

See Also:
Constant Field Values
Constructor Detail

JBossTimer

public JBossTimer()
Method Detail

addNotification

public Integer addNotification(String type,
                               String message,
                               Object userData,
                               Date date)
                        throws IllegalArgumentException
Specified by:
addNotification in interface TimerMBean
Throws:
IllegalArgumentException

addNotification

public Integer addNotification(String type,
                               String message,
                               Object userData,
                               Date date,
                               long period)
                        throws IllegalArgumentException
Specified by:
addNotification in interface TimerMBean
Throws:
IllegalArgumentException

addNotification

public Integer addNotification(String type,
                               String message,
                               Object userData,
                               Date date,
                               long period,
                               long occurences)
                        throws IllegalArgumentException
Specified by:
addNotification in interface TimerMBean
Throws:
IllegalArgumentException

addNotification

public Integer addNotification(String type,
                               String message,
                               Object userData,
                               Date date,
                               long period,
                               long nbOccurences,
                               boolean fixedRate)
                        throws IllegalArgumentException
Creates a new timer notification with the specified type, message and userData and inserts it into the list of notifications with a given date, period and number of occurences.

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. For once-off notifications, the notification is delivered immediately. For periodic notifications, the first notification is delivered immediately and the subsequent ones are spaced as specified by the period parameter.

Note that once the timer notification has been added into the list of notifications, its associated date, period and number of occurences 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 Timer.

Specified by:
addNotification in interface TimerMBean
Parameters:
type - The timer notification type.
message - The timer notification detailed message.
userData - The timer notification user data object.
date - The date when the notification occurs.
period - The period of the timer notification (in milliseconds).
nbOccurences - The total number the timer notification will be emitted.
fixedRate - If 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.
Returns:
The identifier of the new created timer notification.
Throws:
IllegalArgumentException - The period or the number of occurences is negative

getAllNotificationIDs

public Vector getAllNotificationIDs()
Specified by:
getAllNotificationIDs in interface TimerMBean

getDate

public Date getDate(Integer id)
Specified by:
getDate in interface TimerMBean

getNbNotifications

public int getNbNotifications()
Specified by:
getNbNotifications in interface TimerMBean

getNbOccurences

public Long getNbOccurences(Integer id)
Specified by:
getNbOccurences in interface TimerMBean

getFixedRate

public Boolean getFixedRate(Integer id)
Gets a copy of the flag indicating whether a peridic notification is executed at fixed-delay or at fixed-rate.

Specified by:
getFixedRate in interface TimerMBean
Parameters:
id - The timer notification identifier.
Returns:
A copy of the flag indicating whether a peridic notification is executed at fixed-delay or at fixed-rate.

getNotificationIDs

public Vector getNotificationIDs(String type)
Specified by:
getNotificationIDs in interface TimerMBean

getNotificationMessage

public String getNotificationMessage(Integer id)
Specified by:
getNotificationMessage in interface TimerMBean

getNotificationType

public String getNotificationType(Integer id)
Specified by:
getNotificationType in interface TimerMBean

getNotificationUserData

public Object getNotificationUserData(Integer id)
Specified by:
getNotificationUserData in interface TimerMBean

getPeriod

public Long getPeriod(Integer id)
Specified by:
getPeriod in interface TimerMBean

getSendPastNotifications

public boolean getSendPastNotifications()
Specified by:
getSendPastNotifications in interface TimerMBean

isActive

public boolean isActive()
Specified by:
isActive in interface TimerMBean

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface TimerMBean

removeAllNotifications

public void removeAllNotifications()
Specified by:
removeAllNotifications in interface TimerMBean

removeNotification

public void removeNotification(Integer id)
                        throws InstanceNotFoundException
Specified by:
removeNotification in interface TimerMBean
Throws:
InstanceNotFoundException

removeNotifications

public void removeNotifications(String type)
                         throws InstanceNotFoundException
Specified by:
removeNotifications in interface TimerMBean
Throws:
InstanceNotFoundException

setSendPastNotifications

public void setSendPastNotifications(boolean value)
Specified by:
setSendPastNotifications in interface TimerMBean

start

public void start()
Specified by:
start in interface TimerMBean

stop

public void stop()
Specified by:
stop in interface TimerMBean

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName objectName)
                       throws Exception
Specified by:
preRegister in interface MBeanRegistration
Throws:
Exception

postRegister

public void postRegister(Boolean registrationDone)
Specified by:
postRegister in interface MBeanRegistration

preDeregister

public void preDeregister()
                   throws Exception
Specified by:
preDeregister in interface MBeanRegistration
Throws:
Exception

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface MBeanRegistration


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.