|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.memphis.ccrg.lida.framework.tasks.TaskManager
public class TaskManager
All tasks in the Agent
system are executed by this class. Controls
the decay of all the FrameworkModule
s in Agent
. Keeps track
of the current tick, the unit of time in the application. Maintains a task
queue where each position represents the time (in ticks) when a task will be
executed. Multiple tasks can be scheduled for the same tick. Uses an
ExecutorService
to obtain the threads to run all the tasks scheduled
in one tick concurrently.
Field Summary | |
---|---|
static int |
DEFAULT_NUMBER_OF_THREADS
Default number of threads in the ExecutorService |
static int |
DEFAULT_TICK_DURATION
Default minimum duration of a tick in real time (ms) |
Constructor Summary | |
---|---|
TaskManager(int tickDuration,
int maxPoolSize)
Constructs a new TaskManager. |
Method Summary | |
---|---|
void |
addFrameworkGuiEventListener(FrameworkGuiEventListener listener)
Must be able to register FrameworkGuiEvent listeners |
void |
addTicksToExecute(long ticks)
Sets a number of ticks to execute when the system is in interval execution mode. |
boolean |
cancelTask(FrameworkTask task)
Cancels the task from the Task Queue. |
static long |
getCurrentTick()
Current tick in the system. |
long |
getEndOfNextInterval()
This attribute is used for interval execution mode. |
int |
getGuiEventsInterval()
|
long |
getMaxTick()
Returns max tick. |
java.util.Map<java.lang.Long,java.util.Set<FrameworkTask>> |
getTaskQueue()
|
int |
getTickDuration()
|
boolean |
isInIntervalMode()
|
boolean |
isTasksPaused()
|
void |
pauseTasks()
Finish the executions of all tasks scheduled for the currentTick and pauses all further tasks executions. |
(package private) void |
reset()
This method clean up the Task Queue and reset to 0 the currentTick and the maxTick. |
void |
resumeTasks()
Resumes the execution of tasks in the queue. |
boolean |
scheduleTask(FrameworkTask task,
long inXTicks)
Schedules the task for execution in currentTick + inXTicks If inXTicks is negative or 0, the task is not scheduled. |
void |
sendEventToGui(FrameworkGuiEvent event)
This is a convenience method to send GUI events to listeners. |
void |
setDecayingModules(java.util.Collection<FrameworkModule> modules)
Set the Collection of modules for decaying. |
void |
setGuiEventsInterval(int i)
Sets guiEventsInterval |
void |
setInIntervalMode(boolean intervalMode)
Sets inIntervalMode. |
void |
setTickDuration(int d)
Sets tickDuration |
void |
stopRunning()
This method stops all tasks executing and prevents further tasks from being executed. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_TICK_DURATION
public static final int DEFAULT_NUMBER_OF_THREADS
ExecutorService
Constructor Detail |
---|
public TaskManager(int tickDuration, int maxPoolSize)
tickDuration
- - length of time of 1 tick in millisecondsmaxPoolSize
- - max number of threads used by the ExecutorServiceMethod Detail |
---|
public static long getCurrentTick()
public long getMaxTick()
public long getEndOfNextInterval()
public void setTickDuration(int d)
d
- the new tick duration, the length of time of 1 tick in
milliseconds. The actual time that the tick unit represents.
In practice tickDuration affects the speed of tasks in the
simulation.public int getTickDuration()
public void setGuiEventsInterval(int i)
i
- set a new guiEventsInterval, the number of ticks between gui
events generated by the TaskManager. Used to refresh the GUI
panels. with 0, no events are generated.public int getGuiEventsInterval()
public boolean isInIntervalMode()
public void setInIntervalMode(boolean intervalMode)
intervalMode
- true to set the system to interval execution mode, false to
exit.public java.util.Map<java.lang.Long,java.util.Set<FrameworkTask>> getTaskQueue()
public boolean isTasksPaused()
public void pauseTasks()
public void resumeTasks()
public boolean cancelTask(FrameworkTask task)
task
- The task to cancel.
public void addTicksToExecute(long ticks)
ticks
- the number of ticks to use as an interval.public boolean scheduleTask(FrameworkTask task, long inXTicks)
task
- the task to scheduleinXTicks
- the number of ticks in the future that the task will be
scheduled for execution.
public void setDecayingModules(java.util.Collection<FrameworkModule> modules)
modules
- a Collection with the FrameworkModulespublic void stopRunning()
public void addFrameworkGuiEventListener(FrameworkGuiEventListener listener)
GuiEventProvider
addFrameworkGuiEventListener
in interface GuiEventProvider
listener
- receiver of GuiEvents, typically a GuiPanelpublic void sendEventToGui(FrameworkGuiEvent event)
GuiEventProvider
sendEventToGui
in interface GuiEventProvider
event
- GuiEventvoid reset()
TaskSpawner
must be reset also. This method is
intended to be used only when the Agent
is reset. Currently used only for testing. To be
implemented in the framework in the future.
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |