1292 lines · 48.7 KB · Java
RawDownload
            .append("\n\tNotification period = ")            .append(period)            .append("\n\tNotification nb of occurrences = ")            .append(nbOccurences)            .append("\n\tNotification executes at fixed rate = ")            .append(fixedRate);            TIMER_LOGGER.logp(Level.FINER, Timer.class.getName(),                    "addNotification", strb.toString());        }         timerTable.put(notifID, obj);         // Update and start the TimerAlarmClock.        //        if (isActive == true) {          if (fixedRate)          {            timer.schedule(alarmClock, alarmClock.next);          }          else          {            timer.schedule(alarmClock, alarmClock.timeout);          }        }         TIMER_LOGGER.logp(Level.FINER, Timer.class.getName(),                "addNotification", "timer notification added");        return notifID;    }     /**     * Creates a new timer notification with the specified <CODE>type</CODE>, <CODE>message</CODE>     * and <CODE>userData</CODE> and inserts it into the list of notifications with a given date,     * period and number of occurrences.     * <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. <BR>     * For once-off notifications, the notification is delivered immediately. <BR>     * 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 occurrences cannot be updated.     * <P>     * In the case of a periodic notification, uses a <i>fixed-delay</i> execution scheme, as specified in     * {@link java.util.Timer}. In order to use a <i>fixed-rate</i> execution scheme, use     * {@link #addNotification(String, String, Object, Date, long, long, boolean)} instead.     *     * @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.     *     * @return The identifier of the new created timer notification.     *     * @exception java.lang.IllegalArgumentException The date is {@code null} or     * the period or the number of occurrences is negative.     *     * @see #addNotification(String, String, Object, Date, long, long, boolean)     */// NPCTE fix for bugId 4464388, esc 0,  MR , to be added after modification of jmx spec//  public synchronized Integer addNotification(String type, String message, Serializable userData,//                                              Date date, long period)// end of NPCTE fix for bugId 4464388 */     public synchronized Integer addNotification(String type, String message, Object userData,                                                Date date, long period, long nbOccurences)        throws java.lang.IllegalArgumentException {       return addNotification(type, message, userData, date, period, nbOccurences, false);    }     /**     * Creates a new timer notification with the specified <CODE>type</CODE>, <CODE>message</CODE>     * and <CODE>userData</CODE> and inserts it into the list of notifications with a given date     * and period and a null number of occurrences.     * <P>     * The timer notification will repeat continuously using the timer period using a <i>fixed-delay</i>     * execution scheme, as specified in {@link java.util.Timer}. In order to use a <i>fixed-rate</i>     * execution scheme, use {@link #addNotification(String, String, Object, Date, long, long,     * boolean)} instead.     * <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. The     * first notification is delivered immediately and the subsequent ones are     * spaced as specified by the period parameter.     *     * @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).     *     * @return The identifier of the new created timer notification.     *     * @exception java.lang.IllegalArgumentException The date is {@code null} or     * the period is negative.     */// NPCTE fix for bugId 4464388, esc 0,  MR , to be added after modification of jmx spec//  public synchronized Integer addNotification(String type, String message, Serializable userData,//                                              Date date, long period)// end of NPCTE fix for bugId 4464388 */     public synchronized Integer addNotification(String type, String message, Object userData,                                                Date date, long period)        throws java.lang.IllegalArgumentException {         return (addNotification(type, message, userData, date, period, 0));    }     /**     * Creates a new timer notification with the specified <CODE>type</CODE>, <CODE>message</CODE>     * and <CODE>userData</CODE> and inserts it into the list of notifications with a given date     * and a null period and number of occurrences.     * <P>     * The timer notification will be handled once at the specified date.     * <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 and the     * notification is delivered immediately.     *     * @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.     *     * @return The identifier of the new created timer notification.     *     * @exception java.lang.IllegalArgumentException The date is {@code null}.     */// NPCTE fix for bugId 4464388, esc 0,  MR, to be added after modification of jmx spec//  public synchronized Integer addNotification(String type, String message, Serializable userData, Date date)//      throws java.lang.IllegalArgumentException {// end of NPCTE fix for bugId 4464388     public synchronized Integer addNotification(String type, String message, Object userData, Date date)        throws java.lang.IllegalArgumentException {          return (addNotification(type, message, userData, date, 0, 0));    }     /**     * Removes the timer notification corresponding to the specified identifier from the list of notifications.     *     * @param id The timer notification identifier.     *     * @exception InstanceNotFoundException The specified identifier does not correspond to any timer notification     * in the list of notifications of this timer MBean.     */    public synchronized void removeNotification(Integer id) throws InstanceNotFoundException {         // Check that the notification to remove is effectively in the timer table.        //        if (timerTable.containsKey(id) == false) {            throw new InstanceNotFoundException("Timer notification to remove not in the list of notifications");        }         // Stop the TimerAlarmClock.        //        Object[] obj = timerTable.get(id);        TimerAlarmClock alarmClock = (TimerAlarmClock)obj[ALARM_CLOCK_INDEX];        if (alarmClock != null) {//             alarmClock.interrupt();//             try {//                 // Wait until the thread die.//                 ////                 alarmClock.join();//             } catch (InterruptedException e) {//                 // Ignore...//             }//             // Remove the reference on the TimerAlarmClock.//             //            alarmClock.cancel();        }         // Remove the timer notification from the timer table.        //        if (TIMER_LOGGER.isLoggable(Level.FINER)) {            StringBuilder strb = new StringBuilder()            .append("removing timer notification:")            .append("\n\tNotification source = ")            .append(((TimerNotification)obj[TIMER_NOTIF_INDEX]).getSource())            .append("\n\tNotification type = ")            .append(((TimerNotification)obj[TIMER_NOTIF_INDEX]).getType())            .append("\n\tNotification ID = ")            .append(((TimerNotification)obj[TIMER_NOTIF_INDEX]).getNotificationID())            .append("\n\tNotification date = ")            .append(obj[TIMER_DATE_INDEX])            .append("\n\tNotification period = ")            .append(obj[TIMER_PERIOD_INDEX])            .append("\n\tNotification nb of occurrences = ")            .append(obj[TIMER_NB_OCCUR_INDEX])            .append("\n\tNotification executes at fixed rate = ")            .append(obj[FIXED_RATE_INDEX]);            TIMER_LOGGER.logp(Level.FINER, Timer.class.getName(),                    "removeNotification", strb.toString());        }         timerTable.remove(id);         TIMER_LOGGER.logp(Level.FINER, Timer.class.getName(),                "removeNotification", "timer notification removed");    }     /**     * Removes all the timer notifications corresponding to the specified type from the list of notifications.     *     * @param type The timer notification type.     *     * @exception InstanceNotFoundException The specified type does not correspond to any timer notification     * in the list of notifications of this timer MBean.     */    public synchronized void removeNotifications(String type) throws InstanceNotFoundException {         Vector<Integer> v = getNotificationIDs(type);         if (v.isEmpty())            throw new InstanceNotFoundException("Timer notifications to remove not in the list of notifications");         for (Integer i : v)            removeNotification(i);    }     /**     * Removes all the timer notifications from the list of notifications     * and resets the counter used to update the timer notification identifiers.     */    public synchronized void removeAllNotifications() {         TimerAlarmClock alarmClock;         for (Object[] obj : timerTable.values()) {             // Stop the TimerAlarmClock.            //            alarmClock = (TimerAlarmClock)obj[ALARM_CLOCK_INDEX];//             if (alarmClock != null) {//                 alarmClock.interrupt();//                 try {//                     // Wait until the thread die.//                     ////                     alarmClock.join();//                 } catch (InterruptedException ex) {//                     // Ignore...//                 }                  // Remove the reference on the TimerAlarmClock.                  ////             }            alarmClock.cancel();        }         // Remove all the timer notifications from the timer table.        TIMER_LOGGER.logp(Level.FINER, Timer.class.getName(),                "removeAllNotifications", "removing all timer notifications");         timerTable.clear();         TIMER_LOGGER.logp(Level.FINER, Timer.class.getName(),                "removeAllNotifications", "all timer notifications removed");        // Reset the counterID.        //        counterID = 0;         TIMER_LOGGER.logp(Level.FINER, Timer.class.getName(),                "removeAllNotifications", "timer notification counter ID reset");    }     // GETTERS AND SETTERS    //--------------------     /**     * Gets the number of timer notifications registered into the list of notifications.     *     * @return The number of timer notifications.     */    public int getNbNotifications() {        return timerTable.size();    }     /**     * Gets all timer notification identifiers registered into the list of notifications.     *     * @return A vector of <CODE>Integer</CODE> objects containing all the timer notification identifiers.     * <BR>The vector is empty if there is no timer notification registered for this timer MBean.     */    public synchronized Vector<Integer> getAllNotificationIDs() {        return new Vector<Integer>(timerTable.keySet());    }     /**     * Gets all the identifiers of timer notifications corresponding to the specified type.     *     * @param type The timer notification type.     *     * @return A vector of <CODE>Integer</CODE> objects containing all the identifiers of     * timer notifications with the specified <CODE>type</CODE>.     * <BR>The vector is empty if there is no timer notifications registered for this timer MBean     * with the specified <CODE>type</CODE>.     */    public synchronized Vector<Integer> getNotificationIDs(String type) {         String s;         Vector<Integer> v = new Vector<Integer>();         for (Map.Entry<Integer,Object[]> entry : timerTable.entrySet()) {            Object[] obj = entry.getValue();            s = ((TimerNotification)obj[TIMER_NOTIF_INDEX]).getType();            if ((type == null) ? s == null : type.equals(s))                v.addElement(entry.getKey());        }        return v;    }    // 5089997: return is Vector<Integer> not Vector<TimerNotification>     /**     * Gets the timer notification type corresponding to the specified identifier.     *     * @param id The timer notification identifier.     *     * @return The timer notification type or null if the identifier is not mapped to any     * timer notification registered for this timer MBean.     */    public String getNotificationType(Integer id) {         Object[] obj = timerTable.get(id);        if (obj != null) {            return ( ((TimerNotification)obj[TIMER_NOTIF_INDEX]).getType() );        }        return null;    }     /**     * Gets the timer notification detailed message corresponding to the specified identifier.     *     * @param id The timer notification identifier.     *     * @return The timer notification detailed message or null if the identifier is not mapped to any     * timer notification registered for this timer MBean.     */    public String getNotificationMessage(Integer id) {         Object[] obj = timerTable.get(id);        if (obj != null) {            return ( ((TimerNotification)obj[TIMER_NOTIF_INDEX]).getMessage() );        }        return null;    }     /**     * Gets the timer notification user data object corresponding to the specified identifier.     *     * @param id The timer notification identifier.     *     * @return The timer notification user data object or null if the identifier is not mapped to any     * timer notification registered for this timer MBean.     */    // NPCTE fix for bugId 4464388, esc 0, MR, 03 sept 2001, to be added after modification of jmx spec    //public Serializable getNotificationUserData(Integer id) {    // end of NPCTE fix for bugId 4464388     public Object getNotificationUserData(Integer id) {        Object[] obj = timerTable.get(id);        if (obj != null) {            return ( ((TimerNotification)obj[TIMER_NOTIF_INDEX]).getUserData() );        }        return null;    }     /**     * Gets a copy of the date associated to a timer notification.     *     * @param id The timer notification identifier.     *     * @return A copy of the date or null if the identifier is not mapped to any     * timer notification registered for this timer MBean.     */    public Date getDate(Integer id) {         Object[] obj = timerTable.get(id);        if (obj != null) {            Date date = (Date)obj[TIMER_DATE_INDEX];            return (new Date(date.getTime()));        }        return null;    }     /**     * Gets a copy of the period (in milliseconds) associated to a timer notification.     *     * @param id The timer notification identifier.     *     * @return A copy of the period or null if the identifier is not mapped to any     * timer notification registered for this timer MBean.     */    public Long getPeriod(Integer id) {         Object[] obj = timerTable.get(id);        if (obj != null) {            return (Long)obj[TIMER_PERIOD_INDEX];        }        return null;    }     /**     * Gets a copy of the remaining number of occurrences associated to a timer notification.     *     * @param id The timer notification identifier.     *     * @return A copy of the remaining number of occurrences or null if the identifier is not mapped to any     * timer notification registered for this timer MBean.     */    public Long getNbOccurences(Integer id) {         Object[] obj = timerTable.get(id);        if (obj != null) {            return (Long)obj[TIMER_NB_OCCUR_INDEX];        }        return null;    }     /**     * Gets a copy of the flag indicating whether a periodic notification is     * executed at <i>fixed-delay</i> or at <i>fixed-rate</i>.     *     * @param id The timer notification identifier.     *     * @return A copy of the flag indicating whether a periodic notification is     *         executed at <i>fixed-delay</i> or at <i>fixed-rate</i>.     */    public Boolean getFixedRate(Integer id) {       Object[] obj = timerTable.get(id);      if (obj != null) {        Boolean fixedRate = (Boolean)obj[FIXED_RATE_INDEX];        return (Boolean.valueOf(fixedRate.booleanValue()));      }      return null;    }     /**     * Gets the flag indicating whether or not the timer sends past notifications.     * <BR>The default value of the past notifications sending on/off flag is <CODE>false</CODE>.     *     * @return The past notifications sending on/off flag value.     *     * @see #setSendPastNotifications     */    public boolean getSendPastNotifications() {        return sendPastNotifications;    }     /**     * Sets the flag indicating whether the timer sends past notifications or not.     * <BR>The default value of the past notifications sending on/off flag is <CODE>false</CODE>.     *     * @param value The past notifications sending on/off flag value.     *     * @see #getSendPastNotifications     */    public void setSendPastNotifications(boolean value) {        sendPastNotifications = value;    }     /**     * Tests whether the timer MBean is active.     * A timer MBean is marked active when the {@link #start start} method is called.     * It becomes inactive when the {@link #stop stop} method is called.     * <BR>The default value of the active on/off flag is <CODE>false</CODE>.     *     * @return <CODE>true</CODE> if the timer MBean is active, <CODE>false</CODE> otherwise.     */    public boolean isActive() {        return isActive;    }     /**     * Tests whether the list of timer notifications is empty.     *     * @return <CODE>true</CODE> if the list of timer notifications is empty, <CODE>false</CODE> otherwise.     */    public boolean isEmpty() {        return (timerTable.isEmpty());    }     /*     * ------------------------------------------     *  PRIVATE METHODS     * ------------------------------------------     */     /**     * Sends or not past notifications depending on the specified flag.     *     * @param currentDate The current date.     * @param currentFlag The flag indicating if past notifications must be sent or not.     */

Lines 501–1000 of 1292. Previous lines