mome
Class Executor

java.lang.Object
  extended by mome.Executor
All Implemented Interfaces:
Runnable

public class Executor
extends Object
implements Runnable

Executor is a class where actual command events dispatching occurs. It encapsulates a thread in which commands processing occurs. The Thread can be started and stopped via start(), stop() respectively. It maintains the command events queue. So any number of commands can be activated while another command is processed. It also maintains a heap of used command events, so new CommandEvent object need not to be created if there is used one.

Version:
1.0
Author:
Sergio Morozov

Nested Class Summary
(package private)  class Executor.CommandEvent
          Command - Source association.
 
Field Summary
static int DEFAULT_COMMAND_EVENTS_HEAP_SIZE
          Default size of CommandEvents heap.
 
Constructor Summary
Executor()
          Instantiates Executor.
Executor(int commandEventsHeapSize)
          Instantiates Executor.
 
Method Summary
protected  Executor.CommandEvent getCommandEvent(Object cmd, Object src)
          Returns CommandEvent instance populated with values.
 XCommandListener getXCommandListener()
          Returns XCommandListener whose xCommanAction method is called for processing commands in execution thread.
 void pushCommand(Object cmd, Object src)
          Pushes command event (command and source) to the commands execution thread.
protected  void releaseCommandEvent(Executor.CommandEvent cmdRec)
          If heap is not full, populates it with specified CommandEvent.
 void run()
          Processes command events serially by dispatching to XCommandListener.xCommandAction(Object, Object).
 void setXCommandListener(XCommandListener commandListener)
          Sets the XCommandListener for processing command events in the commands execution thread.
 void start()
          Starts the execution thread.
 void stop()
          Stops the execution thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COMMAND_EVENTS_HEAP_SIZE

public static final int DEFAULT_COMMAND_EVENTS_HEAP_SIZE
Default size of CommandEvents heap.

Executor class to omit needless creating and garbage-collecting of CommandEvent instances maintains the heap of used CommandEvents

Since:
1.0
See Also:
Constant Field Values
Constructor Detail

Executor

public Executor()
Instantiates Executor.

Since:
1.0

Executor

public Executor(int commandEventsHeapSize)
Instantiates Executor.

Parameters:
commandEventsHeapSize - Size of CommandEvents heap. If commandEventsHeapSize is not positive the default value (8) is used.

Executor class to omit needless creating and garbage-collecting of CommandEvent instances maintains the heap of used CommandEvents. Heap is dynamically populated.

Note This is not a number of commands, that can be simultaneously activated - this number is unlimited.

Note This constructor should be used in extra situations.

Since:
1.0
Method Detail

getCommandEvent

protected Executor.CommandEvent getCommandEvent(Object cmd,
                                                Object src)
Returns CommandEvent instance populated with values. If there is free instance in heap populates it with specified values, else creates new one.

Parameters:
cmd - Object identifying the command.
src - Object on which this event has occurred.
Returns:
CommandEvent encapsulating command and source.
Since:
1.0

releaseCommandEvent

protected void releaseCommandEvent(Executor.CommandEvent cmdRec)
If heap is not full, populates it with specified CommandEvent.

Parameters:
cmdRec - CommandEvent to be saved in heap.
Since:
1.0

pushCommand

public void pushCommand(Object cmd,
                        Object src)
Pushes command event (command and source) to the commands execution thread.

Parameters:
cmd - An object identifying the command.
src - An object on which this event has occurred. Either Displayable or Item or can be used as parameter for any user command.
Since:
1.0

start

public void start()
Starts the execution thread.

Since:
1.0

stop

public void stop()
Stops the execution thread.

Since:
1.0

getXCommandListener

public XCommandListener getXCommandListener()
Returns XCommandListener whose xCommanAction method is called for processing commands in execution thread.

Returns:
- the xCommandListener if there is one, null otherwise.
Since:
1.0

setXCommandListener

public void setXCommandListener(XCommandListener commandListener)
Sets the XCommandListener for processing command events in the commands execution thread.

Parameters:
commandListener - XCommandListener for processing command events
Since:
1.0

run

public void run()
Processes command events serially by dispatching to XCommandListener.xCommandAction(Object, Object).

Specified by:
run in interface Runnable
Since:
1.0
See Also:
Runnable.run()