[JBoss-dev] CVS update: jboss/src/main/org/jboss/util Scheduler.java SchedulerMBean.java

2002-01-19 Thread Andreas Schaefer

  User: schaefera
  Date: 02/01/19 10:43:30

  Modified:src/main/org/jboss/util Scheduler.java SchedulerMBean.java
  Log:
  Added isActive() flag, NOW will be reset to the current date when Schedule is 
(re)started, fixed some bugs.
  
  Revision  ChangesPath
  1.17  +71 -31jboss/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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Scheduler.java2002/01/18 18:48:12 1.16
  +++ Scheduler.java2002/01/19 18:43:30 1.17
  @@ -73,13 +73,34 @@
   * 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.
  +* was down.
   * 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.
   * Some fixes like the stopping a Schedule even if it already stopped etc.
   * 
   * 
  +* 20020118 Andy:
  +* 
  +* Added the ability to call another MBean instead of an instance of the
  +* given Schedulable class. Use setSchedulableMBean() to specify the JMX
  +* Object Name pointing to the given MBean. Then if the MBean does not
  +* contain the same method as the Schedulable instance you have to specify
  +* the method with setSchedulableMBeanMethod(). There you can use some
  +* constants.
  +* 
  +* 20020119 Andy:
  +* 
  +* Added a helper method isActive()
  +* Fixed a bug not indicating that no MBean is used when setSchedulableClass()
  +* is called.
  +* Fixed a bug therefore that when NOW is set as initial start date a restart
  +* of the Schedule will reset the start date to the current date
  +* Fixed a bug because the start date was update during recalculation of the
  +* start date when the original start date is in the past (see above). With this
  +* you could restart the schedule even after all hits were fired when the
  +* schedule was not started immediately after the initial start date was 
set.
  +* 
   **/
   public class Scheduler
  extends ServiceMBeanSupport
  @@ -136,6 +157,7 @@
  private DateFormat mDateFormatter;
  private Date mStartDate;
  private String mStartDateString;
  +   private boolean mStartDateIsNow;
  private long mSchedulePeriod;
  private long mInitialRepetitions;
  
  @@ -269,28 +291,35 @@
   
   mRemainingRepetitions = mInitialRepetitions;
   mActualSchedulePeriod = mSchedulePeriod;
  +Date lStartDate = null;
   // Register the Schedule at the Timer
  -// Check if initial start date is in the past
  -if( mStartDate.getTime() < new Date().getTime() ) {
  -   // If then first check if a repetition is in the future
  -   long lNow = new Date().getTime() + 100;
  -   long lSkipRepeats = ( ( lNow - mStartDate.getTime() ) / 
mActualSchedulePeriod ) + 1;
  -   if( mRemainingRepetitions > 0 ) {
  -  // If not infinit loop
  -  if( lSkipRepeats >= mRemainingRepetitions ) {
  - // No repetition left -> exit
  - log.info( "No repetitions left because start date is in the 
past and could " +
  -"not be reached by Initial Repetitions * Schedule Period" );
  - return;
  -  } else {
  - // Reduce the missed hits
  - mRemainingRepetitions -= lSkipRepeats;
  +// If start date is NOW then take the current date
  +if( mStartDateIsNow ) {
  +   mStartDate = new Date( new Date().getTime() + 1000 );
  +   lStartDate = mStartDate;
  +} else {
  +   // Check if initial start date is in the past
  +   if( mStartDate.getTime() < new Date().getTime() ) {
  +  // If then first check if a repetition is in the future
  +  long lNow = new Date().getTime() + 100;
  +  long lSkipRepeats = ( ( lNow - mStartDate.getTime() ) / 
mActualSchedulePeriod ) + 1;
  +  log.debug( "Old start date: " + mStartDate + ", now: " + new 
Date( lNow ) + ", Skip repeats: " + lSkipRepeats );
  +  if( mRemainingRepetitions > 0 ) {
  + // If not infinit loop
  + if( lSkipRepeats >= mRemainingRepetitions ) {
  +// No repetition left -> exit
  +log.info( "No repetitions left because start date is in the 
past and could " +
  + 

[JBoss-dev] CVS update: jboss/src/main/org/jboss/util Scheduler.java SchedulerMBean.java

2002-01-17 Thread Andreas Schaefer

  User: schaefera
  Date: 02/01/17 13:57:27

  Modified:src/main/org/jboss/util Scheduler.java SchedulerMBean.java
  Log:
  Ajusted JSR-77 to the new JBoss JMX naming and the Scheduler now can be restarted 
and will keep the schedule and allows an easier date input for Initial Start Date
  
  Revision  ChangesPath
  1.15  +122 -134  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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Scheduler.java2002/01/09 21:49:11 1.14
  +++ Scheduler.java2002/01/17 21:57:27 1.15
  @@ -7,6 +7,8 @@
   package org.jboss.util;
   
   import java.lang.reflect.Constructor;
  +import java.text.DateFormat;
  +import java.text.SimpleDateFormat;
   import java.security.InvalidParameterException;
   import java.util.ArrayList;
   import java.util.Collection;
  @@ -31,7 +33,7 @@
   import javax.naming.NameNotFoundException;
   import javax.naming.Reference;
   import javax.naming.StringRefAddr;
  -
  +import org.jboss.logging.Logger;
   import org.jboss.naming.NonSerializableFactory;
   import org.jboss.system.ServiceMBeanSupport;
   
  @@ -64,6 +66,20 @@
   * MBean is not bind/unbind to JNDI server anymore
   * 
   * 
  +* 20020117 Andy:
  +* 
  +* 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.
  +* 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.
  +* Some fixes like the stopping a Schedule even if it already stopped etc.
  +* 
  +* 
   **/
   public class Scheduler
  extends ServiceMBeanSupport
  @@ -81,7 +97,8 @@
  // Members
  // -
   
  -   private String mName;
  +   /** Class logger. */
  +   private static final Logger log = Logger.getLogger( Scheduler.class );
   
  private long mActualSchedulePeriod;
  private long mRemainingRepetitions = 0;
  @@ -100,47 +117,36 @@
  private String[] mSchedulableArgumentList = new String[ 0 ];
  private String mSchedulableArgumentTypes;
  private Class[] mSchedulableArgumentTypeList = new Class[ 0 ];
  +   private DateFormat mDateFormatter;
  private Date mStartDate;
  +   private String mStartDateString;
  private long mSchedulePeriod;
  private long mInitialRepetitions;
   
  // -
  // Constructors
  // -
  -
  +   
  /**
   * Default (no-args) Constructor
   **/
  public Scheduler()
  {
  -  mName = null;
  -   }
  -
  -   /**
  -* Constructor with the necessary attributes to be set
  -*
  -* @param pName Name of the MBean
  -**/
  -   public Scheduler( String pName )
  -   {
  -  mName = pName;
  }
  -
  +   
  /**
   * Constructor with the necessary attributes to be set
   *
   * @param pName Name of the MBean
   **/
  public Scheduler(
  -  String pName,
 String pSchedulableClass,
 String pInitArguments,
 String pInitTypes,
  -  long pInitialStartDate,
  +  String pInitialStartDate,
 long pSchedulePeriod,
 long pNumberOfRepetitions
  ) {
  -  mName = pName;
 setStartAtStartup( true );
 setSchedulableClass( pSchedulableClass );
 setSchedulableArguments( pInitArguments );
  @@ -160,16 +166,19 @@
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( mSchedulePeriod <= 0 ) {
  +   log.debug( "Schedule Period is less than 0 (ms)" );
  throw new InvalidParameterException(
 "Schedule Period must

[JBoss-dev] CVS update: jboss/src/main/org/jboss/util Scheduler.java SchedulerMBean.java

2001-11-01 Thread Andreas Schaefer

  User: schaefera
  Date: 01/11/01 22:07:48

  Modified:src/main/org/jboss/util Scheduler.java SchedulerMBean.java
  Log:
  Fixed the bug 441291 therefore that a message selector can have leading
  and trailing spaces as well as line breaks and still does not break
  (leading and trailing spaces are remoed, line breaks as converted to
  a space and an empty string is converted to null meaning not restrictions).
  
  Scheduler does not register at the JNDI server as well as supports named
  attributes instead of only constructors arguments.
  
  Abstract Verifier checks not for RemoteException compliant with the
  RMI spec.
  
  Revision  ChangesPath
  1.11  +72 -112   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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Scheduler.java2001/09/11 18:35:04 1.10
  +++ Scheduler.java2001/11/02 06:07:48 1.11
  @@ -36,10 +36,16 @@
   import org.jboss.system.ServiceMBeanSupport;
   
   /**
  -* Scheduler Instance to allow clients to run this as a
  -* scheduling service for any Schedulable instances.
  +* 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:
  +* JBOSS-SYSTEM:service=Scheduler,schedule=
  +* This way you should not run into a name conflict.
   *
  -* @author mailto:[EMAIL PROTECTED]";>Andreas Schaefer
  +* @author mailto:[EMAIL PROTECTED]";>Andreas Schaefer
   * @author Cameron (camtabor)
   *
   * Revisions:
  @@ -51,6 +57,13 @@
   * Stop was broken because removeNotification( Integer ) was broken
   * 
   * 
  +* 20011026 Andy:
  +* 
  +* Move the SchedulerNotificationFilter to become an internal class
  +* and renamed to NotificationFilter
  +* MBean is not bind/unbind to JNDI server anymore
  +* 
  +* 
   **/
   public class Scheduler
  extends ServiceMBeanSupport
  @@ -128,11 +141,11 @@
 long pNumberOfRepetitions
  ) {
 mName = pName;
  -  mStartOnStart = true;
  +  setStartAtStartup( true );
 setSchedulableClass( pSchedulableClass );
 setSchedulableArguments( pInitArguments );
 setSchedulableArgumentTypes( pInitTypes );
  -  mStartDate = new Date( pInitialStartDate );
  +  setInitialStartDate( pInitialStartDate );
 setSchedulePeriod( pSchedulePeriod );
 setInitialRepetitions( pNumberOfRepetitions );
  }
  @@ -281,7 +294,7 @@
   getServer().addNotificationListener(
  mTimer,
  new Listener( mSchedulable ),
  -   new SchedulerNotificationFilter(new Integer(mActualSchedule)),
  +   new Scheduler.NotificationFilter( new Integer( mActualSchedule ) ),
  // No object handback necessary
  null
   );
  @@ -464,6 +477,14 @@
 mSchedulePeriod = pPeriod;
 mIsRestartPending = true;
  }
  +   
  +   public long getInitialStartDate() {
  +  return mStartDate.getTime();
  +   }
  +   
  +   public void setInitialStartDate( long pStartDate ) {
  +  mStartDate = new Date( ( pStartDate > 0 ? pStartDate : 0 ) );
  +   }
   
  public long getInitialRepetitions() {
 return mInitialRepetitions;
  @@ -488,6 +509,10 @@
  public boolean isRestartPending() {
 return mIsRestartPending;
  }
  +   
  +   public void setStartAtStartup( boolean pStartAtStartup ) {
  +  mStartOnStart = pStartAtStartup;
  +   }
   
  // -
  // Methods
  @@ -502,15 +527,6 @@
 return pName;
  }
   
  -   public String getJNDIName() {
  -  if( mName != null ) {
  - return JMX_NAME + ":" + mName;
  -  }
  -  else {
  - return JMX_NAME;
  -  }
  -   }
  -
  public String getName() {
 return "JBoss Scheduler MBean";
  }
  @@ -527,89 +543,36 @@
  protected void startService()
   throws Exception
  {
  -  bind( this );
 try {
// Create Timer MBean if need be
  -
  -   mTimer = new ObjectName( "DefaultDomain", "service", "Timer");
  -   if ( !getServer().isRegistered(mTimer)){
  - getServer().createMBean( "javax.management.timer.Timer", mTimer );
  - // Now start the Timer
  - getServer().invoke(
  -mTimer,
  -"start",
  -new Object[] {},
  -new String[] {}
  - );
  + 
  + mTimer = new ObjectName( "DefaultDomain", "service", "Timer");
  +