[jboss-cvs] contrib/varia/src/main/org/jboss/varia/scheduler ...

Dimitris Andreadis dimitris.andreadis at jboss.com
Thu Jul 13 15:53:58 EDT 2006


  User: dimitris
  Date: 06/07/13 15:53:58

  Modified:    varia/src/main/org/jboss/varia/scheduler    
                        ScheduleManager.java ScheduleManagerMBean.java
                        Scheduler.java SchedulerMBean.java
  Log:
  JBAS-3282, add FixedRate attribute.
   The default JMX Timer scheduling behaviour of FixedDelay execution
   (as of JDK5 or JBoss v4.0.5) is overriden in the config using FixedRate true
  
  Revision  Changes    Path
  1.17      +46 -20    contrib/varia/src/main/org/jboss/varia/scheduler/ScheduleManager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ScheduleManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/varia/src/main/org/jboss/varia/scheduler/ScheduleManager.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -b -r1.16 -r1.17
  --- ScheduleManager.java	20 Feb 2006 21:50:28 -0000	1.16
  +++ ScheduleManager.java	13 Jul 2006 19:53:58 -0000	1.17
  @@ -47,7 +47,8 @@
    * ready.
    *
    * @author <a href="mailto:andreas at jboss.org">Andreas Schaefer</a>
  - * @version $Revision: 1.16 $
  + * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
  + * @version $Revision: 1.17 $
    */
   public class ScheduleManager extends ServiceMBeanSupport
      implements ScheduleManagerMBean
  @@ -78,9 +79,9 @@
      private String mTimerName = DEFAULT_TIMER_NAME;
      private ObjectName mTimer;
   
  -   private boolean mScheduleIsStarted = false;
      private boolean mWaitForNextCallToStop = false;
      private boolean mStartOnStart = false;
  +   private boolean mFixedRate = false;
      private boolean mIsPaused = false;
   
      /**
  @@ -88,6 +89,7 @@
       * Schedule is stop / started or destroyed
       */
      private ArrayList mProviders = new ArrayList();
  +   
      /** List of added Schedules */
      private Hashtable mSchedules = new Hashtable();
   
  @@ -131,7 +133,6 @@
               }
            }
         }
  -      mScheduleIsStarted = true;
      }
   
      /**
  @@ -163,7 +164,6 @@
               }
            }
         }
  -      mScheduleIsStarted = false;
      }
   
      /**
  @@ -393,15 +393,9 @@
         return getState() == STARTED;
      }
   
  -   /**
  -    * @jmx:managed-attribute
  -    *
  -    * @return true if the scheduler should be started upon MBean start or not
  -    */
  -   public boolean isStartAtStartup()
  -   {
  -      return mStartOnStart;
  -   }
  +   // -------------------------------------------------------------------------
  +   // SchedulerManagerMBean Attributes
  +   // -------------------------------------------------------------------------
   
      /**
       * Set the scheduler to start when MBean started or not. Note that this method only
  @@ -420,11 +414,11 @@
      /**
       * @jmx:managed-attribute
       *
  -    * @return Name of the Timer MBean used in here
  +    * @return true if the scheduler should be started upon MBean start or not
       */
  -   public String getTimerName()
  +   public boolean isStartAtStartup()
      {
  -      return mTimerName;
  +      return mStartOnStart;
      }
   
      /**
  @@ -439,6 +433,36 @@
         mTimerName = pTimerName;
      }
   
  +   /**
  +    * @jmx:managed-attribute
  +    *
  +    * @return Name of the Timer MBean used in here
  +    */
  +   public String getTimerName()
  +   {
  +      return mTimerName;
  +   }
  +
  +   /**
  +    * @jmx:managed-attribute
  +    * 
  +    * @param fixedRate the default scheduling to use, fixed-rate or fixed-delay (false, default)
  +    */
  +   public void setFixedRate(boolean fixedRate)
  +   {
  +      mFixedRate = fixedRate;
  +   }
  +   
  +   /**
  +    * @jmx:managed-attribute
  +    * 
  +    * @return the default scheduling to use
  +    */   
  +   public boolean getFixedRate()
  +   {
  +      return mFixedRate;
  +   }
  +   
      // -------------------------------------------------------------------------
      // ServiceMBeanSupport overrides
      // -------------------------------------------------------------------------
  @@ -650,7 +674,7 @@
      }
   
      /**
  -    * Represents a single Schedule which can be started and stop
  +    * Represents a single Schedule which can be started and stopped
       * if necessary.
       */
      private class ScheduleInstance
  @@ -790,7 +814,8 @@
                       new Integer(getID()), // User Object
                       lStartDate,
                       new Long(mPeriod),
  -                    mRemainingRepetitions < 0 ? new Long(0) : new Long(mRemainingRepetitions)
  +                    mRemainingRepetitions < 0 ? new Long(0) : new Long(mRemainingRepetitions),
  +                    new Boolean(mFixedRate)
                    },
                    new String[]{
                       String.class.getName(),
  @@ -798,7 +823,8 @@
                       Object.class.getName(),
                       Date.class.getName(),
                       Long.TYPE.getName(),
  -                    Long.TYPE.getName()
  +                    Long.TYPE.getName(),
  +                    Boolean.TYPE.getName()
                    }
            )).intValue();
            // Register the notification listener at the MBeanServer
  
  
  
  1.4       +5 -1      contrib/varia/src/main/org/jboss/varia/scheduler/ScheduleManagerMBean.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ScheduleManagerMBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/varia/src/main/org/jboss/varia/scheduler/ScheduleManagerMBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- ScheduleManagerMBean.java	20 Feb 2006 18:29:17 -0000	1.3
  +++ ScheduleManagerMBean.java	13 Jul 2006 19:53:58 -0000	1.4
  @@ -33,7 +33,7 @@
    * 
    * @author <a href="mailto:andreas at jboss.org">Andreas Schaefer</a>
    * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public interface ScheduleManagerMBean extends ServiceMBean
   {
  @@ -50,6 +50,10 @@
      void setTimerName(String timerObjectName);
      String getTimerName();
      
  +   /** The default scheduling to use, fixed-rate or fixed-delay (false, default) */
  +   void setFixedRate(boolean fixedRate);
  +   boolean getFixedRate();
  +   
      // Operations ----------------------------------------------------
      
      /**
  
  
  
  1.16      +123 -100  contrib/varia/src/main/org/jboss/varia/scheduler/Scheduler.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Scheduler.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/varia/src/main/org/jboss/varia/scheduler/Scheduler.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -b -r1.15 -r1.16
  --- Scheduler.java	30 Oct 2005 00:07:27 -0000	1.15
  +++ Scheduler.java	13 Jul 2006 19:53:58 -0000	1.16
  @@ -1,43 +1,42 @@
   /*
  -* JBoss, Home of Professional Open Source
  -* Copyright 2005, JBoss Inc., and individual contributors as indicated
  -* by the @authors tag. See the copyright.txt in the distribution for a
  -* full listing of individual contributors.
  -*
  -* This is free software; you can redistribute it and/or modify it
  -* under the terms of the GNU Lesser General Public License as
  -* published by the Free Software Foundation; either version 2.1 of
  -* the License, or (at your option) any later version.
  -*
  -* This software is distributed in the hope that it will be useful,
  -* but WITHOUT ANY WARRANTY; without even the implied warranty of
  -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  -* Lesser General Public License for more details.
  -*
  -* You should have received a copy of the GNU Lesser General Public
  -* License along with this software; if not, write to the Free
  -* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  -* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  -*/
  + * JBoss, Home of Professional Open Source
  + * Copyright 2005, JBoss Inc., and individual contributors as indicated
  + * by the @authors tag. See the copyright.txt in the distribution for a
  + * full listing of individual contributors.
  + *
  + * This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  + */
   package org.jboss.varia.scheduler;
   
   import java.lang.reflect.Constructor;
  -import java.text.SimpleDateFormat;
   import java.security.InvalidParameterException;
  +import java.text.SimpleDateFormat;
   import java.util.Date;
   import java.util.StringTokenizer;
   import java.util.Vector;
   
   import javax.management.MalformedObjectNameException;
  -import javax.management.MBeanServer;
   import javax.management.Notification;
  -import javax.management.timer.TimerNotification;
   import javax.management.NotificationListener;
   import javax.management.ObjectName;
  +import javax.management.timer.TimerNotification;
   
   import org.jboss.logging.Logger;
  +import org.jboss.mx.loading.ClassLoaderUtils;
   import org.jboss.system.ServiceMBeanSupport;
  -import org.jboss.util.Classes;
   
   /**
    * Scheduler Instance to allow clients to run this as a scheduling service for
  @@ -49,15 +48,11 @@
    * :service=Scheduler,schedule=<you schedule name><br>
    * This way you should not run into a name conflict.
    *
  - * @jmx.mbean name="jboss:service=Scheduler"
  - *            extends="org.jboss.system.ServiceMBean"
  - *
    * @author <a href="mailto:andreas at jboss.org">Andreas Schaefer</a>
    * @author Cameron (camtabor)
  - * @version $Revision: 1.15 $
  + * @version $Revision: 1.16 $
    */
  -public class Scheduler
  -   extends ServiceMBeanSupport
  +public class Scheduler extends ServiceMBeanSupport
      implements SchedulerMBean
   {
   
  @@ -86,7 +81,6 @@
      private String mTimerName = DEFAULT_TIMER_NAME;
      private ObjectName mTimer;
      private Schedulable mSchedulable;
  -//as   private Object mSchedulableMBeanObjectName;
   
      private boolean mScheduleIsStarted = false;
      private boolean mWaitForNextCallToStop = false;
  @@ -114,6 +108,7 @@
      private boolean mStartDateIsNow;
      private long mSchedulePeriod;
      private long mInitialRepetitions;
  +   private boolean mFixedRate = false;
   
      private NotificationListener listener;
   
  @@ -129,8 +124,14 @@
      }
   
      /**
  -    * Constructor with the necessary attributes to be set
  -    **/
  +    * 
  +    * @param pSchedulableClass
  +    * @param pInitArguments
  +    * @param pInitTypes
  +    * @param pInitialStartDate
  +    * @param pSchedulePeriod
  +    * @param pNumberOfRepetitions
  +    */ 
      public Scheduler(String pSchedulableClass,
         String pInitArguments,
         String pInitTypes,
  @@ -149,8 +150,15 @@
      }
   
      /**
  -    * Constructor with the necessary attributes to be set
  -    **/
  +    * 
  +    * @param pSchedulableClass
  +    * @param pInitArguments
  +    * @param pInitTypes
  +    * @param pDateFormat
  +    * @param pInitialStartDate
  +    * @param pSchedulePeriod
  +    * @param pNumberOfRepetitions
  +    */ 
      public Scheduler(
         String pSchedulableClass,
         String pInitArguments,
  @@ -180,7 +188,7 @@
       * The Schedule is immediately set to started even the first call is in the
       * future.
       *
  -    * @jmx.managed-operation
  +    * @jmx:managed-operation
       *
       * @throws InvalidParameterException If any of the necessary values are not set
       *                                   or invalid (especially for the Schedulable
  @@ -357,9 +365,8 @@
                     null, // User Object
                     lStartDate,
                     new Long(mActualSchedulePeriod),
  -                  mRemainingRepetitions < 0 ?
  -               new Long(0) :
  -               new Long(mRemainingRepetitions)
  +                  mRemainingRepetitions < 0 ? new Long(0) : new Long(mRemainingRepetitions),
  +                  new Boolean(mFixedRate)
                  },
                  new String[]{
                     String.class.getName(),
  @@ -367,7 +374,8 @@
                     Object.class.getName(),
                     Date.class.getName(),
                     Long.TYPE.getName(),
  -                  Long.TYPE.getName()
  +                  Long.TYPE.getName(),
  +                  Boolean.TYPE.getName()
                  }
               )).intValue();
               if (mUseMBean)
  @@ -400,7 +408,7 @@
       * Stops the schedule because it is either not used anymore or to restart it with
       * new values.
       *
  -    * @jmx.managed-operation
  +    * @jmx:managed-operation
       *
       * @param pDoItNow If true the schedule will be stopped without waiting for the next
       *                 scheduled call otherwise the next call will be performed before
  @@ -457,7 +465,7 @@
      /**
       * Stops the server right now and starts it right now.
       *
  -    * @jmx.managed-operation
  +    * @jmx:managed-operation
       */
      public void restartSchedule()
      {
  @@ -466,7 +474,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return Full qualified Class name of the schedulable class called by the schedule or
       *         null if not set.
  @@ -485,7 +493,7 @@
       * Scheduler. Must be set before the Schedule is started. Please also set the
       * {@link #setSchedulableArguments} and {@link #setSchedulableArgumentTypes}.
       *
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @param pSchedulableClass Fully Qualified Schedulable Class.
       *
  @@ -505,32 +513,15 @@
            // Try to load the Schedulable Class
            ClassLoader loader = TCLActions.getContextClassLoader();
            mSchedulableClass = loader.loadClass(pSchedulableClass);
  -
            // Check if instance of Schedulable
  -         boolean lFound = false;
  -         Class checkedClass = mSchedulableClass;
  -         while (lFound == false && checkedClass != null)
  -         {
  -            Class[] lInterfaces = checkedClass.getInterfaces();
  -            for (int i = 0; i < lInterfaces.length; i++)
  -            {
  -               if (lInterfaces[i] == Schedulable.class)
  -               {
  -                  lFound = true;
  -                  break;
  -               }
  -            }
  -            checkedClass = checkedClass.getSuperclass();
  -         }
  -
  -         if (!lFound)
  +         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);
  +            ClassLoaderUtils.displayClassInfo(mSchedulableClass, info);
               info.append("\nSchedulable.class info:");
  -            Classes.displayClassInfo(Schedulable.class, info);
  +            ClassLoaderUtils.displayClassInfo(Schedulable.class, info);
               log.debug(info.toString());
               throw new InvalidParameterException(msg);
            }
  @@ -547,7 +538,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return Comma seperated list of Constructor Arguments used to instantiate the
       *         Schedulable class instance. Right now only basic data types, String and
  @@ -559,7 +550,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * Sets the comma seperated list of arguments for the Schedulable class. Note that
       * this list must have as many elements as the Schedulable Argument Type list otherwise
  @@ -598,7 +589,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return A comma seperated list of Argument Types which should match the list of
       *         arguments.
  @@ -615,7 +606,7 @@
       * 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.
       *
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @param pTypeList List of arguments used to create the Schedulable intance. If
       *                  the list is null or empty then the no-args constructor is used.
  @@ -694,7 +685,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return Object Name if a Schedulalbe MBean is set
       */
  @@ -716,7 +707,7 @@
       * MBean is available. If the MBean is not available it will not be called but
       * the remaining repetitions will be decreased.
       *
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @param pSchedulableMBean JMX MBean Object Name which should be called.
       *
  @@ -772,7 +763,7 @@
       * have the following signature: doSomething( javax.management.Notification, long,
       * java.lang.String ).
       *
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @param pSchedulableMBeanMethod Name of the method to be called optional followed
       *                                by method arguments (see above).
  @@ -867,7 +858,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return True if the Scheduler uses a Schedulable MBean, false if it uses a
       *         Schedulable class
  @@ -878,7 +869,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @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.
  @@ -891,7 +882,7 @@
      /**
       * Sets the Schedule Period between two scheduled call.
       *
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @param pPeriod Time between to scheduled calls (after the initial call) in Milliseconds.
       *                This value must be bigger than 0.
  @@ -909,7 +900,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return the date format
       */
  @@ -923,7 +914,7 @@
      /**
       * Sets the date format used to parse date/times
       *
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @param dateFormat The date format when empty or null the locale is used to parse dates
       */
  @@ -936,7 +927,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return Date (and time) of the first scheduled. For value see {@link #setInitialStartDate}
       *         method.
  @@ -950,7 +941,7 @@
       * Sets the first scheduled call. If the date is in the past the scheduler tries to find the
       * next available start date.
       *
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @param pStartDate Date when the initial call is scheduled. It can be either:
       *                   <ul>
  @@ -1016,7 +1007,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return Number of scheduled calls initially. If -1 then there is not limit.
       */
  @@ -1028,7 +1019,7 @@
      /**
       * Sets the initial number of scheduled calls.
       *
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @param pNumberOfCalls Initial Number of scheduled calls. If -1 then the number
       *                       is unlimted.
  @@ -1046,7 +1037,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return Number of remaining repetitions. If -1 then there is no limit.
       */
  @@ -1056,7 +1047,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return True if the schedule is up and running. If you want to start the schedule
       *         with another values by using {@ #startSchedule} you have to stop the schedule
  @@ -1068,7 +1059,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return True if any attributes are changed but the Schedule is not restarted yet.
       */
  @@ -1078,7 +1069,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return True if the Schedule when the Scheduler is started
       */
  @@ -1092,7 +1083,7 @@
       * affects when the {@link #startService startService()} gets called (normally at
       * startup time.
       *
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @param pStartAtStartup True if Schedule has to be started at startup time
       */
  @@ -1102,7 +1093,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return True if this Scheduler is active and will send notifications in the future
       */
  @@ -1112,7 +1103,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @return Name of the Timer MBean used in here
       */
  @@ -1122,7 +1113,7 @@
      }
   
      /**
  -    * @jmx.managed-attribute
  +    * @jmx:managed-attribute
       *
       * @param pTimerName Object Name of the Timer MBean to
       *                   be used. If null or not a valid ObjectName
  @@ -1133,20 +1124,31 @@
         mTimerName = pTimerName;
      }
   
  -   // -------------------------------------------------------------------------
  -   // Methods
  -   // -------------------------------------------------------------------------
  +   /**
  +    * @jmx:managed-attribute
  +    * 
  +    * @param fixedRate the default scheduling to use, fixed-rate or fixed-delay (false, default)
  +    */
  +   public void setFixedRate(boolean fixedRate)
  +   {
  +      mFixedRate = fixedRate;
  +   }
   
  -   public ObjectName getObjectName(
  -      MBeanServer pServer,
  -      ObjectName pName
  -      )
  -      throws MalformedObjectNameException
  +   /**
  +    * @jmx:managed-attribute
  +    * 
  +    * @return the default scheduling to use
  +    */   
  +   public boolean getFixedRate()
      {
  -      return pName == null ? OBJECT_NAME : pName;
  +      return mFixedRate;
      }
   
      // -------------------------------------------------------------------------
  +   // Methods
  +   // -------------------------------------------------------------------------
  +
  +   // -------------------------------------------------------------------------
      // ServiceMBean - Methods
      // -------------------------------------------------------------------------
   
  @@ -1192,6 +1194,26 @@
         stopSchedule(true);
      }
   
  +   private static boolean isSchedulable(Class c)
  +   {
  +      boolean lFound = false;
  +      do
  +      {
  +         Class[] lInterfaces = c.getInterfaces();
  +         for (int i = 0; i < lInterfaces.length; i++)
  +         {
  +            if (lInterfaces[i] == Schedulable.class)
  +            {
  +               lFound = true;
  +               break;
  +            }
  +         }
  +         c = c.getSuperclass();
  +      } 
  +      while (c != null && !lFound);
  +      return lFound;
  +   }
  +
      // -------------------------------------------------------------------------
      // Inner Classes
      // -------------------------------------------------------------------------
  @@ -1380,10 +1402,11 @@
   
         /**
          * Create a Filter.
  +       * @param id the Scheduler id
          */
  -      public NotificationFilter(Integer pId)
  +      public NotificationFilter(Integer id)
         {
  -         mId = pId;
  +         mId = id;
         }
   
         /**
  
  
  
  1.5       +157 -119  contrib/varia/src/main/org/jboss/varia/scheduler/SchedulerMBean.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SchedulerMBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/varia/src/main/org/jboss/varia/scheduler/SchedulerMBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- SchedulerMBean.java	30 Oct 2005 00:07:27 -0000	1.4
  +++ SchedulerMBean.java	13 Jul 2006 19:53:58 -0000	1.5
  @@ -1,132 +1,170 @@
   /*
  -* JBoss, Home of Professional Open Source
  -* Copyright 2005, JBoss Inc., and individual contributors as indicated
  -* by the @authors tag. See the copyright.txt in the distribution for a
  -* full listing of individual contributors.
  -*
  -* This is free software; you can redistribute it and/or modify it
  -* under the terms of the GNU Lesser General Public License as
  -* published by the Free Software Foundation; either version 2.1 of
  -* the License, or (at your option) any later version.
  -*
  -* This software is distributed in the hope that it will be useful,
  -* but WITHOUT ANY WARRANTY; without even the implied warranty of
  -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  -* Lesser General Public License for more details.
  -*
  -* You should have received a copy of the GNU Lesser General Public
  -* License along with this software; if not, write to the Free
  -* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  -* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  -*/
  -package org.jboss.varia.scheduler;
  -
  -/**
  - * MBean interface.
  + * JBoss, Home of Professional Open Source
  + * Copyright 2005, JBoss Inc., and individual contributors as indicated
  + * by the @authors tag. See the copyright.txt in the distribution for a
  + * full listing of individual contributors.
  + *
  + * This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    */
  -public interface SchedulerMBean extends org.jboss.system.ServiceMBean {
  +package org.jboss.varia.scheduler;
   
  -   //default object name
  -   public static final javax.management.ObjectName OBJECT_NAME = org.jboss.mx.util.ObjectNameFactory.create("jboss:service=Scheduler");
  +import java.security.InvalidParameterException;
   
  -   /**
  -    * 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.
  -    * @throws InvalidParameterException If any of the necessary values are not set or invalid (especially for the Schedulable class attributes).    */
  -  void startSchedule() ;
  +import javax.management.ObjectName;
   
  -   /**
  -    * Stops the schedule because it is either not used anymore or to restart it with new values.
  -    * @param 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.    */
  -  void stopSchedule(boolean pDoItNow) ;
  +import org.jboss.mx.util.ObjectNameFactory;
  +import org.jboss.system.ServiceMBean;
   
  -   /**
  -    * Stops the server right now and starts it right now.
  +/**
  + * ScheduleMBean interface.
  + * 
  + * @author <a href="mailto:andreas at jboss.org">Andreas Schaefer</a>
  + * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
  + * @version $Revision: 1.5 $
       */
  -  void restartSchedule() ;
  -
  -  java.lang.String getSchedulableClass() ;
  -
  -   /**
  -    * 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 {@link #setSchedulableArguments} and {@link #setSchedulableArgumentTypes}.
  -    * @param 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.    */
  -  void setSchedulableClass(java.lang.String pSchedulableClass) throws java.security.InvalidParameterException;
  -
  -  java.lang.String getSchedulableArguments() ;
  -
  -  void setSchedulableArguments(java.lang.String pArgumentList) ;
  -
  -  java.lang.String getSchedulableArgumentTypes() ;
  -
  -   /**
  -    * 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.
  -    * @param 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.    */
  -  void setSchedulableArgumentTypes(java.lang.String pTypeList) throws java.security.InvalidParameterException;
  -
  -  java.lang.String getSchedulableMBean() ;
  +public interface SchedulerMBean extends ServiceMBean
  +{
  +   /** The default ObjectName */
  +   ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss:service=Scheduler");
  +
  +   // Attributes ----------------------------------------------------
  +
  +   /** 
  +    * The first scheduled call
  +    * 
  +    * - 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 repetitions 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).
  +    */
  +   void setInitialStartDate(String startDate);
  +   String getInitialStartDate();
   
  -   /**
  -    * 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.    */
  -  void setSchedulableMBean(java.lang.String pSchedulableMBean) throws java.security.InvalidParameterException;
  +   /** The date format used to parse date/times - when empty or null the locale is used to parse dates */
  +   void setDateFormat(String dateFormat);
  +   String getDateFormat();
  +   
  +   /** The Schedule Period between two scheduled call (in msecs) */
  +   void setSchedulePeriod(long period);
  +   long getSchedulePeriod();
  +   
  +   /** The number of scheduled calls */
  +   void setInitialRepetitions(long numberOfCalls);
  +   long getInitialRepetitions();
  +   
  +   /** The fully qualified Class name of the Schedulable Class being called by the Scheduler. */
  +   void setSchedulableClass(String schedulableClass) throws java.security.InvalidParameterException;
  +   String getSchedulableClass(); 
  +   
  +   /** The arguments to pass to the schedule */
  +   void setSchedulableArguments(String argumentList);
  +   String getSchedulableArguments();   
  +   
  +   /**
  +    * 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.
  +    * 
  +    * If the list is null or empty then the no-args constructor is used.
  +    */
  +   void setSchedulableArgumentTypes(String typeList) throws java.security.InvalidParameterException;
  +   String getSchedulableArgumentTypes();
   
  -   /**
  -    * 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 sign!
 ature: 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    */
  -  void setSchedulableMBeanMethod(java.lang.String pSchedulableMBeanMethod) throws java.security.InvalidParameterException;
  +   /** The fully qualified JMX MBean name of the Schedulable MBean to be called.
  +    * Attention: if set the 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. */
  +   void setSchedulableMBean(String schedulableMBean) throws java.security.InvalidParameterException;
  +   String getSchedulableMBean();
  +   
  +   /**
  +    * 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, 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, String ).
  +    */
  +   void setSchedulableMBeanMethod(String schedulableMBeanMethod) throws java.security.InvalidParameterException;
  +   String getSchedulableMBeanMethod();
   
  -  boolean isUsingMBean() ;
  +   /** The default scheduling to use, fixed-rate or fixed-delay (false, default) */
  +   void setFixedRate(boolean fixedRate);
  +   boolean getFixedRate();
   
  -  long getSchedulePeriod() ;
  +   /** Start the scheduler when the MBean started or not. */
  +   void setStartAtStartup(boolean startAtStartup);
  +   boolean isStartAtStartup();
   
  -   /**
  -    * Sets the Schedule Period between two scheduled call.
  -    * @param 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    */
  -  void setSchedulePeriod(long pPeriod) ;
  +   /** The JMX Timer to use (or create if not there) */
  +   void setTimerName(String timerName);    
  +   String getTimerName();
   
  -  java.lang.String getDateFormat() ;
  +   // Informative Attributes ----------------------------------------
   
  -   /**
  -    * Sets the date format used to parse date/times
  -    * @param dateFormat The date format when empty or null the locale is used to parse dates    */
  -  void setDateFormat(java.lang.String dateFormat) ;
  +   long getRemainingRepetitions();   
  +   boolean isActive();   
  +   boolean isStarted();
  +   boolean isRestartPending();
  +   boolean isUsingMBean();
   
  -  java.lang.String getInitialStartDate() ;
  +   // Operations ----------------------------------------------------
   
      /**
  -    * Sets the first scheduled call. If the date is in the past the scheduler tries to find the next available start date.
  -    * @param pStartDate Date when the initial call is scheduled. It can be either: <ul> <li> NOW: date will be the current date (new Date()) plus 1 seconds </li><li> Date as String able to be parsed by SimpleDateFormat with default format </li><li> Date as String parsed using the date format attribute </li><li> Milliseconds since 1/1/1970 </li> </ul> 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.<br> 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).    */
  -  void setInitialStartDate(java.lang.String pStartDate) ;
  -
  -  long getInitialRepetitions() ;
  +    * 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.
  +    * @throws InvalidParameterException If any of the necessary values are not set or invalid
  +    * (especially for the Schedulable class attributes).
  +    */
  +   void startSchedule();
   
      /**
  -    * Sets the initial number of scheduled calls.
  -    * @param 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    */
  -  void setInitialRepetitions(long pNumberOfCalls) ;
  -
  -  long getRemainingRepetitions() ;
  -
  -  boolean isStarted() ;
  -
  -  boolean isRestartPending() ;
  -
  -  boolean isStartAtStartup() ;
  +    * Stops the schedule because it is either not used anymore or to restart it with new values.
  +    * @param doItNow 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.
  +    */
  +   void stopSchedule(boolean doItNow);
   
      /**
  -    * Set the scheduler to start when MBean started or not. Note that this method only affects when the {@link #startService startService()} gets called (normally at startup time.
  -    * @param pStartAtStartup True if Schedule has to be started at startup time    */
  -  void setStartAtStartup(boolean pStartAtStartup) ;
  -
  -  boolean isActive() ;
  -
  -  java.lang.String getTimerName() ;
  -
  -  void setTimerName(java.lang.String pTimerName) ;
  -
  +    * Stops the server right now and starts it right now.
  +    */
  +   void restartSchedule();
   }
  
  
  



More information about the jboss-cvs-commits mailing list