- All Implemented Interfaces:
EventListener
,SimulationListener
- Direct Known Subclasses:
SimulationAdapter
Additional simulation packages will generally extend DefaultSimAdapter to add additional events. In these subclasses. additional event types are named by providing an enumeration (OurStateEventType in the example) and by seeing if the event supports that type. If it does not, the processing should be handed to the adapter's superclass:
This design pattern lets each simulation handle events in a type-secure way that is extensible.public void stateChanged(SimulationStateEvent e) { Simulation sim = e.getSimulation)(); OurStateEventType et = e.getType(OurStateEventType.class); if (et == null) { super.stateChanged(e); return; } switch (et) { // handle each case. ... } }
The zero-argument constructor for this class will create an adapter
whose methods (except for stateChanged(SimulationStateEvent)
and the protected method
ScriptListenerAdapter.callScriptMethod(String, Object...)
) can
be overridden to perform some action. The two-argument constructor
allows the implementation of each public method (except, of course,
stateChanged(SimulationStateEvent)
) to be provided using a
scripting language.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bzdev.scripting.ScriptListenerAdapter
ScriptListenerAdapter.ScriptMethodException
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.DefaultSimAdapter
(ScriptingContext context, Object scriptObject) Constructor given a scripting context and script object.DefaultSimAdapter
(ExpressionParser.ESPObject scriptObject) Constructor with only a script object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
callEnd
(Simulation sim, String tag) Indicate that a simulation has finished processing a scheduled call.void
callEndSimObject
(Simulation sim, SimObject obj, String tag) Indicate that a simulation has finished processing a scheduled call associated with a simulation object..void
callStart
(Simulation sim, String tag) Indicate that a simulation has started to process a scheduled call.void
callStartSimObject
(Simulation sim, SimObject obj, String tag) Indicate that a simulation has started to process a scheduled call associated with a simulation object.void
serverCallable
(Simulation sim, ServerQueue q, Object server, String tag) Indicates that a server has completed processing and the Callable that was queued is being processed.void
serverCallableSimObject
(Simulation sim, ServerQueue q, Object server, SimObject target, String tag) Indicate that a server has completed and the Callable (associated with a simulation object) that was queued is being processed.void
serverInteraction
(Simulation sim, ServerQueue q, Object server, String tag) Indicate that one of a server queue's servers is interacting with a request to handle it.void
serverInteractionSimObject
(Simulation sim, ServerQueue q, Object server, SimObject target, String tag) Indicate that one of a server queue's servers is handling a request by interacting with it on behalf of a simulation object.void
serverRunnable
(Simulation sim, ServerQueue q, Object server, String tag) Indicate that a server has completed and the Runnable that was queued is being processed.void
serverRunnableSimObject
(Simulation sim, ServerQueue q, Object server, SimObject target, String tag) Indicate that a server has completed and the Runnable (associated with a simulation object) that was queued is being processed.void
serverSelected
(Simulation sim, ServerQueue q) Indicate that a server queue has selected a server.void
serverTask
(Simulation sim, ServerQueue q, Object server, String tag) Indicate that a server has completed and the task that was queued is continuing to execute.void
serverTaskSimObject
(Simulation sim, ServerQueue q, Object server, SimObject target, String tag) Indicate that a server has completed and the task that was queued and that is associated with a simulation object is continuing to execute.void
Indicate that a simulation has started.void
simulationStop
(Simulation sim) Indicate that a simulation has stopped.void
Process a simulation-state-change event.void
taskEnd
(Simulation sim, String tag) Indicate that a task a simulation is running has ended.void
taskEndSimObject
(Simulation sim, SimObject owner, String tag) Indicate that a task associated with a simulation object has ended.void
taskPause
(Simulation sim, String tag) Indicate that a task a simulation is running has paused.void
taskPauseSimObject
(Simulation sim, SimObject owner, String tag) Indicate that a task associated with a simulation object has paused.void
taskQueuePause
(Simulation sim, TaskQueue q) Indicate that processing of an element on a task queue has paused.void
taskQueueResume
(Simulation sim, TaskQueue q) Indicate that processing of an element on a task queue has resumed.void
taskQueueStart
(Simulation sim, TaskQueue q) Indicate that processing of an element on a task queue has started.void
taskQueueStop
(Simulation sim, TaskQueue q) Indicate that processing of an element on a task queue has ended.void
taskResume
(Simulation sim, String tag) Indicate that a task a simulation is running has resumed.void
taskResumeSimObject
(Simulation sim, SimObject owner, String tag) Indicate that a task associated with a simulation object has resumed.void
taskStart
(Simulation sim, String tag) Indicate that a simulation has started a task.void
taskStartSimObject
(Simulation sim, SimObject owner, String tag) Indicate that a task associated with a simulation object has started.Methods inherited from class org.bzdev.scripting.ScriptListenerAdapter
callScriptMethod
-
Constructor Details
-
DefaultSimAdapter
public DefaultSimAdapter()Constructor. This creates an adapter with no scripting support. -
DefaultSimAdapter
Constructor with only a script object. This creates an adapter for use with the ESP scripting language.Note: This is equivalent to using the constructor
DefaultSimAdapter(ScriptingContext,Object)
with a null first argument.- Parameters:
scriptObject
- the scripting-language object implementing the listener interface for this adapter.
-
DefaultSimAdapter
public DefaultSimAdapter(ScriptingContext context, Object scriptObject) throws IllegalArgumentException Constructor given a scripting context and script object. This constructor implements the adapter using a scripting language provided its arguments are not null. If a method is added to the script object after this constructor is called, that method will be ignored, so all of the methods the adapter implements must be defined by the script object when this constructor is called.If ESP is the scripting language, the context may be null provided that scriptObject is an ESP object. This special case is provided for use with
ObjectNamerLauncher
and the yrunner program.- Parameters:
context
- the scripting context for this adapterscriptObject
- the scripting-language object implementing the listener interface for this adapter.- Throws:
IllegalArgumentException
- the script object was ill formed
-
-
Method Details
-
stateChanged
Process a simulation-state-change event. The implementation dispatches the processing to the other methods in this class, based on the event type. If this method is overridden, the instructions in the class documention forDefaultSimAdapter
must be followed.- Specified by:
stateChanged
in interfaceSimulationListener
- Parameters:
e
- the event
-
simulationStart
Indicate that a simulation has started.- Parameters:
sim
- the simulation
-
simulationStop
Indicate that a simulation has stopped.- Parameters:
sim
- the simulation
-
callStart
Indicate that a simulation has started to process a scheduled call. The call was scheduled using a simulation's methodscheduleCall
,scheduleScript
, orscheduleCallObject
, and is not attributed to any particular simulation object. The argument representing the call must be either a Callable, a string providing a script to execute, or an object in a scripting language with a "call" method that has no arguments.- Parameters:
sim
- the simulationtag
- a description of the event; null if there is none
-
callEnd
Indicate that a simulation has finished processing a scheduled call. The call was scheduled using a simulation's methodscheduleCall
,scheduleScript
, orscheduleCallObject
, and is not attributed to any particular simulation object. The argument representing the call must be either a Callable, a string providing a script to execute, or an object in a scripting language with a "call" method that has no arguments.- Parameters:
sim
- the simulationtag
- a description of the event; null if there is none
-
callStartSimObject
Indicate that a simulation has started to process a scheduled call associated with a simulation object. The call was created using a simulation object's protected method namedcallableScript
,scheduleScript
,scheduleCall
,scheduleCallObject
, orbindCallable
and is attributed to that simulation object.- Parameters:
sim
- the simulationobj
- the simulation objecttag
- a description of the event; null if there is none
-
callEndSimObject
Indicate that a simulation has finished processing a scheduled call associated with a simulation object.. The call was created using a simulation object's protected method namedcallableScript
,scheduleScript
,scheduleCall
,scheduleCallObject
, orbindCallable
and is attributed to that simulation object.- Parameters:
sim
- the simulationobj
- the simulation objecttag
- a description of the event; null if there is none
-
taskStart
Indicate that a simulation has started a task. The task was created by a simulation's public methodscheduleTask
,scheduleTaskScript
,scheduleTaskObject
,scheduleTaskWP
,startImmediateTask
, orunscheduledTaskThread
and is not attributed to any particular simulation object. The argument representing a task must be either a Runnable, a string providing a script to execute, or an object in a scripting language with a "run" method that has no arguments.- Parameters:
sim
- the simulationtag
- a description of the event; null if there is none
-
taskPause
Indicate that a task a simulation is running has paused. The task was created by a simulation's public methodscheduleTask
,scheduleTaskScript
,scheduleTaskObject
,scheduleTaskWP
,startImmediateTask
, orunscheduledTaskThread
and is not attributed to any particular simulation object. The argument representing a task must be either a Runnable, a string providing a script to execute, or an object in a scripting language with a "run" method that has no arguments.- Parameters:
sim
- the simulationtag
- a description of the event; null if there is none
-
taskResume
Indicate that a task a simulation is running has resumed. The task was created by a simulation's public methodscheduleTask
,scheduleTaskScript
,scheduleTaskObject
,scheduleTaskWP
,startImmediateTask
, orunscheduledTaskThread
and is not attributed to any particular simulation object. The argument representing a task must be either a Runnable, a string providing a script to execute, or an object in a scripting language with a "run" method that has no arguments.- Parameters:
sim
- the simulationtag
- a description of the event; null if there is none
-
taskEnd
Indicate that a task a simulation is running has ended. The task was created by a simulation's public methodscheduleTask
,scheduleTaskScript
,scheduleTaskObject
,scheduleTaskWP
,startImmediateTask
, orunscheduledTaskThread
and is not attributed to any particular simulation object. The argument representing a task must be either a Runnable, a string providing a script to execute, or an object in a scripting language with a "run" method that has no arguments.- Parameters:
sim
- the simulationtag
- a description of the event; null if there is none
-
taskStartSimObject
Indicate that a task associated with a simulation object has started. The task was created using a simulation object's protected methodunscheduledTaskThread
,scheduleTask
,scheduleTaskScript
,scheduleTaskObject
startImmediateTask
,runnableScript
,runnableObject
, orbindRunnable
and is attributed to the simulation object.- Parameters:
sim
- the simulationowner
- the simulation objecttag
- a description of the event; null if there is none
-
taskPauseSimObject
Indicate that a task associated with a simulation object has paused. The task was created using a simulation object's protected methodunscheduledTaskThread
,scheduleTask
,scheduleTaskScript
,scheduleTaskObject
startImmediateTask
,runnableScript
,runnableObject
, orbindRunnable
and is attributed to the simulation object.- Parameters:
sim
- the simulationowner
- the simulation objecttag
- a description of the event; null if there is none
-
taskResumeSimObject
Indicate that a task associated with a simulation object has resumed. The task was created using a simulation object's protected methodunscheduledTaskThread
,scheduleTask
,scheduleTaskScript
,scheduleTaskObject
startImmediateTask
,runnableScript
,runnableObject
, orbindRunnable
and is attributed to the simulation object.- Parameters:
sim
- the simulationowner
- the simulation objecttag
- a description of the event; null if there is none
-
taskEndSimObject
Indicate that a task associated with a simulation object has ended. The task was created using a simulation object's protected methodunscheduledTaskThread
,scheduleTask
,scheduleTaskScript
,scheduleTaskObject
startImmediateTask
,runnableScript
,runnableObject
, orbindRunnable
and is attributed to the simulation object.- Parameters:
sim
- the simulationowner
- the simulation objecttag
- a description of the event; null if there is none
-
taskQueueStart
Indicate that processing of an element on a task queue has started. Subsequent calls to other adapter methods may indicate details of that processing.- Parameters:
sim
- the simulationq
- the task queue
-
taskQueuePause
Indicate that processing of an element on a task queue has paused. Subsequent calls to other adapter methods may indicate details of that processing.- Parameters:
sim
- the simulationq
- the task queue
-
taskQueueResume
Indicate that processing of an element on a task queue has resumed. Subsequent calls to other adapter methods may indicate details of that processing.- Parameters:
sim
- the simulationq
- the task queue
-
taskQueueStop
Indicate that processing of an element on a task queue has ended.- Parameters:
sim
- the simulationq
- the task queue
-
serverSelected
Indicate that a server queue has selected a server.- Parameters:
sim
- the simulationq
- the server queue
-
serverInteraction
Indicate that one of a server queue's servers is interacting with a request to handle it. For this method, the task or callable is not associated with a simulation object.- Parameters:
sim
- the simulationq
- the server queueserver
- the server handling the requesttag
- a description of the event; null if there is none
-
serverCallable
Indicates that a server has completed processing and the Callable that was queued is being processed. This callable represents the processing that occurs after the queue is finished with the request. For this method, the callable is not associated with a simulation object.- Parameters:
sim
- the simulationq
- the server queueserver
- the server handling the requesttag
- a description of the event; null if there is none
-
serverRunnable
Indicate that a server has completed and the Runnable that was queued is being processed. This Runnable represents the processing that occurs after the queue is finished with the request. For this method, the task is not associated with a simulation object.- Parameters:
sim
- the simulationq
- the task queueserver
- the server handling the requesttag
- a description of the event; null if there is none
-
serverTask
Indicate that a server has completed and the task that was queued is continuing to execute. For this method, the task is not associated with a simulation object.- Parameters:
sim
- the simulationq
- the task queueserver
- the server handling the requesttag
- a description of the event; null if there is none
-
serverInteractionSimObject
public void serverInteractionSimObject(Simulation sim, ServerQueue q, Object server, SimObject target, String tag) Indicate that one of a server queue's servers is handling a request by interacting with it on behalf of a simulation object. The simulation object's protected method bindCallable or bindRunnable was used to create the Callable or Runnable and associate it with the simulation object, or a thread was created using the simulation object's unscheduledTaskThread or scheduleTask methods.- Parameters:
sim
- the simulationq
- the task queueserver
- the server handling a requesttarget
- the object associated with the Callable, Runnable, or task that was queuedtag
- a description of the event; null if there is none
-
serverCallableSimObject
public void serverCallableSimObject(Simulation sim, ServerQueue q, Object server, SimObject target, String tag) Indicate that a server has completed and the Callable (associated with a simulation object) that was queued is being processed. The simulation object's protected method bindCallable was used to create the Callable and associate it with the simulation object.- Parameters:
sim
- the simulationq
- the task queueserver
- the server handling the requesttarget
- the object associated with the Callable that was queuedtag
- a description of the event; null if there is none
-
serverRunnableSimObject
public void serverRunnableSimObject(Simulation sim, ServerQueue q, Object server, SimObject target, String tag) Indicate that a server has completed and the Runnable (associated with a simulation object) that was queued is being processed. The simulation object's protected method bindRunnable was used to create the Runnable and associate it with the simulation object.- Parameters:
sim
- the simulationq
- the task queueserver
- the server handling the requesttarget
- the object associated with the Runnable or task that was queuedtag
- a description of the event; null if there is none
-
serverTaskSimObject
public void serverTaskSimObject(Simulation sim, ServerQueue q, Object server, SimObject target, String tag) Indicate that a server has completed and the task that was queued and that is associated with a simulation object is continuing to execute. The task was associated with a simulation object when the task was created by creating the task by using one of the simulation object's unscheduledTaskThread or scheduleTask methods.- Parameters:
sim
- the simulationq
- the task queueserver
- the server handling the requesttarget
- the object associated with Runnable or task that was queuedtag
- a description of the event; null if there is none
-