KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > cornerstone > blocks > scheduler > TimeScheduledEntry


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.cornerstone.blocks.scheduler;
19
20 import java.text.SimpleDateFormat JavaDoc;
21 import java.util.Date JavaDoc;
22 import org.apache.avalon.cornerstone.services.scheduler.Target;
23 import org.apache.avalon.cornerstone.services.scheduler.TimeTrigger;
24
25 /**
26  * Class use internally to package to hold scheduled time entries.
27  *
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  */

30 public final class TimeScheduledEntry
31     implements Comparable JavaDoc
32 {
33     private static final SimpleDateFormat JavaDoc DATEFORMAT = new SimpleDateFormat JavaDoc();
34
35     private final String JavaDoc m_name;
36     private final TimeTrigger m_trigger;
37     private final Target m_target;
38
39     //cached version of time from TimeTrigger class
40
private long m_time;
41     private boolean m_isValid;
42
43     public TimeScheduledEntry( String JavaDoc name, TimeTrigger trigger, Target target )
44     {
45         m_name = name;
46         m_trigger = trigger;
47         m_target = target;
48         //m_time = m_trigger.getTimeAfter( System.currentTimeMillis() );
49
m_isValid = true;
50     }
51
52     /**
53      * Return name of trigger.
54      *
55      * @return the name of trigger
56      */

57     public String JavaDoc getName()
58     {
59         return m_name;
60     }
61
62     public Target getTarget()
63     {
64         return m_target;
65     }
66
67     public TimeTrigger getTimeTrigger()
68     {
69         return m_trigger;
70     }
71
72     /**
73      * Determine if this entry is valid
74      *
75      * @return true if trigger is valid, false otherwise
76      */

77     public boolean isValid()
78     {
79         return m_isValid;
80     }
81
82     /**
83      * Invalidate trigger
84      */

85     public void invalidate()
86     {
87         m_isValid = false;
88     }
89
90     /**
91      * Retrieve cached time when trigger should run next.
92      *
93      * @return the time in milliseconds when trigger should run
94      */

95     public long getNextTime()
96     {
97         return m_time;
98     }
99
100     /**
101      * Set cached time in milliseconds when trigger should run
102      *
103      * @param time the time
104      */

105     public void setNextTime( long time )
106     {
107         m_time = time;
108     }
109
110     /**
111      * Implement comparable interface used to help sort triggers.
112      * Triggers are compared based on next time to run
113      *
114      * @param object the other trigger
115      * @return -'ve value if other trigger occurs before this trigger
116      */

117     public int compareTo( final Object JavaDoc object )
118     {
119         final TimeScheduledEntry other = (TimeScheduledEntry)object;
120         return (int)-( other.m_time - m_time );
121     }
122
123     public String JavaDoc toString()
124     {
125         return "TimeEntry[ name=" + m_name + " valid=" + m_isValid + " time=" + DATEFORMAT.format( new Date JavaDoc( m_time ) ) + " ]";
126     }
127 }
128
129
Popular Tags