J-Sim v1.2.1-p7 API

drcl.sim.event
Class SESimulator

java.lang.Object
  extended bydrcl.DrclObj
      extended bydrcl.comp.ForkManager
          extended bydrcl.comp.ACARuntime
              extended bydrcl.sim.event.SESimulator
All Implemented Interfaces:
java.lang.Cloneable, ObjectDuplicable, java.io.Serializable

public class SESimulator
extends ACARuntime

A sequential event simulation engine.

See Also:
SEThread, Serialized Form

Field Summary
static java.lang.String Debug_Q
           
static java.lang.String Debug_RECYCLE
           
static java.lang.String Debug_STATE
           
static java.lang.String Debug_THREAD
           
static java.lang.String Debug_THREAD_STATE
           
protected  long ltime
           
protected  long nEvents
           
protected  long nLags
           
protected  int nthreadsWaiting
           
protected  FIFOQueue qReady
          Used to store tasks.
protected  TreeMapQueue qWaiting
           
protected  boolean rtEnabled
           
protected  long rtTol
           
protected  long startTime
           
static java.lang.String State_RESETTING
          Transitional state to INACTIVE when system is being reset.
static java.lang.String State_SUSPENDING
          Transitional state to SUSPENDED.
protected  java.lang.ThreadGroup threadGroup
           
protected  FIFOQueue threadPool
           
protected  double time
           
protected  int total
           
protected  long totalThreadRequests
           
 
Fields inherited from class drcl.comp.ACARuntime
debug, DEFAULT_RUNTIME, logenabled, name, resetting, state, State_INACTIVE, State_RUNNING, State_SUSPENDED, tf, timeScale, timeScaleReciprocal, tr, vStateListener
 
Fields inherited from class drcl.comp.ForkManager
parent, runtime
 
Constructor Summary
SESimulator()
           
SESimulator(java.lang.String name_)
           
 
Method Summary
 void ___PROFILE___()
           
protected  double _getEventRate(long numArrivals_)
           
protected  double _getTime()
          Asynchronized version of getTime(), for diagnosis.
protected  void _stop(boolean block_)
           
 java.lang.String a_info(boolean listWaitingTasks_)
          Asynchronous version of ACARuntime.diag(boolean).
 java.lang.String a_info(boolean listWaitingTasks_, boolean listReadyTasks_, boolean listWorkingThreads_)
          Asynchronous version of ACARuntime.diag().
protected  void adjustTime()
          Adjust startTime according to wall time and ltime Called when simulation started and resumed.
 void forceReset()
          Forces to reset this runtime.
 double getEfficiencyIndex()
          Returns the efficiency index of thread recycling.
 double getEventEfficiencyIndex(long numberOfArrivalEvents_)
           
 java.lang.Object getEventQueue()
           
 double getEventRate()
          Returns the event processing rate of this runtime.
 long getNumberOfArrivalEvents()
          Returns the number of arrival events.
 int getNumberOfIdleThreads()
          Returns the number of [idle] worker threads in the recycling pool.
 long getNumberOfThreadRequests()
          Returns the number of requests for worker threads.
 int getNumberOfThreadsCreated()
          Returns the number of worker threads being created.
 int getNumberOfWorkingThreads()
          Returns the number of worker threads that are currently executing some tasks.
 long getNumLaggingEvents()
           
 Queue getQ()
           
 double getRTEvaluation()
          Returns the percentage where events are processed in real time (within tolerance specified by setRTTolerance() (not implemented).
 long getRTTolerance()
           
 java.lang.ThreadGroup getThreadGroup()
           
 double getThreadRequestRate()
           
 long getWallTimeElapsed()
          Returns the actual time (in ms) this runtime has run for.
 SEThread getWorkingThread(int index_)
          Returns the worker thread, for diagnosis
protected  SEThread[] getWorkingThreads()
           
protected  SEThread grabOne()
          Grabs a SEThread from recycling pool, creates one if necessary.
 java.lang.String info()
          Returns general information of this runtime.
 boolean isIdle()
          Returns true if the runtime is stopped (inactive or suspended) or running but all working threads are waiting.
 boolean isResetting()
          Returns true if the runtime is in resetting.
 boolean isRTEnabled()
           
 void listThreads()
           
protected  void newTask(Task task_, WorkerThread currentThread_)
          The only way to trigger new tasks to be executed.
protected  SEThread newThread()
          For subclasses to provide its own worker thread class.
protected  void off(ACATimer handle_)
          Cancels a fork event.
 void print(java.lang.String which_, SEThread current_, java.lang.String msg_)
           
 void println(java.lang.String which_, SEThread current_, java.lang.String msg_)
           
 java.lang.String q_info(java.lang.String prefix_, boolean listElement_)
          Returns information of the event queue.
protected  void recordTime()
           
protected  void recycle(SEThread thread_)
          Used by SEThread to return itself to the pool.
 void reset()
          The workerpool enters a transitional period when reset() is issued.
 void resume()
          Resumes the system.
 java.lang.String s_info()
          Returns statistics of this runtime.
 java.lang.String s_info(boolean listWaitingTasks_)
          Returns statistics of this runtime.
 void setRTEnabled(boolean value_)
          Can only be set when INACTIVE (not implemented).
 void setRTTolerance(long v_)
           
protected  void setState(java.lang.String new_)
           
 java.lang.String ss_info()
          Synchronized version of s_info().
 java.lang.String sthreads()
           
 java.lang.String swthreads()
          Synchronized version of wthreads().
 java.lang.String t_info()
           
protected  java.lang.String t_info(java.lang.String prefix_)
           
 java.lang.String tasks()
          Returns information of the task queue.
protected  void threadBecomesWaiting(SEThread exe_)
           
protected  boolean threadRequestsSleeping(SEThread exe_, double time_)
          Subclasses should override this method to handle the event when a workerthread requests to become waiting.
 java.lang.String threads()
          Returns information of the associate thread group.
protected  void threadStateChange(SEThread thread_, java.lang.String oldState_, java.lang.String newState_)
           
 java.lang.String wthreads()
          Returns information of working threads.
 
Methods inherited from class drcl.comp.ACARuntime
_openlog, a_info, addDebugLevel, addRunnable, addRunnable, addRunnableAt, addRunnableAt, addStateListener, childManager, containsDebugLevel, debug_info, diag, diag, finalized, getAllDebugLevels, getAllStateListeners, getName, getParent, getState, getThread, getTime, getTimeScale, isDebugEnabled, isDebugEnabledAt, isRunning, isStopped, isSuspended, notifyStateListeners, process, reboot, receive, receiveAt, removeDebugLevel, removeStateListener, resumeFor, resumeTo, send, sendAt, setDebugEnabled, setDebugEnabledAt, setDebugLevels, setMaxWorkforce, setName, setParent, setRuntime, setTimeScale, stop, stop, stopAt, takeover, takeover, toString, tr_info
 
Methods inherited from class drcl.comp.ForkManager
a_list, getRuntime, info, list, takeover
 
Methods inherited from class drcl.DrclObj
clone, duplicate
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

Debug_THREAD

public static final java.lang.String Debug_THREAD
See Also:
Constant Field Values

Debug_THREAD_STATE

public static final java.lang.String Debug_THREAD_STATE
See Also:
Constant Field Values

Debug_Q

public static final java.lang.String Debug_Q
See Also:
Constant Field Values

Debug_RECYCLE

public static final java.lang.String Debug_RECYCLE
See Also:
Constant Field Values

Debug_STATE

public static final java.lang.String Debug_STATE
See Also:
Constant Field Values

State_SUSPENDING

public static final java.lang.String State_SUSPENDING
Transitional state to SUSPENDED.

See Also:
Constant Field Values

State_RESETTING

public static final java.lang.String State_RESETTING
Transitional state to INACTIVE when system is being reset.

See Also:
Constant Field Values

threadPool

protected FIFOQueue threadPool

total

protected int total

totalThreadRequests

protected long totalThreadRequests

startTime

protected long startTime

ltime

protected long ltime

time

protected double time

threadGroup

protected java.lang.ThreadGroup threadGroup

qReady

protected FIFOQueue qReady
Used to store tasks.


qWaiting

protected TreeMapQueue qWaiting

nthreadsWaiting

protected int nthreadsWaiting

rtEnabled

protected boolean rtEnabled

nLags

protected long nLags

nEvents

protected long nEvents

rtTol

protected long rtTol
Constructor Detail

SESimulator

public SESimulator()

SESimulator

public SESimulator(java.lang.String name_)
Method Detail

newTask

protected void newTask(Task task_,
                       WorkerThread currentThread_)
The only way to trigger new tasks to be executed.

Specified by:
newTask in class ACARuntime

getThreadGroup

public java.lang.ThreadGroup getThreadGroup()

listThreads

public void listThreads()

info

public java.lang.String info()
Returns general information of this runtime.

Specified by:
info in class ACARuntime

ss_info

public java.lang.String ss_info()
Synchronized version of s_info().


s_info

public java.lang.String s_info()
Returns statistics of this runtime.


s_info

public java.lang.String s_info(boolean listWaitingTasks_)
Returns statistics of this runtime.


a_info

public java.lang.String a_info(boolean listWaitingTasks_)
Description copied from class: ACARuntime
Asynchronous version of ACARuntime.diag(boolean).

Specified by:
a_info in class ACARuntime

a_info

public java.lang.String a_info(boolean listWaitingTasks_,
                               boolean listReadyTasks_,
                               boolean listWorkingThreads_)
Asynchronous version of ACARuntime.diag().


sthreads

public java.lang.String sthreads()

threads

public java.lang.String threads()
Returns information of the associate thread group.


swthreads

public java.lang.String swthreads()
Synchronized version of wthreads().


wthreads

public java.lang.String wthreads()
Returns information of working threads.


tasks

public java.lang.String tasks()
Returns information of the task queue.


grabOne

protected SEThread grabOne()
Grabs a SEThread from recycling pool, creates one if necessary.


newThread

protected SEThread newThread()
For subclasses to provide its own worker thread class.


recycle

protected void recycle(SEThread thread_)
Used by SEThread to return itself to the pool.


forceReset

public void forceReset()
Forces to reset this runtime.


getWorkingThread

public SEThread getWorkingThread(int index_)
Returns the worker thread, for diagnosis


___PROFILE___

public void ___PROFILE___()

getNumberOfThreadsCreated

public int getNumberOfThreadsCreated()
Returns the number of worker threads being created.


getNumberOfIdleThreads

public int getNumberOfIdleThreads()
Returns the number of [idle] worker threads in the recycling pool.


getNumberOfThreadRequests

public long getNumberOfThreadRequests()
Returns the number of requests for worker threads.


getNumberOfArrivalEvents

public long getNumberOfArrivalEvents()
Returns the number of arrival events.

Specified by:
getNumberOfArrivalEvents in class ACARuntime

getEfficiencyIndex

public double getEfficiencyIndex()
Returns the efficiency index of thread recycling. Calculated by getNumberOfThreadRequests() over getNumberOfThreadsCreated().


getEventEfficiencyIndex

public double getEventEfficiencyIndex(long numberOfArrivalEvents_)

getNumberOfWorkingThreads

public int getNumberOfWorkingThreads()
Returns the number of worker threads that are currently executing some tasks.


getEventRate

public double getEventRate()
Returns the event processing rate of this runtime.

Specified by:
getEventRate in class ACARuntime

_getEventRate

protected double _getEventRate(long numArrivals_)

getThreadRequestRate

public double getThreadRequestRate()

getWorkingThreads

protected SEThread[] getWorkingThreads()

_getTime

protected double _getTime()
Asynchronized version of getTime(), for diagnosis. Subclasses should override this method to provide its own time mapping function.

Specified by:
_getTime in class ACARuntime

adjustTime

protected void adjustTime()
Adjust startTime according to wall time and ltime Called when simulation started and resumed.


recordTime

protected void recordTime()

_stop

protected void _stop(boolean block_)
Specified by:
_stop in class ACARuntime

resume

public void resume()
Resumes the system. The state must advance to RUNNING when this method returns.

Specified by:
resume in class ACARuntime

reset

public void reset()
The workerpool enters a transitional period when reset() is issued. It waits for all the working thread to either finishes the job or goes into sleep. After all the threads finish jobs, it releases all the threads by kill()ing them.

CAUTION: 1. This method is better be executed by a thread that is not created from this worker pool, unless you know what you're doing. 2. Current implementation does not work if a thread executes indefinitely.

Specified by:
reset in class ACARuntime

getWallTimeElapsed

public long getWallTimeElapsed()
Returns the actual time (in ms) this runtime has run for.

Specified by:
getWallTimeElapsed in class ACARuntime

t_info

public java.lang.String t_info()
Overrides:
t_info in class ACARuntime

t_info

protected java.lang.String t_info(java.lang.String prefix_)
Specified by:
t_info in class ACARuntime

setState

protected void setState(java.lang.String new_)
Overrides:
setState in class ACARuntime

isResetting

public boolean isResetting()
Returns true if the runtime is in resetting.


isIdle

public boolean isIdle()
Returns true if the runtime is stopped (inactive or suspended) or running but all working threads are waiting.

Overrides:
isIdle in class ACARuntime

threadStateChange

protected void threadStateChange(SEThread thread_,
                                 java.lang.String oldState_,
                                 java.lang.String newState_)

print

public void print(java.lang.String which_,
                  SEThread current_,
                  java.lang.String msg_)

println

public void println(java.lang.String which_,
                    SEThread current_,
                    java.lang.String msg_)

setRTEnabled

public void setRTEnabled(boolean value_)
Can only be set when INACTIVE (not implemented).


isRTEnabled

public boolean isRTEnabled()

getNumLaggingEvents

public long getNumLaggingEvents()

getRTEvaluation

public double getRTEvaluation()
Returns the percentage where events are processed in real time (within tolerance specified by setRTTolerance() (not implemented).


setRTTolerance

public void setRTTolerance(long v_)

getRTTolerance

public long getRTTolerance()

getQ

public Queue getQ()

getEventQueue

public java.lang.Object getEventQueue()
Specified by:
getEventQueue in class ACARuntime

threadBecomesWaiting

protected void threadBecomesWaiting(SEThread exe_)

threadRequestsSleeping

protected boolean threadRequestsSleeping(SEThread exe_,
                                         double time_)
Subclasses should override this method to handle the event when a workerthread requests to become waiting.

Returns:
false if current thread should continue execution (the request is rejected).

q_info

public java.lang.String q_info(java.lang.String prefix_,
                               boolean listElement_)
Returns information of the event queue.


off

protected void off(ACATimer handle_)
Cancels a fork event.

Specified by:
off in class ACARuntime

J-Sim v1.2.1-p7 API

Copyright © 1998-2003 Distributed Real-time Computing Lab (DRCL). All Rights Reserved.     ~ To J-Sim Home ~