celeboss.command
Class CommandEngine

java.lang.Object
  extended byceleboss.command.CommandEngine
All Implemented Interfaces:
java.lang.Runnable

public class CommandEngine
extends java.lang.Object
implements java.lang.Runnable

Create a thread class to acts as a Runnable that executes commands in the backgound. It just takes the next elements off the Queue and invokes the refresh action.


Constructor Summary
CommandEngine(java.lang.String name)
          Creates an updater for the Refreshable entities.
 
Method Summary
 void addItem(Command item, java.lang.Object param, int when)
          Adds an items to the refresh queue.
 void addListener(CommandEngineListener listener)
          Add a listener to the engine
 QueueItem getActiveItem()
          Get the item that is active at the moment.
 java.util.List getQueue()
          Get a read-only copy of the queue list.
 boolean isPaused()
          Is the engine paused
 void removeItem(Command command, java.lang.Object param)
          Remote a queued item.
 void removeListener(CommandEngineListener listener)
          Remove a previously registered listener to the engine
 void run()
          Execution of the thread.
 void setPaused(boolean b)
          Set the engine paused.
 void shutdown()
          Stop the update thread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandEngine

public CommandEngine(java.lang.String name)
Creates an updater for the Refreshable entities.

Parameters:
name - Name of engine.
Method Detail

addItem

public void addItem(Command item,
                    java.lang.Object param,
                    int when)
Adds an items to the refresh queue. If this Refreshable is already queued, then the it's update time will be adjusted to be the time specified if it is sooner.

Parameters:
item - Item to refresh.
param - Parameter to pass when the command is invoked.
when - How many seconds befor ethis command shoudl be invoked.

addListener

public void addListener(CommandEngineListener listener)
Add a listener to the engine

Parameters:
listener - Listener to add.

getActiveItem

public QueueItem getActiveItem()
Get the item that is active at the moment.

Returns:
Returns the activeItem.

getQueue

public java.util.List getQueue()
Get a read-only copy of the queue list. This list will be updated as the interla queue is updated, i.e. new item appears in the returned list automatically. This list is read only and no modifications can be made.

Returns:
Read only view on queue.

removeItem

public void removeItem(Command command,
                       java.lang.Object param)
Remote a queued item.

Parameters:
command - Command to remove
param - Optional parameter of the item to remove

removeListener

public void removeListener(CommandEngineListener listener)
Remove a previously registered listener to the engine

Parameters:
listener - Listener to remove.

run

public void run()
Execution of the thread.

Specified by:
run in interface java.lang.Runnable

shutdown

public void shutdown()
Stop the update thread


isPaused

public boolean isPaused()
Is the engine paused

Returns:
Paused state

setPaused

public void setPaused(boolean b)
Set the engine paused.

Parameters:
b - New pause state.