KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > scheduler > ScheduleEvent


1 /*
2  * Copyright (C) 2001 - 2005 ScalAgent Distributed Technologies
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  *
19  * Initial developer(s): ScalAgent Distributed Technologies
20  * Contributor(s):
21  */

22 package com.scalagent.scheduler;
23
24 import java.util.*;
25 import fr.dyade.aaa.agent.*;
26
27 /**
28  * Base class for notifications requesting a scheduling to a
29  * <code>Scheduler</code> agent. The event holds a name which is the name of
30  * the condition the scheduler is requested to send.
31  * <p>
32  * The base class implements a one shot scheduling. A positive
33  * <code>Condition</code> notification is sent at the event start date, and a
34  * negative one is sent when the not null duration expires.
35  * This is true as long as the <code>Scheduler</code> agent is active at
36  * (about) the scheduling date and time. If the agent server was down at that
37  * time, the outdated event is triggered only if its
38  * <code>outdatedRestart</code> field is true.
39  * <p>
40  * This class is also used by the <code>Scheduler</code> agent to keep the
41  * request until it is complete.
42  *
43  * @see Scheduler
44  * @see Condition
45  */

46 public class ScheduleEvent extends Notification {
47   /** event and condition name */
48   protected String JavaDoc name;
49   /** event scheduling date */
50   protected Date date;
51   /** event duration in seconds */
52   protected long duration;
53   /** execute outdated event on restart */
54   protected boolean outdatedRestart;
55
56
57   /**
58    * Creates an item.
59    *
60    * @param name event and condition name
61    * @param date event scheduling date
62    * @param duration event duration in seconds
63    * @param outdatedRestart execute outdated event on restart
64    */

65   public ScheduleEvent(String JavaDoc name, Date date, long duration, boolean outdatedRestart) {
66     this.name = name;
67     this.date = date;
68     this.duration = duration;
69     this.outdatedRestart = outdatedRestart;
70   }
71
72   /**
73    * Creates an item with a default value for <code>outdatedRestart</code>.
74    * <p>
75    * <code>outdatedRestart</code> is given a <code>true</code> value when
76    * <code>duration</code> value is <code>0</code>.
77    *
78    * @param name event and condition name
79    * @param date event scheduling date
80    * @param duration event duration in seconds
81    */

82   public ScheduleEvent(String JavaDoc name, Date date, long duration) {
83     this(name, date, duration, duration == 0);
84   }
85
86   /**
87    * Creates an item with null duration.
88    *
89    * @param name event and condition name
90    * @param date event scheduling date
91    */

92   public ScheduleEvent(String JavaDoc name, Date date) {
93     this(name, date, 0);
94   }
95
96
97   /**
98    * Provides a string image for this object.
99    *
100    * @return a string image for this object
101    */

102   public StringBuffer JavaDoc toString(StringBuffer JavaDoc output) {
103     output.append('(');
104     output.append(super.toString(output));
105     output.append(",name=");
106     output.append(name);
107     output.append(",date=");
108     output.append(date);
109     output.append(",duration=");
110     output.append(duration);
111     output.append(",outdatedRestart=");
112     output.append(outdatedRestart);
113     output.append(')');
114     return output;
115   }
116
117   /**
118    * Returns the next scheduling date after current date given as parameter. The
119    * new date must be strictly greater than the current date. A
120    * <code>null</code> date leads to the scheduler deleting the event.
121    * <p>
122    * This function should be overloaded in derived classes to actually implement
123    * recurrent scheduling.
124    *
125    * @param now
126    * current date
127    * @return next scheduling date after now
128    */

129   Date nextDate(Date now) {
130     if (date == null)
131       return null;
132     if (date.after(now))
133       return date;
134     return null;
135   }
136 }
137
Popular Tags