com.newisys.eventsim
Class SimulationManager

java.lang.Object
  extended by com.newisys.eventsim.SimulationManager

public class SimulationManager
extends Object

Manages the creation, scheduling, and synchronization of serialized simulation threads.


Constructor Summary
SimulationManager()
          Constructs a new simulation manager with the default name, random factory, and seed source.
SimulationManager(String name, PRNGFactory defRandomFactory)
          Constructs a new simulation manager with the given name and random factory, and a seed source created from the given factory with seed 0.
SimulationManager(String name, PRNGFactory defRandomFactory, PRNG seedSource)
          Constructs a new simulation manager with the given name, random factory, and seed source.
 
Method Summary
 void executeThreads()
          Executes runnable threads until none remain (i.e.
 SimulationThread[] fork(Runnable... rs)
          Starts a set of new simulation threads with generated names.
 SimulationThread fork(Runnable r)
          Starts a new simulation thread with a generated name.
 SimulationThread fork(String name, Runnable r)
          Starts a new simulation thread with the specified name.
 Thread getManagerThread()
          Returns the thread used to schedule execution of simulation threads managed by this object.
 com.newisys.threadmarshal.ThreadMarshaller getThreadMarshaller()
          Returns the thread marshaller used to allow simulation threads to execute calls from the scheduler thread.
 boolean hasActiveThreads()
          Returns whether this object is currently managing any unterminated threads.
 void notifyOf(Event e)
          Notifies waiting threads that an event has occurred.
 void terminateThreads()
          Terminates all threads currently registered in the simulation.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimulationManager

public SimulationManager()
Constructs a new simulation manager with the default name, random factory, and seed source.


SimulationManager

public SimulationManager(String name,
                         PRNGFactory defRandomFactory)
Constructs a new simulation manager with the given name and random factory, and a seed source created from the given factory with seed 0.

Parameters:
name - the name of this simulation manager (for debugging purposes)
defRandomFactory - the factory used to create random number generators for top-level threads

SimulationManager

public SimulationManager(String name,
                         PRNGFactory defRandomFactory,
                         PRNG seedSource)
Constructs a new simulation manager with the given name, random factory, and seed source.

Parameters:
name - the name of this simulation manager (for debugging purposes)
defRandomFactory - the factory used to create random number generators for top-level threads
seedSource - the random number generator used to seed top-level random number generators
Method Detail

getManagerThread

public Thread getManagerThread()
Returns the thread used to schedule execution of simulation threads managed by this object. This is generally the thread that created the simulation manager.

Returns:
the thread used to schedule execution of simulation threads

getThreadMarshaller

public com.newisys.threadmarshal.ThreadMarshaller getThreadMarshaller()
Returns the thread marshaller used to allow simulation threads to execute calls from the scheduler thread.

Returns:
the thread marshaller for this simulation manager

hasActiveThreads

public final boolean hasActiveThreads()
Returns whether this object is currently managing any unterminated threads.

This method must not be called from a managed simulation thread.

Returns:
true iff there are unterminated threads

executeThreads

public void executeThreads()
                    throws UnhandledExceptionException
Executes runnable threads until none remain (i.e. all threads have blocked or terminated).

This method must be called from the thread that created this simulation manager.

Throws:
UnhandledExceptionException - if a simulation thread is terminated by an unhandled exception

terminateThreads

public final void terminateThreads()
Terminates all threads currently registered in the simulation. This method initiates the termination process for all threads, then waits until all threads have entered the TERMINATED state.

This method may be called from both managed simulation threads and external threads.


fork

public final SimulationThread fork(String name,
                                   Runnable r)
Starts a new simulation thread with the specified name.

This method may be called from both managed simulation threads and external threads.

Parameters:
name - the name of this thread, for debugging purposes
r - the code to run for this thread
Returns:
the SimulationThread object associated with the new thread

fork

public final SimulationThread fork(Runnable r)
Starts a new simulation thread with a generated name.

Parameters:
r - the code to run for this thread
Returns:
the SimulationThread object associated with the new thread

fork

public final SimulationThread[] fork(Runnable... rs)
Starts a set of new simulation threads with generated names.

Parameters:
rs - the code to run for each thread
Returns:
the SimulationThread objects associated with the new threads

notifyOf

public final void notifyOf(Event e)
Notifies waiting threads that an event has occurred.

This method may be called from both managed simulation threads and external threads.

Parameters:
e - the event to notify of

toString

public String toString()
Overrides:
toString in class Object