当前页面:
在线文档首页 >
JBoss 4.0.1 sp1 varia API Documentation 英文版文档
Scheduler (Various API) - JBoss 4.0.1 sp1 varia API Documentation 英文版文档
org.jboss.varia.scheduler
Class Scheduler
java.lang.Object
org.jboss.mx.util.JBossNotificationBroadcasterSupport
org.jboss.system.ServiceMBeanSupport
org.jboss.varia.scheduler.Scheduler
- All Implemented Interfaces:
- javax.management.MBeanRegistration, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, SchedulerMBean, org.jboss.system.Service, org.jboss.system.ServiceMBean
- public class Scheduler
- extends org.jboss.system.ServiceMBeanSupport
- implements SchedulerMBean
Scheduler Instance to allow clients to run this as a scheduling service for
any Schedulable instances.
ATTENTION: The scheduler instance only allows to run one schedule at a time.
Therefore when you want to run two schedules create to instances with this
MBean. Suggested Object Name for the MBean are:
:service=Scheduler,schedule=
This way you should not run into a name conflict.
- Version:
- $Revision: 1.12.4.1 $
- Author:
- Andreas Schaefer, Cameron (camtabor)
Fields inherited from class org.jboss.system.ServiceMBeanSupport |
log, server, SERVICE_CONTROLLER_SIG, serviceName |
Fields inherited from interface org.jboss.system.ServiceMBean |
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, START_EVENT, STARTED, STARTING, states, STOP_EVENT, STOPPED, STOPPING, UNREGISTERED |
Constructor Summary |
Scheduler()
Default (no-args) Constructor |
Scheduler(String pSchedulableClass,
String pInitArguments,
String pInitTypes,
String pInitialStartDate,
long pSchedulePeriod,
long pNumberOfRepetitions)
|
Scheduler(String pSchedulableClass,
String pInitArguments,
String pInitTypes,
String pDateFormat,
String pInitialStartDate,
long pSchedulePeriod,
long pNumberOfRepetitions)
|
Methods inherited from class org.jboss.system.ServiceMBeanSupport |
create, createService, destroy, destroyService, getLog, getName, getNextNotificationSequenceNumber, getObjectName, getServer, getServiceName, getState, getStateString, jbossInternalCreate, jbossInternalDescription, jbossInternalDestroy, jbossInternalLifecycle, jbossInternalStart, jbossInternalStop, postDeregister, postRegister, preDeregister, preRegister, start, stop |
Methods inherited from class org.jboss.mx.util.JBossNotificationBroadcasterSupport |
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.jboss.system.ServiceMBean |
getName, getState, getStateString, jbossInternalLifecycle |
Methods inherited from interface org.jboss.system.Service |
create, destroy, start, stop |
JNDI_NAME
public static String JNDI_NAME
JMX_NAME
public static String JMX_NAME
DEFAULT_TIMER_NAME
public static String DEFAULT_TIMER_NAME
- Default Timer Object Name
Scheduler
public Scheduler()
- Default (no-args) Constructor
Scheduler
public Scheduler(String pSchedulableClass,
String pInitArguments,
String pInitTypes,
String pInitialStartDate,
long pSchedulePeriod,
long pNumberOfRepetitions)
- Parameters:
pSchedulableClass
- pInitArguments
- pInitTypes
- pInitialStartDate
- pSchedulePeriod
- pNumberOfRepetitions
-
Scheduler
public Scheduler(String pSchedulableClass,
String pInitArguments,
String pInitTypes,
String pDateFormat,
String pInitialStartDate,
long pSchedulePeriod,
long pNumberOfRepetitions)
- Parameters:
pSchedulableClass
- pInitArguments
- pInitTypes
- pDateFormat
- pInitialStartDate
- pSchedulePeriod
- pNumberOfRepetitions
-
startSchedule
public void startSchedule()
- Starts the schedule if the schedule is stopped otherwise nothing will happen.
The Schedule is immediately set to started even the first call is in the
future.
- Specified by:
startSchedule
in interface SchedulerMBean
- Throws:
InvalidParameterException
- If any of the necessary values are not set
or invalid (especially for the Schedulable
class attributes).
stopSchedule
public void stopSchedule(boolean pDoItNow)
- Stops the schedule because it is either not used anymore or to restart it with
new values.
- Specified by:
stopSchedule
in interface SchedulerMBean
- Parameters:
pDoItNow
- If true the schedule will be stopped without waiting for the next
scheduled call otherwise the next call will be performed before
the schedule is stopped.
restartSchedule
public void restartSchedule()
- Stops the server right now and starts it right now.
- Specified by:
restartSchedule
in interface SchedulerMBean
getSchedulableClass
public String getSchedulableClass()
- Specified by:
getSchedulableClass
in interface SchedulerMBean
- Returns:
- Full qualified Class name of the schedulable class called by the schedule or
null if not set.
setSchedulableClass
public void setSchedulableClass(String pSchedulableClass)
throws InvalidParameterException
- Sets the fully qualified Class name of the Schedulable Class being called by the
Scheduler. Must be set before the Schedule is started. Please also set the
setSchedulableArguments(java.lang.String)
and setSchedulableArgumentTypes(java.lang.String)
.
- Specified by:
setSchedulableClass
in interface SchedulerMBean
- Parameters:
pSchedulableClass
- Fully Qualified Schedulable Class.
- Throws:
InvalidParameterException
- If the given value is not a valid class or cannot
be loaded by the Scheduler or is not of instance
Schedulable.
getSchedulableArguments
public String getSchedulableArguments()
- Specified by:
getSchedulableArguments
in interface SchedulerMBean
- Returns:
- Comma seperated list of Constructor Arguments used to instantiate the
Schedulable class instance. Right now only basic data types, String and
Classes with a Constructor with a String as only argument are supported.
setSchedulableArguments
public void setSchedulableArguments(String pArgumentList)
- Specified by:
setSchedulableArguments
in interface SchedulerMBean
- Parameters:
pArgumentList
- List of arguments used to create the Schedulable intance. If
the list is null or empty then the no-args constructor is used.
getSchedulableArgumentTypes
public String getSchedulableArgumentTypes()
- Specified by:
getSchedulableArgumentTypes
in interface SchedulerMBean
- Returns:
- A comma seperated list of Argument Types which should match the list of
arguments.
setSchedulableArgumentTypes
public void setSchedulableArgumentTypes(String pTypeList)
throws InvalidParameterException
- Sets the comma seperated list of argument types for the Schedulable class. This will
be used to find the right constructor and to created the right instances to call the
constructor with. This list must have as many elements as the Schedulable Arguments
list otherwise the start of the Scheduler will fail. Right now only basic data types,
String and Classes with a Constructor with a String as only argument are supported.
- Specified by:
setSchedulableArgumentTypes
in interface SchedulerMBean
- Parameters:
pTypeList
- List of arguments used to create the Schedulable intance. If
the list is null or empty then the no-args constructor is used.
- Throws:
InvalidParameterException
- If the given list contains a unknow datat type.
getSchedulableMBean
public String getSchedulableMBean()
- Specified by:
getSchedulableMBean
in interface SchedulerMBean
- Returns:
- Object Name if a Schedulalbe MBean is set
setSchedulableMBean
public void setSchedulableMBean(String pSchedulableMBean)
throws InvalidParameterException
- Sets the fully qualified JMX MBean name of the Schedulable MBean to be called.
Attention: if set the all values set by
setSchedulableClass(java.lang.String)
,
setSchedulableArguments(java.lang.String)
and setSchedulableArgumentTypes(java.lang.String)
are
cleared and not used anymore. Therefore only use either Schedulable Class or
Schedulable MBean. If setSchedulableMBeanMethod(java.lang.String)
is not set then the
schedule method as in the Schedulable.perform(java.util.Date, long)
will be called with the
same arguments. Also note that the Object Name will not be checked if the
MBean is available. If the MBean is not available it will not be called but
the remaining repetitions will be decreased.
- Specified by:
setSchedulableMBean
in interface SchedulerMBean
- Parameters:
pSchedulableMBean
- JMX MBean Object Name which should be called.
- Throws:
InvalidParameterException
- If the given value is an valid Object Name.
getSchedulableMBeanMethod
public String getSchedulableMBeanMethod()
- Returns:
- Schedulable MBean Method description if set
setSchedulableMBeanMethod
public void setSchedulableMBeanMethod(String pSchedulableMBeanMethod)
throws InvalidParameterException
- Sets the method name to be called on the Schedulable MBean. It can optionally be
followed by an opening bracket, list of attributes (see below) and a closing bracket.
The list of attributes can contain:
- NOTIFICATION which will be replaced by the timers notification instance
(javax.management.Notification)
- DATE which will be replaced by the date of the notification call
(java.util.Date)
- REPETITIONS which will be replaced by the number of remaining repetitions
(long)
- SCHEDULER_NAME which will be replaced by the Object Name of the Scheduler
(javax.management.ObjectName)
- any full qualified Class name which the Scheduler will be set a "null" value
for it
An example could be: "doSomething( NOTIFICATION, REPETITIONS, java.lang.String )"
where the Scheduler will pass the timer's notification instance, the remaining
repetitions as int and a null to the MBean's doSomething() method which must
have the following signature: doSomething( javax.management.Notification, long,
java.lang.String ).
- Specified by:
setSchedulableMBeanMethod
in interface SchedulerMBean
- Parameters:
pSchedulableMBeanMethod
- Name of the method to be called optional followed
by method arguments (see above).
- Throws:
InvalidParameterException
- If the given value is not of the right
format
isUsingMBean
public boolean isUsingMBean()
- Specified by:
isUsingMBean
in interface SchedulerMBean
- Returns:
- True if the Scheduler uses a Schedulable MBean, false if it uses a
Schedulable class
getSchedulePeriod
public long getSchedulePeriod()
- Specified by:
getSchedulePeriod
in interface SchedulerMBean
- Returns:
- Schedule Period between two scheduled calls in Milliseconds. It will always
be bigger than 0 except it returns -1 then the schedule is stopped.
setSchedulePeriod
public void setSchedulePeriod(long pPeriod)
- Sets the Schedule Period between two scheduled call.
- Specified by:
setSchedulePeriod
in interface SchedulerMBean
- Parameters:
pPeriod
- Time between to scheduled calls (after the initial call) in Milliseconds.
This value must be bigger than 0.
- Throws:
InvalidParameterException
- If the given value is less or equal than 0
getDateFormat
public String getDateFormat()
- Specified by:
getDateFormat
in interface SchedulerMBean
- Returns:
- the date format
setDateFormat
public void setDateFormat(String dateFormat)
- Sets the date format used to parse date/times
- Specified by:
setDateFormat
in interface SchedulerMBean
- Parameters:
dateFormat
- The date format when empty or null the locale is used to parse dates
getInitialStartDate
public String getInitialStartDate()
- Specified by:
getInitialStartDate
in interface SchedulerMBean
- Returns:
- Date (and time) of the first scheduled. For value see
setInitialStartDate(java.lang.String)
method.
setInitialStartDate
public void setInitialStartDate(String pStartDate)
- Sets the first scheduled call. If the date is in the past the scheduler tries to find the
next available start date.
- Specified by:
setInitialStartDate
in interface SchedulerMBean
- Parameters:
pStartDate
- Date when the initial call is scheduled. It can be either:
-
NOW: date will be the current date (new Date()) plus 1 seconds
-
Date as String able to be parsed by SimpleDateFormat with default format
-
Date as String parsed using the date format attribute
-
Milliseconds since 1/1/1970
If the date is in the past the Scheduler
will search a start date in the future with respect to the initial repe-
titions and the period between calls. This means that when you restart
the MBean (restarting JBoss etc.) it will start at the next scheduled
time. When no start date is available in the future the Scheduler will
not start.
Example: if you start your Schedulable everyday at Noon and you restart
your JBoss server then it will start at the next Noon (the same if started
before Noon or the next day if start after Noon).
getInitialRepetitions
public long getInitialRepetitions()
- Specified by:
getInitialRepetitions
in interface SchedulerMBean
- Returns:
- Number of scheduled calls initially. If -1 then there is not limit.
setInitialRepetitions
public void setInitialRepetitions(long pNumberOfCalls)
- Sets the initial number of scheduled calls.
- Specified by:
setInitialRepetitions
in interface SchedulerMBean
- Parameters:
pNumberOfCalls
- Initial Number of scheduled calls. If -1 then the number
is unlimted.
- Throws:
InvalidParameterException
- If the given value is less or equal than 0
getRemainingRepetitions
public long getRemainingRepetitions()
- Specified by:
getRemainingRepetitions
in interface SchedulerMBean
- Returns:
- Number of remaining repetitions. If -1 then there is no limit.
isStarted
public boolean isStarted()
- Specified by:
isStarted
in interface SchedulerMBean
- Returns:
- True if the schedule is up and running. If you want to start the schedule
with another values by using you have to stop the schedule
first with and wait until this method returns false.
isRestartPending
public boolean isRestartPending()
- Specified by:
isRestartPending
in interface SchedulerMBean
- Returns:
- True if any attributes are changed but the Schedule is not restarted yet.
isStartAtStartup
public boolean isStartAtStartup()
- Specified by:
isStartAtStartup
in interface SchedulerMBean
- Returns:
- True if the Schedule when the Scheduler is started
setStartAtStartup
public void setStartAtStartup(boolean pStartAtStartup)
- Set the scheduler to start when MBean started or not. Note that this method only
affects when the
startService()
gets called (normally at
startup time.
- Specified by:
setStartAtStartup
in interface SchedulerMBean
- Parameters:
pStartAtStartup
- True if Schedule has to be started at startup time
isActive
public boolean isActive()
- Specified by:
isActive
in interface SchedulerMBean
- Returns:
- True if this Scheduler is active and will send notifications in the future
getTimerName
public String getTimerName()
- Specified by:
getTimerName
in interface SchedulerMBean
- Returns:
- Name of the Timer MBean used in here
setTimerName
public void setTimerName(String pTimerName)
- Specified by:
setTimerName
in interface SchedulerMBean
- Parameters:
pTimerName
- Object Name of the Timer MBean to
be used. If null or not a valid ObjectName
the default will be used
startService
protected void startService()
throws Exception
- Throws:
Exception
stopService
protected void stopService()
Copyright © 2002 JBoss Group, LLC. All Rights Reserved.