| Method from org.jboss.varia.scheduler.Scheduler Detail: |
public String getDateFormat() {
if (mDateFormatter == null)
mDateFormatter = new SimpleDateFormat();
return mDateFormatter.toPattern();
}
|
public boolean getFixedRate() {
return mFixedRate;
}
|
public long getInitialRepetitions() {
return mInitialRepetitions;
}
|
public String getInitialStartDate() {
return mStartDateString;
}
|
public long getRemainingRepetitions() {
return mRemainingRepetitions;
}
|
public String getSchedulableArgumentTypes() {
return mSchedulableArgumentTypes;
}
|
public String getSchedulableArguments() {
return mSchedulableArguments;
}
|
public String getSchedulableClass() {
if (mSchedulableClass == null)
{
return null;
}
return mSchedulableClass.getName();
}
|
public String getSchedulableMBean() {
return mSchedulableMBean == null ?
null :
mSchedulableMBean.toString();
}
|
public String getSchedulableMBeanMethod() {
return mSchedulableMBeanMethod;
}
|
public long getSchedulePeriod() {
return mSchedulePeriod;
}
|
public String getTimerName() {
return mTimerName;
}
|
public boolean isActive() {
return isStarted() && mRemainingRepetitions != 0;
}
|
public boolean isRestartPending() {
return mIsRestartPending;
}
|
public boolean isStartAtStartup() {
return mStartOnStart;
}
|
public boolean isStarted() {
return mScheduleIsStarted;
}
|
public boolean isUsingMBean() {
return mUseMBean;
}
|
public void restartSchedule() {
stopSchedule();
startSchedule();
}
Stops the server right now and starts it right now. |
public void setDateFormat(String dateFormat) {
if (dateFormat == null || dateFormat.trim().length() == 0)
mDateFormatter = new SimpleDateFormat();
else
mDateFormatter = new SimpleDateFormat(dateFormat);
}
Sets the date format used to parse date/times |
public void setFixedRate(boolean fixedRate) {
mFixedRate = fixedRate;
}
|
public void setInitialRepetitions(long pNumberOfCalls) {
if (pNumberOfCalls < = 0)
{
pNumberOfCalls = -1;
}
mInitialRepetitions = pNumberOfCalls;
mIsRestartPending = true;
}
Sets the initial number of scheduled calls. |
public void setInitialStartDate(String pStartDate) {
mStartDateString = pStartDate == null ? "" : pStartDate.trim();
if (mStartDateString.equals(""))
{
mStartDate = new Date(0);
}
else if (mStartDateString.equals("NOW"))
{
mStartDate = getNow();
mStartDateIsNow = true;
}
else
{
try
{
long lDate = new Long(pStartDate).longValue();
mStartDate = new Date(lDate);
mStartDateIsNow = false;
}
catch (NumberFormatException e)
{
try
{
if (mDateFormatter == null)
{
mDateFormatter = new SimpleDateFormat();
}
mStartDate = mDateFormatter.parse(mStartDateString);
mStartDateIsNow = false;
}
catch (Exception e2)
{
log.error("Could not parse given date string: " + mStartDateString, e2);
throw new InvalidParameterException("Schedulable Date is not of correct format: " + mStartDateString);
}
}
}
log.debug("Initial Start Date is set to: " + mStartDate);
}
Sets the first scheduled call. If the date is in the past the scheduler tries to find the
next available start date. |
public void setSchedulableArgumentTypes(String pTypeList) throws InvalidParameterException {
if (pTypeList == null || pTypeList.equals(""))
{
mSchedulableArgumentTypeList = new Class[0];
}
else
{
StringTokenizer lTokenizer = new StringTokenizer(pTypeList, ",");
Vector lList = new Vector();
while (lTokenizer.hasMoreTokens())
{
String lToken = lTokenizer.nextToken().trim();
// Get the class
Class lClass = null;
if (lToken.equals("short"))
{
lClass = Short.TYPE;
}
else if (lToken.equals("int"))
{
lClass = Integer.TYPE;
}
else if (lToken.equals("long"))
{
lClass = Long.TYPE;
}
else if (lToken.equals("byte"))
{
lClass = Byte.TYPE;
}
else if (lToken.equals("char"))
{
lClass = Character.TYPE;
}
else if (lToken.equals("float"))
{
lClass = Float.TYPE;
}
else if (lToken.equals("double"))
{
lClass = Double.TYPE;
}
else if (lToken.equals("boolean"))
{
lClass = Boolean.TYPE;
}
if (lClass == null)
{
try
{
// Load class to check if available
ClassLoader loader = TCLActions.getContextClassLoader();
lClass = loader.loadClass(lToken);
}
catch (ClassNotFoundException cnfe)
{
throw new InvalidParameterException(
"The argument type: " + lToken + " is not a valid class or could not be found"
);
}
}
lList.add(lClass);
}
mSchedulableArgumentTypeList = (Class[]) lList.toArray(new Class[0]);
}
mSchedulableArgumentTypes = pTypeList;
mIsRestartPending = true;
}
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. |
public void setSchedulableArguments(String pArgumentList) {
if (pArgumentList == null || pArgumentList.equals(""))
{
mSchedulableArgumentList = new String[0];
}
else
{
StringTokenizer lTokenizer = new StringTokenizer(pArgumentList, ",");
Vector lList = new Vector();
while (lTokenizer.hasMoreTokens())
{
String lToken = lTokenizer.nextToken().trim();
if (lToken.equals(""))
{
lList.add("null");
}
else
{
lList.add(lToken);
}
}
mSchedulableArgumentList = (String[]) lList.toArray(new String[0]);
}
mSchedulableArguments = pArgumentList;
mIsRestartPending = true;
}
|
public void setSchedulableClass(String pSchedulableClass) throws InvalidParameterException {
if (pSchedulableClass == null || pSchedulableClass.equals(""))
{
throw new InvalidParameterException("Schedulable Class cannot be empty or undefined");
}
try
{
// Try to load the Schedulable Class
ClassLoader loader = TCLActions.getContextClassLoader();
mSchedulableClass = loader.loadClass(pSchedulableClass);
// Check if instance of Schedulable
if (!isSchedulable(mSchedulableClass))
{
String msg = "Given class " + pSchedulableClass + " is not instance of Schedulable";
StringBuffer info = new StringBuffer(msg);
info.append("\nThe SchedulableClass info:");
Classes.displayClassInfo(mSchedulableClass, info);
info.append("\nSchedulable.class info:");
Classes.displayClassInfo(Schedulable.class, info);
log.debug(info.toString());
throw new InvalidParameterException(msg);
}
}
catch (ClassNotFoundException e)
{
log.info("Failed to find: "+pSchedulableClass, e);
throw new InvalidParameterException(
"Given class " + pSchedulableClass + " is not not found"
);
}
mIsRestartPending = true;
mUseMBean = false;
}
|
public void setSchedulableMBean(String pSchedulableMBean) throws InvalidParameterException {
if (pSchedulableMBean == null)
{
throw new InvalidParameterException("Schedulable MBean must be specified");
}
try
{
mSchedulableMBean = new ObjectName(pSchedulableMBean);
mUseMBean = true;
}
catch (MalformedObjectNameException e)
{
throw new InvalidParameterException("Schedulable MBean name invalid " + pSchedulableMBean);
}
}
Sets the fully qualified JMX MBean name of the Schedulable MBean to be called.
Attention: if set the all values set by #setSchedulableClass ,
#setSchedulableArguments and #setSchedulableArgumentTypes are
cleared and not used anymore. Therefore only use either Schedulable Class or
Schedulable MBean. If #setSchedulableMBeanMethod is not set then the
schedule method as in the Schedulable#perform 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. |
public void setSchedulableMBeanMethod(String pSchedulableMBeanMethod) throws InvalidParameterException {
if (pSchedulableMBeanMethod == null)
{
mSchedulableMBeanMethod = null;
return;
}
int lIndex = pSchedulableMBeanMethod.indexOf('(');
String lMethodName;
if (lIndex == -1)
{
lMethodName = pSchedulableMBeanMethod.trim();
mSchedulableMBeanArguments = new int[0];
mSchedulableMBeanArgumentTypes = new String[0];
}
else
{
lMethodName = pSchedulableMBeanMethod.substring(0, lIndex).trim();
}
if (lMethodName.equals(""))
{
lMethodName = "perform";
}
if (lIndex >= 0)
{
int lIndex2 = pSchedulableMBeanMethod.indexOf(')');
if (lIndex2 < lIndex)
{
throw new InvalidParameterException("Schedulable MBean Method: closing bracket must be after opening bracket");
}
if (lIndex2 < pSchedulableMBeanMethod.length() - 1)
{
String lRest = pSchedulableMBeanMethod.substring(lIndex2 + 1).trim();
if (lRest.length() > 0)
{
throw new InvalidParameterException("Schedulable MBean Method: nothing should be after closing bracket");
}
}
String lArguments = pSchedulableMBeanMethod.substring(lIndex + 1, lIndex2).trim();
if (lArguments.equals(""))
{
mSchedulableMBeanArguments = new int[0];
mSchedulableMBeanArgumentTypes = new String[0];
}
else
{
StringTokenizer lTokenizer = new StringTokenizer(lArguments, ", ");
mSchedulableMBeanArguments = new int[lTokenizer.countTokens()];
mSchedulableMBeanArgumentTypes = new String[lTokenizer.countTokens()];
for (int i = 0; lTokenizer.hasMoreTokens(); i++)
{
String lToken = lTokenizer.nextToken().trim();
if (lToken.equals("NOTIFICATION"))
{
mSchedulableMBeanArguments[i] = NOTIFICATION;
mSchedulableMBeanArgumentTypes[i] = Notification.class.getName();
}
else if (lToken.equals("DATE"))
{
mSchedulableMBeanArguments[i] = DATE;
mSchedulableMBeanArgumentTypes[i] = Date.class.getName();
}
else if (lToken.equals("REPETITIONS"))
{
mSchedulableMBeanArguments[i] = REPETITIONS;
mSchedulableMBeanArgumentTypes[i] = Long.TYPE.getName();
}
else if (lToken.equals("SCHEDULER_NAME"))
{
mSchedulableMBeanArguments[i] = SCHEDULER_NAME;
mSchedulableMBeanArgumentTypes[i] = ObjectName.class.getName();
}
else
{
mSchedulableMBeanArguments[i] = NULL;
//AS ToDo: maybe later to check if this class exists !
mSchedulableMBeanArgumentTypes[i] = lToken;
}
}
}
}
mSchedulableMBeanMethodName = lMethodName;
mSchedulableMBeanMethod = pSchedulableMBeanMethod;
}
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 ). |
public void setSchedulePeriod(long pPeriod) {
if (pPeriod < = 0)
{
throw new InvalidParameterException("Schedulable Period may be not less or equals than 0");
}
mSchedulePeriod = pPeriod;
mIsRestartPending = true;
}
Sets the Schedule Period between two scheduled call. |
public void setStartAtStartup(boolean pStartAtStartup) {
mStartOnStart = 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. |
public void setTimerName(String pTimerName) {
mTimerName = pTimerName;
}
|
public void startSchedule() {
if (isStarted())
{
log.debug("already started");
return;
}
if (mUseMBean)
{
checkMBean();
}
else
{
createSchedulable();
}
mRemainingRepetitions = mInitialRepetitions;
mActualSchedulePeriod = mSchedulePeriod;
initStartDate();
log.debug("Schedule initial call to: " + mStartDate + ", remaining repetitions: " + mRemainingRepetitions);
mNotificationID = mTimer.addNotification(
"Schedule", "Scheduler Notification",
null, // new Integer(getID()), // User Object
mStartDate,
new Long(mActualSchedulePeriod),
mRemainingRepetitions < 0 ? new Long(0) : new Long(mRemainingRepetitions),
Boolean.valueOf(mFixedRate)
);
mListener = mUseMBean ? new MBeanListener() : new PojoScheduler();
mTimerEmitter.addNotificationListener(
mListener,
new ScheduleManager.IdNotificationFilter(mNotificationID),
null
);
mScheduleIsStarted = true;
mIsRestartPending = false;
}
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. |
protected void startService() throws Exception {
mTimerObjectName = new ObjectName(mTimerName);
if (!getServer().isRegistered(mTimerObjectName))
{
getServer().createMBean(Timer.class.getName(), mTimerObjectName);
}
mTimer = (TimerMBean)MBeanServerInvocationHandler.newProxyInstance(getServer(),
mTimerObjectName, TimerMBean.class, true);
mTimerEmitter = (NotificationEmitter)mTimer;
if (!mTimer.isActive())
{
mTimer.start();
}
if (mStartOnStart)
{
log.debug("Start Scheduler on start up time");
startSchedule();
}
}
|
public void stopSchedule() {
stopSchedule(true);
}
Stops the schedule immediately. |
public void stopSchedule(boolean pDoItNow) {
log.debug("stopSchedule(" + pDoItNow + ")");
try
{
if (mNotificationID < 0)
{
mScheduleIsStarted = false;
mWaitForNextCallToStop = false;
return;
}
if (pDoItNow)
{
log.debug("stopSchedule(), removing schedule id: " + mNotificationID);
mWaitForNextCallToStop = false;
if (mListener != null)
{
mTimerEmitter.removeNotificationListener(mListener);
try
{
mTimer.removeNotification(mNotificationID);
}
catch (InstanceNotFoundException e)
{
log.trace(e);
}
mListener = null;
}
mNotificationID = -1;
mScheduleIsStarted = false;
}
else
{
mWaitForNextCallToStop = true;
}
}
catch (Exception e)
{
log.error("stopSchedule failed", e);
}
}
Stops the schedule because it is either not used anymore or to restart it with
new values. |
protected void stopService() {
stopSchedule();
}
|