juife
v0.1a

net.sf.juife
Class TaskQueue

java.lang.Object
  extended by net.sf.juife.TaskQueue

public class TaskQueue
extends java.lang.Object

The TaskQueue class represents a queue that holds tasks which are executed in FIFO order. Note that the tasks are removed from the queue before their execution.


Constructor Summary
TaskQueue()
          Creates a new instance of TaskQueue.
TaskQueue(java.lang.String name)
          Creates a new instance of TaskQueue with the specified name.
TaskQueue(java.lang.String name, Task... tasks)
          Creates a new instance of TaskQueue with the specified name and adds the specified tasks to the queue.
TaskQueue(Task... tasks)
          Creates a new instance of TaskQueue and adds the specified tasks to the queue.
 
Method Summary
 void add(Task task)
          Adds the specified task to the queue.
 void addTaskQueueListener(TaskQueueListener l)
          Registers the specified listener for receiving event messages.
 void cancel()
          Stops the task queue and cancels the execution of all pending tasks.
 java.lang.String getName()
          Gets the name of this task queue.
 int getPendingTaskCount()
          Gets the number of pending tasks.
 Task[] getPendingTasks()
          Gets a list of all tasks in the queue pending for execution.
 Task getRunningTask()
          Gets the currently running task.
 boolean isCancelled()
          Determines whether the task queue is cancelled.
 boolean isEmpty()
          Determines whether the task queue is empty.
 boolean isIdle()
          Determines whether the queue is in idle state.
 boolean isRunning()
          Determines whether this task queue is running.
 boolean isStarted()
          Determines whether this task queue has been started.
 boolean isStopped()
          Determines whether this task queue is stopped.
 void removePendingTasks()
          Removes all pending tasks.
 void removeTaskQueueListener(TaskQueueListener l)
          Removes the specified listener.
 void start()
          Starts the processing of tasks in the queue.
 void stop()
          Stops the task queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskQueue

public TaskQueue()
Creates a new instance of TaskQueue.


TaskQueue

public TaskQueue(java.lang.String name)
Creates a new instance of TaskQueue with the specified name.

Parameters:
name - The name of this task queue.

TaskQueue

public TaskQueue(Task... tasks)
Creates a new instance of TaskQueue and adds the specified tasks to the queue.

Parameters:
tasks - The tasks to be added.

TaskQueue

public TaskQueue(java.lang.String name,
                 Task... tasks)
Creates a new instance of TaskQueue with the specified name and adds the specified tasks to the queue.

Parameters:
name - The name of this task queue.
tasks - The tasks to be added.
Method Detail

getName

public java.lang.String getName()
Gets the name of this task queue.

Returns:
The name of this task queue.

add

public void add(Task task)
Adds the specified task to the queue. Note that once the queue is started this method throws an exception if the queue is not running.

Parameters:
task - The task to be added.
Throws:
java.lang.IllegalStateException - If the queue is not running.

start

public void start()
Starts the processing of tasks in the queue.

Throws:
java.lang.IllegalStateException - If the queue is already running.

isStarted

public boolean isStarted()
Determines whether this task queue has been started. Note that once the queue is started this method returns true even if the queue is not running.

Returns:
true if the task queue has been started, false otherwise.
See Also:
isRunning(), isStopped()

cancel

public void cancel()
Stops the task queue and cancels the execution of all pending tasks. Note that this method does not remove the pending tasks from the queue.

See Also:
removePendingTasks(), stop

isCancelled

public boolean isCancelled()
Determines whether the task queue is cancelled.

Returns:
true if the task queue is cancelled, false otherwise.

stop

public void stop()
Stops the task queue. Note that the already queued tasks will be processed. Use isIdle() method to determine whether all tasks in the queue are processed.

See Also:
cancel

isStopped

public boolean isStopped()
Determines whether this task queue is stopped.

Returns:
true if the task queue is stopped, false otherwise.

isRunning

public boolean isRunning()
Determines whether this task queue is running. The task queue is running if it has been started and is not stopped at this moment.

Returns:
true if the task queue is running, false otherwise.

isEmpty

public boolean isEmpty()
Determines whether the task queue is empty. Note that the tasks are removed from the queue before their execution. This means that we still may have a running task even if the queue is empty. In other words, if the queue is empty doesn't mean that there is no running task at that moment.

Returns:
true if the queue is empty, false otherwise.
See Also:
isIdle(), getRunningTask()

isIdle

public boolean isIdle()
Determines whether the queue is in idle state. Idle state means that the queue is empty and there is no running task.

Returns:
true if the queue is in idle state, false otherwise.

getPendingTaskCount

public int getPendingTaskCount()
Gets the number of pending tasks.

Returns:
The number of pending tasks.

getPendingTasks

public Task[] getPendingTasks()
Gets a list of all tasks in the queue pending for execution.

Returns:
An array containing all tasks pending for execution.

getRunningTask

public Task getRunningTask()
Gets the currently running task.

Returns:
The task that is currently running or null if there is no running task at this moment.

removePendingTasks

public void removePendingTasks()
Removes all pending tasks.


addTaskQueueListener

public void addTaskQueueListener(TaskQueueListener l)
Registers the specified listener for receiving event messages.

Parameters:
l - The TaskListener to register.

removeTaskQueueListener

public void removeTaskQueueListener(TaskQueueListener l)
Removes the specified listener.

Parameters:
l - The TaskQueueListener to remove.

juife
v0.1a

Copyright © 2005 Grigor Iliev. All rights reserved. SourceForge.net Logo