[jboss-cvs] jboss-j2se/src/main/javax/management/timer ...

Dimitris Andreadis dimitris.andreadis at jboss.com
Thu Jul 13 09:21:17 EDT 2006


  User: dimitris
  Date: 06/07/13 09:21:17

  Modified:    src/main/javax/management/timer  Timer.java
  Log:
  JBAS-3281, implement the fixed-rate API methods. Add support for fixed-delay execution, make it default (it was fixed-rate before)
  
  Revision  Changes    Path
  1.3       +302 -336  jboss-j2se/src/main/javax/management/timer/Timer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Timer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-j2se/src/main/javax/management/timer/Timer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- Timer.java	30 Oct 2005 00:05:06 -0000	1.2
  +++ Timer.java	13 Jul 2006 13:21:17 -0000	1.3
  @@ -1,24 +1,24 @@
   /*
  -* 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 javax.management.timer;
   
   import java.util.Date;
  @@ -32,18 +32,18 @@
   import javax.management.NotificationBroadcasterSupport;
   import javax.management.ObjectName;
   
  +import org.jboss.logging.Logger;
   import org.jboss.mx.util.RunnableScheduler;
   import org.jboss.mx.util.SchedulableRunnable;
  -import org.jboss.logging.Logger;
   
   /**
    * The timer service.
    *
    * @author <a href="mailto:Adrian.Brock at HappeningTimes.com">Adrian Brock</a>
  - * @version $Revision: 1.2 $
  + * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
  + * @version $Revision: 1.3 $
    */
  -public class Timer
  -  extends NotificationBroadcasterSupport
  +public class Timer extends NotificationBroadcasterSupport
     implements TimerMBean, MBeanRegistration
   {
      // logging support
  @@ -51,81 +51,51 @@
   
     // Constants -----------------------------------------------------
   
  -  /**
  -   * The number of milliseconds in one second.
  -   */
  +   /** The number of milliseconds in one second. */
     public static final long ONE_SECOND = 1000;
   
  -  /**
  -   * The number of milliseconds in one minute.
  -   */
  +   /** The number of milliseconds in one minute. */
     public static final long ONE_MINUTE = ONE_SECOND * 60;
   
  -  /**
  -   * The number of milliseconds in one hour.
  -   */
  +   /** The number of milliseconds in one hour. */
     public static final long ONE_HOUR = ONE_MINUTE * 60;
   
  -  /**
  -   * The number of milliseconds in one day.
  -   */
  +   /** The number of milliseconds in one day. */
     public static final long ONE_DAY = ONE_HOUR * 24;
   
  -  /**
  -   * The number of milliseconds in one week.
  -   */
  +   /** The number of milliseconds in one week. */
     public static final long ONE_WEEK = ONE_DAY * 7;
   
  -  /**
  -   * Don't send notifications at initial start up.
  -   */
  +   /** Don't send notifications at initial start up. */
     private static final int SEND_NO = 0;
   
  -  /**
  -   * Send all past notifications at initial start up.
  -   */
  +   /** Send all past notifications at initial start up. */
     private static final int SEND_START = 1;
   
  -  /**
  -   * Normal operation sending
  -   */
  +   /** Normal operation sending */
     private static final int SEND_NORMAL = 2;
   
     // Attributes ----------------------------------------------------
   
  -  /**
  -   * The next notification id.
  -   */
  +   /** The next notification id. */
     int nextId = 0;
   
  -  /**
  -   * The next notification sequence number.
  -   */
  +   /** The next notification sequence number. */
     long sequenceNumber = 0;
   
  -  /**
  -   * The send past events attribute.
  -   */
  +   /** The send past events attribute. */
     boolean sendPastNotifications = false;
   
  -  /**
  -   * Whether the service is active.
  -   */
  +   /** Whether the service is active. */
     boolean active = false;
   
  -  /**
  -   * Our object name.
  -   */
  +   /** Our object name. */
     ObjectName objectName;
   
  -  /**
  -   * The registered notifications.
  -   */
  +   /** The registered notifications. */
     HashMap notifications = new HashMap();
   
  -  /**
  -   * The scheduler
  -   */
  +   /** The scheduler */
     private RunnableScheduler scheduler = new RunnableScheduler();
   
     // Static --------------------------------------------------------
  @@ -136,22 +106,46 @@
   
     // TimerMBean implementation -------------------------------------
   
  -  public Integer addNotification(String type, String message, Object userData,
  -                                 Date date)
  +   public Integer addNotification(String type, String message, Object userData, Date date)
       throws IllegalArgumentException
     {
       return addNotification(type, message, userData, date, 0);
     }
   
  -  public Integer addNotification(String type, String message, Object userData,
  -                                 Date date, long period)
  +   public Integer addNotification(String type, String message, Object userData, Date date, long period)
       throws IllegalArgumentException
     {
       return addNotification(type, message, userData, date, period, 0);
     }
   
  -  public Integer addNotification(String type, String message,
  -                Object userData, Date date, long period, long occurences)
  +   public Integer addNotification(String type, String message, Object userData, Date date, long period, long occurences)
  +      throws IllegalArgumentException
  +   {
  +      return addNotification(type, message, userData, date, period, occurences, false);
  +   }
  +
  +   /**
  +    * Creates a new timer notification with the specified type, message and userData and inserts it into the list of notifications with a given date, period and number of occurences.
  +    * <p/>
  +    * If the timer notification to be inserted has a date that is before the current date, the method behaves as if the specified date were the current date.
  +    * For once-off notifications, the notification is delivered immediately.
  +    * For periodic notifications, the first notification is delivered immediately and the subsequent ones are spaced as specified by the period parameter.
  +    * <p/>
  +    * Note that once the timer notification has been added into the list of notifications, its associated date, period and number of occurences cannot be updated.
  +    * <p/>
  +    * In the case of a periodic notification, the value of parameter fixedRate is used to specify the execution scheme, as specified in Timer.
  +    *
  +    * @param type         The timer notification type.
  +    * @param message      The timer notification detailed message.
  +    * @param userData     The timer notification user data object.
  +    * @param date         The date when the notification occurs.
  +    * @param period       The period of the timer notification (in milliseconds).
  +    * @param nbOccurences The total number the timer notification will be emitted.
  +    * @param fixedRate    If true and if the notification is periodic, the notification is scheduled with a fixed-rate execution scheme. If false and if the notification is periodic, the notification is scheduled with a fixed-delay execution scheme. Ignored if the notification is not periodic.
  +    * @return The identifier of the new created timer notification.
  +    * @throws IllegalArgumentException The period or the number of occurences is negative
  +    */
  +   public Integer addNotification(String type, String message, Object userData, Date date, long period, long nbOccurences, boolean fixedRate)
       throws IllegalArgumentException
     {
        // Generate the next id.
  @@ -161,8 +155,7 @@
   
       // Validate and create the registration.
       RegisteredNotification rn =
  -      new RegisteredNotification(id, type, message, userData, date, period,
  -                                 occurences);
  +         new RegisteredNotification(id, type, message, userData, date, period, nbOccurences, fixedRate);
   
       // Add the registration.
       synchronized(notifications)
  @@ -218,8 +211,13 @@
       */
      public Boolean getFixedRate(Integer id)
      {
  -      //[todo] implement getFixedRate
  -      throw new RuntimeException("NYI");
  +      // Make sure there is a registration
  +      RegisteredNotification rn = (RegisteredNotification) notifications.get(id);
  +      if (rn == null)
  +         return null;
  +
  +      // Return a copy of the fixedRate
  +      return new Boolean(rn.fixedRate);
      }
   
      public Vector getNotificationIDs(String type)
  @@ -419,33 +417,6 @@
       scheduler.stop();
     }
   
  -   /**
  -    * Creates a new timer notification with the specified type, message and userData and inserts it into the list of notifications with a given date, period and number of occurences.
  -    * <p/>
  -    * If the timer notification to be inserted has a date that is before the current date, the method behaves as if the specified date were the current date.
  -    * For once-off notifications, the notification is delivered immediately.
  -    * For periodic notifications, the first notification is delivered immediately and the subsequent ones are spaced as specified by the period parameter.
  -    * <p/>
  -    * Note that once the timer notification has been added into the list of notifications, its associated date, period and number of occurences cannot be updated.
  -    * <p/>
  -    * In the case of a periodic notification, the value of parameter fixedRate is used to specify the execution scheme, as specified in Timer.
  -    *
  -    * @param type         The timer notification type.
  -    * @param message      The timer notification detailed message.
  -    * @param userData     The timer notification user data object.
  -    * @param date         The date when the notification occurs.
  -    * @param period       The period of the timer notification (in milliseconds).
  -    * @param nbOccurences The total number the timer notification will be emitted.
  -    * @param fixedRate    If true and if the notification is periodic, the notification is scheduled with a fixed-rate execution scheme. If false and if the notification is periodic, the notification is scheduled with a fixed-delay execution scheme. Ignored if the notification is not periodic.
  -    * @return The identifier of the new created timer notification.
  -    * @throws IllegalArgumentException The period or the number of occurences is negative
  -    */
  -   public Integer addNotification(String type, String message, Object userData, Date date, long period, long nbOccurences, boolean fixedRate) throws IllegalArgumentException
  -   {
  -      // [todo] implement addNotification
  -      throw new RuntimeException("NYI");
  -   }
  -
      // MBeanRegistrationImplementation overrides ---------------------
   
     public ObjectName preRegister(MBeanServer server, ObjectName objectName)
  @@ -539,54 +510,38 @@
     /**
      * A registered notification. These run as separate threads.
      */
  -  private class RegisteredNotification
  -    extends SchedulableRunnable
  +   private class RegisteredNotification extends SchedulableRunnable
     {
       // Attributes ----------------------------------------------------
   
  -    /**
  -     * The notification id.
  -     */
  +      /** The notification id. */
       public Integer id;
   
  -    /**
  -     * The notification type.
  -     */
  +      /** The notification type. */
       public String type;
   
  -    /**
  -     * The message.
  -     */
  +      /** The message. */
       public String message;
   
  -    /**
  -     * The user data.
  -     */
  +      /** The user data. */
       public Object userData;
   
  -    /**
  -     * The start date.
  -     */
  +      /** The start date. */
       public long startDate;
   
  -    /**
  -     * The period.
  -     */
  +      /** The period. */
       public long period;
   
  -    /**
  -     * The maximum number of occurences.
  -     */
  +      /** The maximum number of occurences. */
       public long occurences;
   
  -    /**
  -     * The send type, no send, past notifications or normal
  -     */
  +      /** The flag to indicate fixedRate notifications, or fixedDelay (default) */
  +      public boolean fixedRate;
  +      
  +      /** The send type, no send, past notifications or normal */
       public int sendType = SEND_NORMAL;
   
  -    /**
  -     * The next run date
  -     */
  +      /** The next run date */
       public long nextDate = 0;
   
       // Constructors --------------------------------------------------
  @@ -603,11 +558,17 @@
        *        no repeat.
        * @param occurences the maximum number of repeats. When the period is not
        *        zero and this parameter is zero, it will repeat indefinitely.
  +       * @param fixedRate If true and if the notification is periodic, the notification
  +       *        is scheduled with a fixed-rate execution scheme. If false and if the notification
  +       *        is periodic, the notification is scheduled with a fixed-delay execution scheme.
  +       *        Ignored if the notification is not periodic.
  +       *
        * @exception IllegalArgumentException when the date is before the current
        *        date, the period is negative or the number of repeats is
        *        negative.
        */
  -    public RegisteredNotification(Integer id, String type, String message, Object userData, Date startDate, long period, long occurences)
  +      public RegisteredNotification(Integer id, String type, String message, Object userData,
  +            Date startDate, long period, long occurences, boolean fixedRate)
               throws IllegalArgumentException
       {
          // Basic validation
  @@ -621,7 +582,7 @@
          this.startDate = startDate.getTime();
          if (startDate.getTime() < System.currentTimeMillis())
          {
  -          log.warn("startDate [" + startDate + "] in the past, set to now");
  +            log.debug("startDate [" + startDate + "] in the past, set to now");
             this.startDate = System.currentTimeMillis();
          }
   
  @@ -632,6 +593,7 @@
          this.userData = userData;
          this.period = period;
          this.occurences = occurences;
  +         this.fixedRate = fixedRate;
   
          this.nextDate = this.startDate;
   
  @@ -664,7 +626,10 @@
           }
   
           // Calculate the next occurence
  +         if (fixedRate)
           nextDate += period;
  +         else // fixed delay
  +            nextDate = System.currentTimeMillis() + period;
   
           return true;
        }
  @@ -683,7 +648,8 @@
        public String toString()
        {
           return " RegisteredNotification: [timer=" + objectName + ",id=" + id + ",startDate=" + new Date(startDate) +
  -                ",periode=" + period + ",occurences=" + occurences + ",nextDate=" + new Date(nextDate) + "]";
  +                ",period=" + period + ",occurences=" + occurences + ",fixedRate=" + fixedRate +
  +                ",nextDate=" + new Date(nextDate) + "]";
        }
     }
   }
  
  
  



More information about the jboss-cvs-commits mailing list