View Javadoc

1   /*
2    * Copyright (c) 2003-2008 by Cosylab d. d.
3    *
4    * This file is part of Java-Common.
5    *
6    * Java-Common is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * Java-Common is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with Java-Common.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package com.cosylab.util;
21  
22  /**
23   * This is a convenience implementation of <code>SchedulerTask</code>
24   * interface.
25   *
26   * @author <a href="mailto:ales.pucelj@cosylab.com">Ales Pucelj</a>
27   * @version $id$
28   */
29  public abstract class AbstractSchedulerTask implements SchedulerTask
30  {
31  	/** Flag indicating if this task is scheduled to be canceled. */
32  	private boolean canceled;
33  
34  	/** Interval between executions. */
35  	private long interval;
36  
37  	/** Name of this task, can be null. */
38  	private String name;
39  
40  	/**
41  	 * Creates a new AbstractSchedulerTask object.
42  	 *
43  	 * @param taskName DOCUMENT ME!
44  	 * @param taskInterval DOCUMENT ME!
45  	 */
46  	public AbstractSchedulerTask(String taskName, long taskInterval)
47  	{
48  		name = taskName;
49  		interval = taskInterval;
50  	}
51  
52  	/**
53  	 * Mark this task to be canceled.
54  	 *
55  	 * @see com.cosylab.util.SchedulerTask#cancel()
56  	 */
57  	public void cancel()
58  	{
59  		canceled = true;
60  	}
61  
62  	/**
63  	 * Returns whether <code>cancel()</code> has been called.
64  	 *
65  	 * @see com.cosylab.util.SchedulerTask#isCanceled()
66  	 */
67  	public boolean isCanceled()
68  	{
69  		return canceled;
70  	}
71  
72  	/**
73  	 * Set new name for this task.
74  	 *
75  	 * @param taskName Name of task.
76  	 */
77  	public void setTaskName(String taskName)
78  	{
79  		name = taskName;
80  	}
81  
82  	/**
83  	 * @see com.cosylab.util.SchedulerTask#getTaskName()
84  	 */
85  	public String getTaskName()
86  	{
87  		return name;
88  	}
89  
90  	/**
91  	 * Returns interval between executions. If negative, indicates this task
92  	 * should execute immediatelly.
93  	 *
94  	 * @see com.cosylab.util.SchedulerTask#getInterval()
95  	 */
96  	public long getInterval()
97  	{
98  		return interval;
99  	}
100 }
101 
102 /* __oOo__ */