View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.portal.service.daemon;
35  
36  import fr.paris.lutece.util.date.DateUtil;
37  
38  import java.util.Date;
39  
40  
41  /**
42   *  this class is used to manage daemons declaration
43   */
44  public final class DaemonEntry
45  {
46      private String _strId;
47      private String _strNameKey;
48      private String _strDescriptionKey;
49      private String _strClassName;
50      private Date _dateLastRunDate;
51      private String _strLastRunLogs;
52      private long _lInterval;
53      private boolean _bOnStartup;
54      private boolean _bIsRunning;
55      private Daemon _daemon;
56      private DaemonThread _thread;
57      private String _strPluginName;
58  
59      // Variables declarations
60  
61      /**
62       * Constructor
63       */
64      public DaemonEntry(  )
65      {
66          _thread = new DaemonThread( this );
67      }
68  
69      /**
70       * Returns the Id
71       *
72       * @return The Id
73       */
74      public String getId(  )
75      {
76          return _strId;
77      }
78  
79      /**
80       * Sets the Id
81       *
82       * @param strId The Id
83       */
84      public void setId( String strId )
85      {
86          _strId = strId;
87      }
88  
89      /**
90       * Returns the NameKey
91       *
92       * @return The NameKey
93       */
94      public String getNameKey(  )
95      {
96          return _strNameKey;
97      }
98  
99      /**
100      * Sets the NameKey
101      *
102      * @param strNameKey The NameKey
103      */
104     public void setNameKey( String strNameKey )
105     {
106         _strNameKey = strNameKey;
107     }
108 
109     /**
110      * Returns the DescriptionKey
111      *
112      * @return The DescriptionKey
113      */
114     public String getDescriptionKey(  )
115     {
116         return _strDescriptionKey;
117     }
118 
119     /**
120      * Sets the DescriptionKey
121      *
122      * @param strDescriptionKey The DescriptionKey
123      */
124     public void setDescriptionKey( String strDescriptionKey )
125     {
126         _strDescriptionKey = strDescriptionKey;
127     }
128 
129     /**
130      * Returns the ClassName
131      *
132      * @return The ClassName
133      */
134     public String getClassName(  )
135     {
136         return _strClassName;
137     }
138 
139     /**
140      * Sets the ClassName
141      *
142      * @param strClassName The ClassName
143      */
144     public void setClassName( String strClassName )
145     {
146         _strClassName = strClassName;
147     }
148 
149     /**
150      * Load the daemon
151      *
152      * @throws ClassNotFoundException If an error occured
153      * @throws InstantiationException If an error occured
154      * @throws IllegalAccessException If an error occured
155      */
156     public void loadDaemon(  ) throws ClassNotFoundException, InstantiationException, IllegalAccessException
157     {
158         _daemon = (Daemon) Class.forName( _strClassName ).newInstance(  );
159     }
160 
161     /**
162      * Returns the daemon associated to the entry
163      *
164      * @return The daemon
165      */
166     protected Daemon getDaemon(  )
167     {
168         return _daemon;
169     }
170 
171     /**
172      * Returns the thread which start the daemon task
173      * @return The thread
174      */
175     public DaemonThread getDaemonThread(  )
176     {
177         return _thread;
178     }
179 
180     /**
181      * Returns the Interval of time in seconds between two executions
182      * @return _lInterval the interval of time
183      */
184     public long getInterval(  )
185     {
186         return _lInterval;
187     }
188 
189     /**
190      * Indicates if the daemon must be process on system startup
191      * @return _bOnStartup
192      */
193     public boolean onStartup(  )
194     {
195         return _bOnStartup;
196     }
197 
198     /**
199      * Checks if the daemon is running
200      * @return True if the thread is running, otherwise false
201      */
202     public boolean isRunning(  )
203     {
204         return _bIsRunning;
205     }
206 
207     /**
208      * Set running daemon status
209      * @param bIsRunning True if the thread is running, otherwise false
210      */
211     public void setIsRunning( boolean bIsRunning )
212     {
213         _bIsRunning = bIsRunning;
214     }
215 
216     /**
217      * Returns the PluginName
218      *
219      * @return The PluginName
220      */
221     public String getPluginName(  )
222     {
223         return _strPluginName;
224     }
225 
226     /**
227      * Sets the PluginName
228      *
229      * @param strPluginName The PluginName
230      */
231     public void setPluginName( String strPluginName )
232     {
233         _strPluginName = strPluginName;
234     }
235 
236     /**
237      * Returns the LastRunDate
238      *
239      * @return The LastRunDate
240      */
241     public String getLastRunDate(  )
242     {
243         return ( _dateLastRunDate != null ) ? DateUtil.getDateTimeString( _dateLastRunDate.getTime(  ) ) : "";
244     }
245 
246     /**
247      * Sets the LastRunDate
248      *
249      * @param dateLastRunDate The LastRunDate
250      */
251     public void setLastRunDate( Date dateLastRunDate )
252     {
253         _dateLastRunDate = dateLastRunDate;
254     }
255 
256     /**
257      * Returns the LastRunLogs
258      *
259      * @return The LastRunLogs
260      */
261     public String getLastRunLogs(  )
262     {
263         return ( _strLastRunLogs != null ) ? _strLastRunLogs : "";
264     }
265 
266     /**
267      * Sets the LastRunLogs
268      *
269      * @param strLastRunLogs The LastRunLogs
270      */
271     public void setLastRunLogs( String strLastRunLogs )
272     {
273         _strLastRunLogs = strLastRunLogs;
274     }
275 
276     /**
277      * Sets the interval
278      * @param lInterval The interval
279      */
280     public void setInterval( long lInterval )
281     {
282         _lInterval = lInterval;
283     }
284 
285     /**
286      * Sets the OnStartUp property
287      * @param bOnStartup True if the daemon should be launched on startup, otherwise false
288      */
289     public void setOnStartUp( boolean bOnStartup )
290     {
291         _bOnStartup = bOnStartup;
292     }
293 }