summaryrefslogtreecommitdiffstats
path: root/EssentialsUpdate/src/f00f/net/irc/martyr/TimerTaskCommand.java
blob: 00ab56f56b398be906328c21e4a87e80f0fa7fb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package f00f.net.irc.martyr;

import java.util.TimerTask;

// TODO: BD: Unit test
// TODO: BD: synchronization semantics?

/**
 * This class delays sending a command to the IRC connection.
 *
 * @author <a href="mailto:martyr@mog.se">Morgan Christiansson</a>
 */
public class TimerTaskCommand extends TimerTask
{

	private IRCConnection _conn;
	private OutCommand _cmd;
	public TimerTaskCommand(IRCConnection conn, OutCommand cmd)
	{
		_conn = conn;
		_cmd = cmd;
	}
	/* (non-Javadoc)
	 * @see java.util.TimerTask#run()
	 */
	public synchronized void run()
	{
		if( !isScheduled )
			return;

		_conn.sendCommand(_cmd);
		isScheduled = false;
	}

	private boolean isScheduled = true;
	
	/* (non-Javadoc)
	 * @see java.util.TimerTask#cancel()
	 */
	public synchronized boolean cancel()
	{
		boolean ret = super.cancel();
		isScheduled = false;
		return ret;
	}

	/**
	 * @return true if the command has yet to run or is running, false
	 * otherwise.
	 */
	public synchronized boolean isScheduled()
	{
		return isScheduled;
	}

}