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  Changes    Path
  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.java    2001/09/11 18:35:04     1.10
  +++ Scheduler.java    2001/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.
  +* <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-SYSTEM: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 <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>
   * @author Cameron (camtabor)
   *
   * <p><b>Revisions:</b></p>
  @@ -51,6 +57,13 @@
   * <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>
   **/
   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");
  +         if( !getServer().isRegistered( mTimer ) ) {
  +            getServer().createMBean( "javax.management.timer.Timer", mTimer );
  +            // Now start the Timer
  +            getServer().invoke(
  +               mTimer,
  +               "start",
  +               new Object[] {},
  +               new String[] {}
  +            );
            }
         }
         catch( Exception e ) {
            e.printStackTrace();
         }
  +
         if( mStartOnStart ) {
            startSchedule();
         }
      }
   
      protected void stopService() {
  -      try {
  -         unbind();
  -      }
  -      catch( Exception e ) {
  -         log.error("Failed to unbind", e );
  -      }
  +      // Stop the schedule right now !!
  +      stopSchedule( true );
      }
   
      // -------------------------------------------------------------------------
  -   // Helper methods to bind/unbind the Management class
  -   // -------------------------------------------------------------------------
  -
  -    private void bind( Scheduler pScheduler )
  -      throws
  -         NamingException
  -   {
  -        Context lContext = new InitialContext();
  -        String lJNDIName = getJNDIName();
  -
  -        // Ah ! JBoss Server isn't serializable, so we use a helper class
  -        NonSerializableFactory.bind( lJNDIName, pScheduler );
  -
  -      //AS Don't ask me what I am doing here
  -        Name lName = lContext.getNameParser("").parse( lJNDIName );
  -        while( lName.size() > 1 ) {
  -            String lContextName = lName.get( 0 );
  -            try {
  -                lContext = (Context) lContext.lookup(lContextName);
  -            }
  -            catch( NameNotFoundException e )    {
  -                lContext = lContext.createSubcontext(lContextName);
  -            }
  -            lName = lName.getSuffix( 1 );
  -        }
  -
  -        // The helper class NonSerializableFactory uses address type nns, we go on 
to
  -        // use the helper class to bind the javax.mail.Session object in JNDI
  -        StringRefAddr lAddress = new StringRefAddr( "nns", lJNDIName );
  -        Reference lReference = new Reference(
  -         Scheduler.class.getName(),
  -         lAddress,
  -         NonSerializableFactory.class.getName(),
  -         null
  -      );
  -        lContext.bind( lName.get( 0 ), lReference );
  -
  -        log.info( "JBoss Scheduler Service '" + getJNDIName() + "' bound to " + 
lJNDIName );
  -    }
  -
  -    private void unbind() throws NamingException {
  -      String lJNDIName = getJNDIName();
  -
  -      new InitialContext().unbind( lJNDIName );
  -      NonSerializableFactory.unbind( lJNDIName );
  -      log.info("JBoss Scheduler service '" + lJNDIName + "' removed from JNDI" );
  -    }
  -
  -   // -------------------------------------------------------------------------
      // Inner Classes
      // -------------------------------------------------------------------------
   
  @@ -702,6 +665,33 @@
      }
   
      /**
  +    * Filter to ensure that each Scheduler only gets notified when it is supposed 
to.
  +    */
  +   private static class NotificationFilter implements 
javax.management.NotificationFilter {
  +   
  +      private Integer mId;
  +   
  +      /**
  +       * Create a Filter.
  +       * @param id the Scheduler id
  +       */
  +      public NotificationFilter( Integer pId ){
  +         mId = pId;
  +      }
  +   
  +      /**
  +       * Determine if the notification should be sent to this Scheduler
  +       */
  +      public boolean isNotificationEnabled( Notification pNotification ) {
  +         if( pNotification instanceof TimerNotification ) {
  +            TimerNotification lTimerNotification = (TimerNotification) 
pNotification;
  +            return lTimerNotification.getNotificationID().equals( mId );
  +         }
  +         return false;
  +      }
  +   }
  +
  +   /**
       * A test class for a Schedulable Class
       **/
      public static class SchedulableExample
  @@ -731,34 +721,4 @@
               ", test, name: " + mName + ", value: " + mValue );
         }
      }
  -}
  -
  -/**
  - * Filter to ensure that each Scheduler only gets notified when it is supposed to.
  - */
  -class SchedulerNotificationFilter implements javax.management.NotificationFilter{
  -
  -   private Integer mId;
  -
  -   /**
  -    * Create a Filter.
  -    * @param id the Scheduler id
  -    */
  -   public SchedulerNotificationFilter(Integer id){
  -     mId = id;
  -   }
  -
  -   /**
  -    * Determine if the notification should be sent to this Scheduler
  -    */
  -   public boolean isNotificationEnabled(Notification notification){
  -     if (notification instanceof javax.management.timer.TimerNotification){
  -       TimerNotification timerNotification = (TimerNotification) notification;
  -       if (timerNotification.getNotificationID().equals(mId)){
  -         return true;
  -       }
  -     }
  -     return false;
  -   }
  -
   }
  
  
  
  1.6       +26 -0     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SchedulerMBean.java       2001/08/30 03:50:12     1.5
  +++ SchedulerMBean.java       2001/11/02 06:07:48     1.6
  @@ -135,6 +135,23 @@
      public void setSchedulePeriod( long pPeriod );
      
      /**
  +   * @return Date (and time) of the first scheduled call. Value is in milliseconds 
since 1/1/1970.
  +   *         If date is in the past when the schedule is added to the Timer then 
the schedule will
  +   *         started immediately
  +   **/
  +   public long getInitialStartDate();
  +   
  +   /**
  +   * Sets the first scheduled call. If in the past when the scheduler gets setup it 
will start
  +   * immediately.
  +   *
  +   * @param pStartDate Date in milliseconds since 1/1/1970 for the first initial 
call. Anything
  +   *                   less than zero means 1/1/1970. Any date less than now means 
the schedule
  +   *                   will be started immediately.
  +   **/
  +   public void setInitialStartDate( long pStartDate );
  +   
  +   /**
       * @return Number of scheduled calls initially. If -1 then there is not limit.
       **/
      public long getInitialRepetitions();
  @@ -165,5 +182,14 @@
       * @return True if any attributes are changed but the Schedule is not restarted 
yet.
       **/
      public boolean isRestartPending();
  +   
  +   /**
  +   * 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
  +   **/
  +   public void setStartAtStartup( boolean pStartAtStartup );
   
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to