Class DefaultSimAdapter

java.lang.Object
org.bzdev.scripting.ScriptListenerAdapter
org.bzdev.devqsim.DefaultSimAdapter
All Implemented Interfaces:
EventListener, SimulationListener
Direct Known Subclasses:
SimulationAdapter

public class DefaultSimAdapter extends ScriptListenerAdapter implements SimulationListener
Default adapter for simulation listeners. This class will typically be overridden by a subclass to implement methods other than stateChanged. With the exception of the stateChanged methods, the remaining methods do nothing.

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:

     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.
           ...
        }
     }
  
This design pattern lets each simulation handle events in a type-secure way that is extensible.

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.

  • Constructor Details

    • DefaultSimAdapter

      public DefaultSimAdapter()
      Constructor. This creates an adapter with no scripting support.
    • DefaultSimAdapter

      public DefaultSimAdapter(ExpressionParser.ESPObject scriptObject)
      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 adapter
      scriptObject - the scripting-language object implementing the listener interface for this adapter.
      Throws:
      IllegalArgumentException - the script object was ill formed
  • Method Details

    • stateChanged

      public void stateChanged(SimulationStateEvent e)
      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 for DefaultSimAdapter must be followed.
      Specified by:
      stateChanged in interface SimulationListener
      Parameters:
      e - the event
    • simulationStart

      public void simulationStart(Simulation sim)
      Indicate that a simulation has started.
      Parameters:
      sim - the simulation
    • simulationStop

      public void simulationStop(Simulation sim)
      Indicate that a simulation has stopped.
      Parameters:
      sim - the simulation
    • callStart

      public void callStart(Simulation sim, String tag)
      Indicate that a simulation has started to process a scheduled call. The call was scheduled using a simulation's method scheduleCall, scheduleScript, or scheduleCallObject, 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 simulation
      tag - a description of the event; null if there is none
    • callEnd

      public void callEnd(Simulation sim, String tag)
      Indicate that a simulation has finished processing a scheduled call. The call was scheduled using a simulation's method scheduleCall, scheduleScript, or scheduleCallObject, 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 simulation
      tag - a description of the event; null if there is none
    • callStartSimObject

      public void callStartSimObject(Simulation sim, SimObject obj, String tag)
      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 named callableScript, scheduleScript, scheduleCall, scheduleCallObject, or bindCallable and is attributed to that simulation object.
      Parameters:
      sim - the simulation
      obj - the simulation object
      tag - a description of the event; null if there is none
    • callEndSimObject

      public void callEndSimObject(Simulation sim, SimObject obj, String tag)
      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 named callableScript, scheduleScript, scheduleCall, scheduleCallObject, or bindCallable and is attributed to that simulation object.
      Parameters:
      sim - the simulation
      obj - the simulation object
      tag - a description of the event; null if there is none
    • taskStart

      public void taskStart(Simulation sim, String tag)
      Indicate that a simulation has started a task. The task was created by a simulation's public method scheduleTask, scheduleTaskScript, scheduleTaskObject, scheduleTaskWP, startImmediateTask, or unscheduledTaskThread 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 simulation
      tag - a description of the event; null if there is none
    • taskPause

      public void taskPause(Simulation sim, String tag)
      Indicate that a task a simulation is running has paused. The task was created by a simulation's public method scheduleTask, scheduleTaskScript, scheduleTaskObject, scheduleTaskWP, startImmediateTask, or unscheduledTaskThread 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 simulation
      tag - a description of the event; null if there is none
    • taskResume

      public void taskResume(Simulation sim, String tag)
      Indicate that a task a simulation is running has resumed. The task was created by a simulation's public method scheduleTask, scheduleTaskScript, scheduleTaskObject, scheduleTaskWP, startImmediateTask, or unscheduledTaskThread 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 simulation
      tag - a description of the event; null if there is none
    • taskEnd

      public void taskEnd(Simulation sim, String tag)
      Indicate that a task a simulation is running has ended. The task was created by a simulation's public method scheduleTask, scheduleTaskScript, scheduleTaskObject, scheduleTaskWP, startImmediateTask, or unscheduledTaskThread 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 simulation
      tag - a description of the event; null if there is none
    • taskStartSimObject

      public void taskStartSimObject(Simulation sim, SimObject owner, String tag)
      Indicate that a task associated with a simulation object has started. The task was created using a simulation object's protected method unscheduledTaskThread, scheduleTask, scheduleTaskScript, scheduleTaskObject startImmediateTask, runnableScript, runnableObject, or bindRunnable and is attributed to the simulation object.
      Parameters:
      sim - the simulation
      owner - the simulation object
      tag - a description of the event; null if there is none
    • taskPauseSimObject

      public void taskPauseSimObject(Simulation sim, SimObject owner, String tag)
      Indicate that a task associated with a simulation object has paused. The task was created using a simulation object's protected method unscheduledTaskThread, scheduleTask, scheduleTaskScript, scheduleTaskObject startImmediateTask, runnableScript, runnableObject, or bindRunnable and is attributed to the simulation object.
      Parameters:
      sim - the simulation
      owner - the simulation object
      tag - a description of the event; null if there is none
    • taskResumeSimObject

      public void taskResumeSimObject(Simulation sim, SimObject owner, String tag)
      Indicate that a task associated with a simulation object has resumed. The task was created using a simulation object's protected method unscheduledTaskThread, scheduleTask, scheduleTaskScript, scheduleTaskObject startImmediateTask, runnableScript, runnableObject, or bindRunnable and is attributed to the simulation object.
      Parameters:
      sim - the simulation
      owner - the simulation object
      tag - a description of the event; null if there is none
    • taskEndSimObject

      public void taskEndSimObject(Simulation sim, SimObject owner, String tag)
      Indicate that a task associated with a simulation object has ended. The task was created using a simulation object's protected method unscheduledTaskThread, scheduleTask, scheduleTaskScript, scheduleTaskObject startImmediateTask, runnableScript, runnableObject, or bindRunnable and is attributed to the simulation object.
      Parameters:
      sim - the simulation
      owner - the simulation object
      tag - a description of the event; null if there is none
    • taskQueueStart

      public void taskQueueStart(Simulation sim, TaskQueue q)
      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 simulation
      q - the task queue
    • taskQueuePause

      public void taskQueuePause(Simulation sim, TaskQueue q)
      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 simulation
      q - the task queue
    • taskQueueResume

      public void taskQueueResume(Simulation sim, TaskQueue q)
      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 simulation
      q - the task queue
    • taskQueueStop

      public void taskQueueStop(Simulation sim, TaskQueue q)
      Indicate that processing of an element on a task queue has ended.
      Parameters:
      sim - the simulation
      q - the task queue
    • serverSelected

      public void serverSelected(Simulation sim, ServerQueue q)
      Indicate that a server queue has selected a server.
      Parameters:
      sim - the simulation
      q - the server queue
    • serverInteraction

      public 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. For this method, the task or callable is not associated with a simulation object.
      Parameters:
      sim - the simulation
      q - the server queue
      server - the server handling the request
      tag - a description of the event; null if there is none
    • serverCallable

      public 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. 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 simulation
      q - the server queue
      server - the server handling the request
      tag - a description of the event; null if there is none
    • serverRunnable

      public 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. 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 simulation
      q - the task queue
      server - the server handling the request
      tag - a description of the event; null if there is none
    • serverTask

      public 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. For this method, the task is not associated with a simulation object.
      Parameters:
      sim - the simulation
      q - the task queue
      server - the server handling the request
      tag - 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 simulation
      q - the task queue
      server - the server handling a request
      target - the object associated with the Callable, Runnable, or task that was queued
      tag - 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 simulation
      q - the task queue
      server - the server handling the request
      target - the object associated with the Callable that was queued
      tag - 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 simulation
      q - the task queue
      server - the server handling the request
      target - the object associated with the Runnable or task that was queued
      tag - 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 simulation
      q - the task queue
      server - the server handling the request
      target - the object associated with Runnable or task that was queued
      tag - a description of the event; null if there is none