KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > backgroundtask > util > BackgroundTask


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: BackgroundTask.java,v 1.3 2007/01/07 06:15:03 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.patterns.backgroundtask.util;
23
24 import java.util.TimerTask JavaDoc;
25
26 import org.opensubsystems.core.util.SetupReader;
27
28 /**
29  * Background task is base class for all tasks which should be run in the
30  * background, that is without user interaction, to execute its functionality.
31  *
32  * @version $Id: BackgroundTask.java,v 1.3 2007/01/07 06:15:03 bastafidli Exp $
33  * @author Miro Halas
34  * @code.reviewer Miro Halas
35  * @code.reviewed Initial revision
36  */

37 public abstract class BackgroundTask extends TimerTask JavaDoc
38 {
39    // Attributes ///////////////////////////////////////////////////////////////
40

41    /**
42     * Description of the task, will show in the gui.
43     */

44    protected String JavaDoc m_strTaskDescription;
45    
46    /**
47     * Reader to read configuration for this task.
48     */

49    protected SetupReader m_setupReader;
50    
51    /**
52     * Delay from creation of the task to first invocation
53     */

54    protected Integer JavaDoc m_startDelay;
55    
56    /**
57     * How often to run this task
58     */

59    protected Integer JavaDoc m_runEvery;
60    
61    // Constructors /////////////////////////////////////////////////////////////
62

63    /**
64     * Default constructor
65     *
66     * @param strTaskDescription - description of the task, will show in the gui
67     * @param setupReader - reader to read configuration for this task. Must also
68     * implement BackgroundTaskSetupReader interface
69     */

70    public BackgroundTask(
71       String JavaDoc strTaskDescription,
72       SetupReader setupReader
73    )
74    {
75       super();
76       
77       m_strTaskDescription = strTaskDescription;
78       m_setupReader = setupReader;
79       
80       m_startDelay = setupReader.getIntegerParameterValue(
81                ((BackgroundTaskSetupReader)setupReader).getStartDelayParameterName());
82
83       m_runEvery = setupReader.getIntegerParameterValue(
84                ((BackgroundTaskSetupReader)setupReader).getRunEveryParameterName());
85    }
86    
87    /**
88     * Get setup reader used to read properties for this task. It must implement
89     * BackgroundTaskSetupReader interface.
90     *
91     * @return SetupReader - reader implementing BackgroundTaskSetupReader interface
92     */

93    public SetupReader getSetupReader()
94    {
95       return m_setupReader;
96    }
97
98    /**
99     * Get initial delay from the time when the task is created to the time when
100     * it is first run.
101     *
102     * @return int - value in seconds
103     */

104    public int getStartDelay()
105    {
106       return m_startDelay.intValue();
107    }
108
109    /**
110     * Get value which tells it how often this task should be run.
111     *
112     * @return int - value in seconds
113     */

114    public int getRunEvery()
115    {
116       return m_runEvery.intValue();
117    }
118 }
119
Popular Tags