User: schaefera
Date: 02/01/18 10:48:12
Modified: src/main/org/jboss/util Scheduler.java SchedulerMBean.java
Added: src/main/org/jboss/util SchedulableExample.java
SchedulableExampleMBean.java
Log:
Enable the Scheduler to work with another Schedulable MBean instead of the
Schedulable class
Revision Changes Path
1.16 +306 -74 jboss/src/main/org/jboss/util/Scheduler.java
Index: Scheduler.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/util/Scheduler.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Scheduler.java 2002/01/17 21:57:27 1.15
+++ Scheduler.java 2002/01/18 18:48:12 1.16
@@ -89,40 +89,56 @@
// -------------------------------------------------------------------------
// Constants
// -------------------------------------------------------------------------
-
+
+ /** Class logger. */
+ private static final Logger log = Logger.getLogger( Scheduler.class );
+
public static String JNDI_NAME = "scheduler:domain";
public static String JMX_NAME = "scheduler";
-
+
+ private static final int NOTIFICATION = 0;
+ private static final int DATE = 1;
+ private static final int REPETITIONS = 2;
+ private static final int SCHEDULER_NAME = 3;
+ private static final int NULL = 4;
+
// -------------------------------------------------------------------------
// Members
// -------------------------------------------------------------------------
-
- /** Class logger. */
- private static final Logger log = Logger.getLogger( Scheduler.class );
-
+
private long mActualSchedulePeriod;
private long mRemainingRepetitions = 0;
private int mActualSchedule = -1;
private ObjectName mTimer;
private Schedulable mSchedulable;
-
+//as private Object mSchedulableMBeanObjectName;
+
private boolean mScheduleIsStarted = false;
private boolean mWaitForNextCallToStop = false;
private boolean mStartOnStart = false;
private boolean mIsRestartPending = true;
-
+
// Pending values which can be different to the actual ones
+ private boolean mUseMBean = false;
+
private Class mSchedulableClass;
private String mSchedulableArguments;
private String[] mSchedulableArgumentList = new String[ 0 ];
private String mSchedulableArgumentTypes;
private Class[] mSchedulableArgumentTypeList = new Class[ 0 ];
+
+ private ObjectName mSchedulableMBean;
+ private String mSchedulableMBeanMethod;
+ private String mSchedulableMBeanMethodName;
+ private int[] mSchedulableMBeanArguments = new int[ 0 ];
+ private String[] mSchedulableMBeanArgumentTypes = new String[ 0 ];
+
private DateFormat mDateFormatter;
private Date mStartDate;
private String mStartDateString;
private long mSchedulePeriod;
private long mInitialRepetitions;
-
+
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
@@ -165,17 +181,34 @@
if( !isStarted() ) {
try {
// Check the given attributes if correct
- if( mSchedulableClass == null ) {
- log.debug( "Schedulable Class is not set" );
- throw new InvalidParameterException(
- "Schedulable Class must be set"
- );
- }
- if( mSchedulableArgumentList.length !=
mSchedulableArgumentTypeList.length ) {
- log.debug( "Schedulable Class Arguments and Types do not match in
length" );
- throw new InvalidParameterException(
- "Schedulable Class Arguments and Types do not match in length"
- );
+ if( mUseMBean ) {
+ if( mSchedulableMBean == null ) {
+ log.debug( "Schedulable MBean Object Name is not set" );
+ throw new InvalidParameterException(
+ "Schedulable MBean must be set"
+ );
+ }
+ if( mSchedulableMBeanMethodName == null ) {
+ mSchedulableMBeanMethodName = "perform";
+ mSchedulableMBeanArguments = new int[] { DATE, REPETITIONS };
+ mSchedulableMBeanArgumentTypes = new String[] {
+ Date.class.getName(),
+ Integer.TYPE.getName()
+ };
+ }
+ } else {
+ if( mSchedulableClass == null ) {
+ log.debug( "Schedulable Class is not set" );
+ throw new InvalidParameterException(
+ "Schedulable Class must be set"
+ );
+ }
+ if( mSchedulableArgumentList.length !=
mSchedulableArgumentTypeList.length ) {
+ log.debug( "Schedulable Class Arguments and Types do not match in
length" );
+ throw new InvalidParameterException(
+ "Schedulable Class Arguments and Types do not match in length"
+ );
+ }
}
if( mSchedulePeriod <= 0 ) {
log.debug( "Schedule Period is less than 0 (ms)" );
@@ -183,53 +216,55 @@
"Schedule Period must be set and greater than 0 (ms)"
);
}
- // Create all the Objects for the Constructor to be called
- Object[] lArgumentList = new Object[
mSchedulableArgumentTypeList.length ];
- try {
- for( int i = 0; i < mSchedulableArgumentTypeList.length; i++ ) {
- Class lClass = mSchedulableArgumentTypeList[ i ];
- if( lClass == Boolean.TYPE ) {
- lArgumentList[ i ] = new Boolean( mSchedulableArgumentList[ i
] );
- } else
- if( lClass == Integer.TYPE ) {
- lArgumentList[ i ] = new Integer( mSchedulableArgumentList[ i
] );
- } else
- if( lClass == Long.TYPE ) {
- lArgumentList[ i ] = new Long( mSchedulableArgumentList[ i ] );
- } else
- if( lClass == Short.TYPE ) {
- lArgumentList[ i ] = new Short( mSchedulableArgumentList[ i ]
);
- } else
- if( lClass == Float.TYPE ) {
- lArgumentList[ i ] = new Float( mSchedulableArgumentList[ i ]
);
- } else
- if( lClass == Double.TYPE ) {
- lArgumentList[ i ] = new Double( mSchedulableArgumentList[ i ]
);
- } else
- if( lClass == Byte.TYPE ) {
- lArgumentList[ i ] = new Byte( mSchedulableArgumentList[ i ] );
- } else
- if( lClass == Character.TYPE ) {
- lArgumentList[ i ] = new Character( mSchedulableArgumentList[
i ].charAt( 0 ) );
- } else {
- Constructor lConstructor = lClass.getConstructor( new Class[]
{ String.class } );
- lArgumentList[ i ] = lConstructor.newInstance( new Object[] {
mSchedulableArgumentList[ i ] } );
+ if( !mUseMBean ) {
+ // Create all the Objects for the Constructor to be called
+ Object[] lArgumentList = new Object[
mSchedulableArgumentTypeList.length ];
+ try {
+ for( int i = 0; i < mSchedulableArgumentTypeList.length; i++ ) {
+ Class lClass = mSchedulableArgumentTypeList[ i ];
+ if( lClass == Boolean.TYPE ) {
+ lArgumentList[ i ] = new Boolean( mSchedulableArgumentList[
i ] );
+ } else
+ if( lClass == Integer.TYPE ) {
+ lArgumentList[ i ] = new Integer( mSchedulableArgumentList[
i ] );
+ } else
+ if( lClass == Long.TYPE ) {
+ lArgumentList[ i ] = new Long( mSchedulableArgumentList[ i
] );
+ } else
+ if( lClass == Short.TYPE ) {
+ lArgumentList[ i ] = new Short( mSchedulableArgumentList[ i
] );
+ } else
+ if( lClass == Float.TYPE ) {
+ lArgumentList[ i ] = new Float( mSchedulableArgumentList[ i
] );
+ } else
+ if( lClass == Double.TYPE ) {
+ lArgumentList[ i ] = new Double( mSchedulableArgumentList[
i ] );
+ } else
+ if( lClass == Byte.TYPE ) {
+ lArgumentList[ i ] = new Byte( mSchedulableArgumentList[ i
] );
+ } else
+ if( lClass == Character.TYPE ) {
+ lArgumentList[ i ] = new Character(
mSchedulableArgumentList[ i ].charAt( 0 ) );
+ } else {
+ Constructor lConstructor = lClass.getConstructor( new
Class[] { String.class } );
+ lArgumentList[ i ] = lConstructor.newInstance( new Object[]
{ mSchedulableArgumentList[ i ] } );
+ }
}
}
- }
- catch( Exception e ) {
- log.error( "Could not load or create constructor argument", e );
- throw new InvalidParameterException( "Could not load or create a
constructor argument" );
- }
- try {
- // Check if constructor is found
- Constructor lSchedulableConstructor =
mSchedulableClass.getConstructor( mSchedulableArgumentTypeList );
- // Create an instance of it
- mSchedulable = (Schedulable) lSchedulableConstructor.newInstance(
lArgumentList );
- }
- catch( Exception e ) {
- log.error( "Could not find the constructor or create Schedulable
instance", e );
- throw new InvalidParameterException( "Could not find the constructor
or create the Schedulable Instance" );
+ catch( Exception e ) {
+ log.error( "Could not load or create constructor argument", e );
+ throw new InvalidParameterException( "Could not load or create a
constructor argument" );
+ }
+ try {
+ // Check if constructor is found
+ Constructor lSchedulableConstructor =
mSchedulableClass.getConstructor( mSchedulableArgumentTypeList );
+ // Create an instance of it
+ mSchedulable = (Schedulable) lSchedulableConstructor.newInstance(
lArgumentList );
+ }
+ catch( Exception e ) {
+ log.error( "Could not find the constructor or create Schedulable
instance", e );
+ throw new InvalidParameterException( "Could not find the
constructor or create the Schedulable Instance" );
+ }
}
mRemainingRepetitions = mInitialRepetitions;
@@ -279,14 +314,25 @@
Long.TYPE.getName()
}
) ).intValue();
- // Register the notification listener at the MBeanServer
- getServer().addNotificationListener(
- mTimer,
- new Listener( mSchedulable ),
- new Scheduler.NotificationFilter( new Integer( mActualSchedule ) ),
- // No object handback necessary
- null
- );
+ if( mUseMBean ) {
+ // Register the notification listener at the MBeanServer
+ getServer().addNotificationListener(
+ mTimer,
+ new MBeanListener( mSchedulableMBean ),
+ new Scheduler.NotificationFilter( new Integer( mActualSchedule )
),
+ // No object handback necessary
+ null
+ );
+ } else {
+ // Register the notification listener at the MBeanServer
+ getServer().addNotificationListener(
+ mTimer,
+ new Listener( mSchedulable ),
+ new Scheduler.NotificationFilter( new Integer( mActualSchedule )
),
+ // No object handback necessary
+ null
+ );
+ }
mScheduleIsStarted = true;
mIsRestartPending = false;
}
@@ -461,7 +507,105 @@
mSchedulableArgumentTypes = pTypeList;
mIsRestartPending = true;
}
-
+
+ public String getSchedulableMBean() {
+ return mSchedulableMBean == null ?
+ null :
+ mSchedulableMBean.toString();
+ }
+
+ 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 mone ) {
+ log.error( "Schedulable MBean Object Name is malformed", mone );
+ throw new InvalidParameterException( "Schedulable MBean is not correctly
formatted" );
+ }
+ }
+
+ public String getSchedulableMBeanMethod() {
+ return mSchedulableMBeanMethod;
+ }
+
+ public void setSchedulableMBeanMethod( String pSchedulableMBeanMethod )
+ throws InvalidParameterException
+ {
+ if( pSchedulableMBeanMethod == null ) {
+ mSchedulableMBeanMethod = null;
+ return;
+ }
+ int lIndex = pSchedulableMBeanMethod.indexOf( '(' );
+ String lMethodName = "";
+ if( lIndex < 0 ) {
+ lMethodName = pSchedulableMBeanMethod.trim();
+ mSchedulableMBeanArguments = new int[ 0 ];
+ mSchedulableMBeanArgumentTypes = new String[ 0 ];
+ } else
+ if( lIndex > 0 ) {
+ 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;
+ }
+
+ public boolean isUsingMBean() {
+ return mUseMBean;
+ }
+
public long getSchedulePeriod() {
return mSchedulePeriod;
}
@@ -530,6 +674,10 @@
return mIsRestartPending;
}
+ public boolean isStartAtStartup() {
+ return mStartOnStart;
+ }
+
public void setStartAtStartup( boolean pStartAtStartup ) {
mStartOnStart = pStartAtStartup;
}
@@ -620,6 +768,90 @@
lTimeStamp,
getRemainingRepetitions()
);
+ log.debug( "Remaining Repititions: " + getRemainingRepetitions() +
+ ", wait for next call to stop: " + mWaitForNextCallToStop );
+ if( getRemainingRepetitions() == 0 || mWaitForNextCallToStop ) {
+ stopSchedule( true );
+ }
+ }
+ }
+ else {
+ // Schedule is stopped therefore remove the Schedule
+ getServer().invoke(
+ mTimer,
+ "removeNotification",
+ new Object[] {
+ new Integer( mActualSchedule )
+ },
+ new String[] {
+ "java.lang.Integer",
+ }
+ );
+ mActualSchedule = -1;
+ }
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public class MBeanListener
+ implements NotificationListener
+ {
+
+ private ObjectName mDelegate;
+
+ public MBeanListener( ObjectName pDelegate ) {
+ mDelegate = pDelegate;
+ }
+
+ public void handleNotification(
+ Notification pNotification,
+ Object pHandback
+ ) {
+ log.debug( "MBeanListener.handleNotification(), notification: " +
pNotification );
+ try {
+ // If schedule is started invoke the schedule method on the Schedulable
instance
+ log.debug( "Scheduler is started: " + isStarted() );
+ Date lTimeStamp = new Date( pNotification.getTimeStamp() );
+ if( isStarted() ) {
+ if( getRemainingRepetitions() > 0 || getRemainingRepetitions() < 0 )
{
+ if( mRemainingRepetitions > 0 ) {
+ mRemainingRepetitions--;
+ }
+ Object[] lArguments = new Object[
mSchedulableMBeanArguments.length ];
+ for( int i = 0; i < lArguments.length; i++ ) {
+ switch( mSchedulableMBeanArguments[ i ] ) {
+ case NOTIFICATION:
+ lArguments[ i ] = pNotification;
+ break;
+ case DATE:
+ lArguments[ i ] = lTimeStamp;
+ break;
+ case REPETITIONS:
+ lArguments[ i ] = new Long( mRemainingRepetitions );
+ break;
+ case SCHEDULER_NAME:
+ lArguments[ i ] = getServiceName();
+ break;
+ default:
+ lArguments[ i ] = null;
+ }
+ }
+ log.debug( "MBean Arguments are: " + java.util.Arrays.asList(
lArguments ) );
+ log.debug( "MBean Arguments Types are: " +
java.util.Arrays.asList( mSchedulableMBeanArgumentTypes ) );
+ try {
+ getServer().invoke(
+ mDelegate,
+ mSchedulableMBeanMethodName,
+ lArguments,
+ mSchedulableMBeanArgumentTypes
+ );
+ }
+ catch( javax.management.RuntimeOperationsException roe ) {
+ log.error( "Caught ROE in Schedulable MBean Call",
roe.getTargetException() );
+ }
log.debug( "Remaining Repititions: " + getRemainingRepetitions() +
", wait for next call to stop: " + mWaitForNextCallToStop );
if( getRemainingRepetitions() == 0 || mWaitForNextCallToStop ) {
1.9 +79 -1 jboss/src/main/org/jboss/util/SchedulerMBean.java
Index: SchedulerMBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/util/SchedulerMBean.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SchedulerMBean.java 2002/01/17 21:57:27 1.8
+++ SchedulerMBean.java 2002/01/18 18:48:12 1.9
@@ -14,7 +14,14 @@
/**
* This interface defines the manageable interface for a Scheduler Service
* allowing the client to create a Schedulable instance which is then run
- * by this service at given times.
+ * by this service at given times or to use a MBean which is called by this
+ * service at given times.
+ * <br>
+ * <b>Attention: </b> You have two ways to specify the Schedulable. Either
+ * you specify a Schedulable Class which is created and used by the Scheduler
+ * or you specify a JMX MBean which the specified method is called. Note that
+ * the last method of {@link #setSchedulableClass} or {@link #setSchedulableMBean}
+ * defines which one is used. Therefore you should <b>never mixed these two</b>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>
**/
@@ -119,6 +126,72 @@
throws InvalidParameterException;
/**
+ * @return Object Name if a Schedulalbe MBean is set
+ **/
+ public String getSchedulableMBean();
+
+ /**
+ * Sets the fully qualified JMX MBean name of the Schedulable MBean to be called.
+ * <b>Attention: </b>if set the all values set by {@link #setSchedulableClass},
+ * {@link #setSchedulableArguments} and {@link #setSchedulableArgumentTypes} are
+ * cleared and not used anymore. Therefore only use either Schedulable Class or
+ * Schedulable MBean. If {@link #setSchedulableMBeanMethod} is not set then the
+ * schedule method as in the {@link 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.
+ *
+ * @param pSchedulableMBean JMX MBean Object Name which should be called.
+ *
+ * @throws InvalidParameterException If the given value is an valid Object Name.
+ **/
+ public void setSchedulableMBean( String pSchedulableMBean )
+ throws InvalidParameterException;
+
+ /**
+ * @return Schedulable MBean Method description if set
+ **/
+ public String getSchedulableMBeanMethod();
+
+ /**
+ * 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:
+ * <ul>
+ * <li>NOTIFICATION which will be replaced by the timers notification instance
+ * (javax.management.Notification)</li>
+ * <li>DATE which will be replaced by the date of the notification call
+ * (java.util.Date)</li>
+ * <li>REPETITIONS which will be replaced by the number of remaining repetitions
+ * (long)</li>
+ * <li>SCHEDULER_NAME which will be replaced by the Object Name of the Scheduler
+ * (javax.management.ObjectName)</li>
+ * <li>any full qualified Class name which the Scheduler will be set a "null"
value
+ * for it</li>
+ * </ul>
+ * <br>
+ * 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 ).
+ *
+ * @param 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
+ **/
+ public void setSchedulableMBeanMethod( String pSchedulableMBeanMethod )
+ throws InvalidParameterException;
+
+ /**
+ * @return True if the Scheduler uses a Schedulable MBean, false if it uses a
+ * Schedulable class
+ **/
+ public boolean isUsingMBean();
+
+ /**
* @return Schedule Period between two scheduled calls in Milliseconds. It will
always
* be bigger than 0 except it returns -1 then the schedule is stopped.
**/
@@ -197,6 +270,11 @@
* @return True if any attributes are changed but the Schedule is not restarted
yet.
**/
public boolean isRestartPending();
+
+ /**
+ * @return True if the Schedule when the Scheduler is started
+ **/
+ public boolean isStartAtStartup();
/**
* Set the scheduler to start when MBean started or not. Note that this method
only
1.1 jboss/src/main/org/jboss/util/SchedulableExample.java
Index: SchedulableExample.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.util;
import java.security.InvalidParameterException;
import java.util.Date;
import javax.management.MalformedObjectNameException;
import javax.management.MBeanServer;
import javax.management.Notification;
import javax.management.timer.TimerNotification;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import org.jboss.logging.Logger;
import org.jboss.system.ServiceMBeanSupport;
/**
* Scheduler Instance to allow clients to run this as a scheduling service for
* any Schedulable instances.
* <br>
* 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:<br>
* jboss:service=Scheduler,schedule=<you schedule name><br>
* This way you should not run into a name conflict.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>
* @author Cameron (camtabor)
*
* <p><b>Revisions:</b></p>
* <p><b>20010814 Cameron:</b>
* <ul>
* <li>Checks if the TimerMBean is already loaded</li>
* <li>Created a SchedulerNotificationFilter so that each Scheduler only
* get its notifications</li>
* <li>Stop was broken because removeNotification( Integer ) was broken</li>
* </ul>
* </p>
* <p><b>20011026 Andy:</b>
* <ul>
* <li>Move the SchedulerNotificationFilter to become an internal class
* and renamed to NotificationFilter</li>
* <li>MBean is not bind/unbind to JNDI server anymore</li>
* </ul>
* </p>
* <p><b>20020117 Andy:</b>
* <ul>
* <li>Change the behaviour when the Start Date is in the past. Now the
* Scheduler will behave as the Schedule is never stopped and find
* the next available time to start with respect to the settings.
* Therefore you can restart JBoss without adjust your Schedule
* every time. BUT you will still loose the calls during the Schedule
* was donw.</li>
* <li>Added parsing capabilities to setInitialStartDate. Now NOW: current time,
* and a string in a format the SimpleDataFormat understand in your environment
* (US: m/d/yy h:m a) but of course the time in ms since 1/1/1970.</li>
* <li>Some fixes like the stopping a Schedule even if it already stopped etc.</li>
* </ul>
* </p>
**/
public class SchedulableExample
extends ServiceMBeanSupport
implements SchedulableExampleMBean
{
// -------------------------------------------------------------------------
// Constants
// -------------------------------------------------------------------------
/** Class logger. */
private static final Logger log = Logger.getLogger( SchedulableExample.class );
// -------------------------------------------------------------------------
// Members
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
/**
* Default (no-args) Constructor
**/
public SchedulableExample()
{
}
// -------------------------------------------------------------------------
// SchedulableExampleMBean Methods
// -------------------------------------------------------------------------
public void hit( Notification lNotification, Date lDate, long lRepetitions,
ObjectName lName, String lTest ) {
log.info( "got hit"
+ ", notification: " + lNotification
+ ", date: " + lDate
+ ", remaining repetitions: " + lRepetitions
+ ", scheduler name: " + lName
+ ", test string: " + lTest
);
}
// -------------------------------------------------------------------------
// Methods
// -------------------------------------------------------------------------
public ObjectName getObjectName(
MBeanServer pServer,
ObjectName pName
)
throws MalformedObjectNameException
{
return new ObjectName( OBJECT_NAME );
}
public String getName() {
return "JBoss Schedulable Example MBean";
}
}
1.1 jboss/src/main/org/jboss/util/SchedulableExampleMBean.java
Index: SchedulableExampleMBean.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.util;
import java.util.Date;
import javax.management.Notification;
import javax.management.ObjectName;
import org.jboss.system.ServiceMBean;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>
**/
public interface SchedulableExampleMBean
extends ServiceMBean
{
// -------------------------------------------------------------------------
// Constants
// -------------------------------------------------------------------------
public static final String OBJECT_NAME = "jboss:type=example,name=schedulable";
// -------------------------------------------------------------------------
// Methods
// -------------------------------------------------------------------------
public void hit( Notification lNotification, Date lDate, long lRepetitions,
ObjectName lName, String lTest );
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development