javax.realtime
Class ThreadedAsyncEventHandler

java.lang.Object
  extended byjavax.realtime.AsyncEventHandler
      extended byjavax.realtime.ThreadedAsyncEventHandler
All Implemented Interfaces:
Runnable, Schedulable

public class ThreadedAsyncEventHandler
extends AsyncEventHandler

This class is one of the different implementation available for the AsyncEventHandler. This specific implementation is not not permanently bound to a thread, but a thread is created on demand each time an event firing has to be handled.

Author:
Angelo Corsaro
See Also:
AsyncEventHandler

Field Summary
protected  int fireCount
           
protected  ProcessingGroupParameters groupParam
           
protected  javax.realtime.ThreadedAsyncEventHandler.HanderLogic handlerLogic
           
protected  Runnable logic
           
protected  MemoryArea memoryArea
           
protected  MemoryParameters memoryParam
           
protected  boolean noHeap
           
protected  ReleaseParameters releaseParam
           
protected  Scheduler scheduler
           
protected  SchedulingParameters schedulingParam
           
 
Fields inherited from class javax.realtime.AsyncEventHandler
executionEligibility, natFireCount_
 
Constructor Summary
ThreadedAsyncEventHandler()
          Creates a new ThreadedAsyncEventHandler instance whose SchedulingParameters are inherited from the current thread and does not have either ReleaseParameters or MemoryParameters.
ThreadedAsyncEventHandler(boolean noHeap)
          Creates a new ThreadedAsyncEventHandler instance whose parameters are inherited from the current thread, if it is a RealtimeThread ,or null other wise.
ThreadedAsyncEventHandler(boolean noHeap, Runnable logic)
          Creates a new ThreadedAsyncEventHandler instance whose parameters are inherited from the current thread, if it is a RealtimeThread, or null otherwise.
ThreadedAsyncEventHandler(Runnable logic)
          Creates a new ThreadedAsyncEventHandler instance whose parameters are inherited from the current thread, if it is a RealtimeThread, or null otherwise.
ThreadedAsyncEventHandler(SchedulingParameters schedulingParam, ReleaseParameters releaseParam, MemoryParameters memoryParam, MemoryArea memoryArea, ProcessingGroupParameters groupParam, boolean noHeap)
          Creates a new ThreadedAsyncEventHandler instance with the specified parameters.
ThreadedAsyncEventHandler(SchedulingParameters schedulingParam, ReleaseParameters releaseParam, MemoryParameters memoryParam, MemoryArea memoryArea, ProcessingGroupParameters groupParam, boolean nonHeap, Runnable logic)
          Creates a new ThreadedAsyncEventHandler instance with the specified parameters.
ThreadedAsyncEventHandler(SchedulingParameters schedulingParam, ReleaseParameters releaseParam, MemoryParameters memoryParam, MemoryArea memoryArea, ProcessingGroupParameters groupParam, Runnable logic)
          Creates a new ThreadedAsyncEventHandler instance with the specified parameters.
 
Method Summary
 boolean addIfFeasible()
          Add to the feasibility of the already set scheduler if the resulting feasibility set is schedulable.
 boolean addToFeasibility()
          Inform the scheduler and cooperating facilities that the resource demands (as expressed in the associated instances of SchedulingParameters, ReleaseParameters, MemoryParameters, and ProcessingGroupParameters) of this instance of Schedulable will be considered in the feasibility analysis of the associated Scheduler until further notice.
 int executionEligibility()
          NOTE: This method is not part of the RTSJ Specification.
 MemoryParameters getMemoryParameters()
          Get the MemoryParameters of this schedulable object.
 ProcessingGroupParameters getProcessingGroupParameters()
          Get the ProcessingGroupParameters of this schedulable object.
 ReleaseParameters getReleaseParameters()
          Get the ReleaseParameters of this schedulable object.
 Scheduler getScheduler()
          Get the Scheduler for this schedulable object.
 SchedulingParameters getSchedulingParameters()
          Get the SchedulingParameters for this schedulable object.
 void handleAsyncEvent()
          If this handler was constructed using a separate Runnable logic object, then that Runnable object s run method is called; This method will be invoked repeatedly while fireCount is greater than zero.
protected  void handleAsyncEventImpl()
           
 boolean removeFromFeasibility()
          Inform the scheduler and cooperating facilities that the resource demands, as expressed in the associated instances of SchedulingParameters, ReleaseParameters, MemoryParameters, and ProcessingGroupParameters, of this instance of Schedulable should no longer be considered in the feasibility analysis of the associated Scheduler.
 void setMemoryParameters(MemoryParameters memoryParam)
          Set the MemoryParameters for this schedulable object.
 boolean setMemoryParametersIfFeasible(MemoryParameters memoryParam)
          Returns true if, after considering the value of the parameter, the task set would still be feasible.
 void setProcessingGroupParameters(ProcessingGroupParameters groupParam)
          Set the ProcessingGroupParameters for this schedulable object.
 boolean setProcessingGroupParametersIfFeasible(ProcessingGroupParameters groupParam)
          Set the ProcessingGroupParameters of this schedulable object only if the resulting task set is feasible.
 void setReleaseParameters(ReleaseParameters releaseParam)
          Set the ReleaseParametersfor this schedulable object.
 boolean setReleaseParametersIfFeasible(ReleaseParameters releaseParam)
          Returns true if, after considering the value of the parameter, the task set would still be feasible.
 void setScheduler(Scheduler scheduler)
          Set the Scheduler for this schedulable object.
 void setScheduler(Scheduler scheduler, SchedulingParameters schedulingParam, ReleaseParameters releaseParam, MemoryParameters memoryParam, ProcessingGroupParameters groupParam)
          Set the Scheduler for this schedulable object.
 void setSchedulingParameters(SchedulingParameters schedulingParam)
          Set the SchedulingParameters for this schedulable object only if the resulting task set is feasible.
 boolean setSchedulingParametersIfFeasible(SchedulingParameters schedulingParam)
          Set the SchedulingParameters for this schedulable object.
 
Methods inherited from class javax.realtime.AsyncEventHandler
finalize, getAndClearPendingFireCount, getAndDecrementPendingFireCount, getAndIncrementPendingFireCount, getPendingFireCount, run
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

memoryParam

protected MemoryParameters memoryParam

releaseParam

protected ReleaseParameters releaseParam

schedulingParam

protected SchedulingParameters schedulingParam

memoryArea

protected MemoryArea memoryArea

groupParam

protected ProcessingGroupParameters groupParam

scheduler

protected Scheduler scheduler

noHeap

protected boolean noHeap

logic

protected Runnable logic

fireCount

protected int fireCount

handlerLogic

protected javax.realtime.ThreadedAsyncEventHandler.HanderLogic handlerLogic
Constructor Detail

ThreadedAsyncEventHandler

public ThreadedAsyncEventHandler()
Creates a new ThreadedAsyncEventHandler instance whose SchedulingParameters are inherited from the current thread and does not have either ReleaseParameters or MemoryParameters.


ThreadedAsyncEventHandler

public ThreadedAsyncEventHandler(boolean noHeap)
Creates a new ThreadedAsyncEventHandler instance whose parameters are inherited from the current thread, if it is a RealtimeThread ,or null other wise.

Parameters:
noHeap - A flag meaning, when true, that this will have characteristics identical to a NoHeapRealtimeThread. A false value means this will have characteristics identical to a RealtimeThread. If true and the current thread is not a NoHeapRealtimeThread or a RealtimeThread executing within a ScopedMemory or ImmortalMemory scope then an IllegalArgumentException is thrown.

ThreadedAsyncEventHandler

public ThreadedAsyncEventHandler(Runnable logic)
Creates a new ThreadedAsyncEventHandler instance whose parameters are inherited from the current thread, if it is a RealtimeThread, or null otherwise.

Parameters:
logic - The java.lang.Runnable object whose run is executed by handleAsyncEvent.

ThreadedAsyncEventHandler

public ThreadedAsyncEventHandler(boolean noHeap,
                                 Runnable logic)
                          throws IllegalArgumentException
Creates a new ThreadedAsyncEventHandler instance whose parameters are inherited from the current thread, if it is a RealtimeThread, or null otherwise.

Parameters:
noHeap - A flag meaning, when true, that this will have characteristics identical to a NoHeapRealtimeThread. A false value means this will have characteristics identical to a RealtimeThread. If true and the current thread is not a NoHeapRealtimeThread or a RealtimeThread executing within a ScopedMemory or ImmortalMemory scope then an IllegalArgumentException is thrown.
logic - -The java.lang.Runnable object whose run is executed by handleAsyncEvent.
Throws:
IllegalArgumentException

ThreadedAsyncEventHandler

public ThreadedAsyncEventHandler(SchedulingParameters schedulingParam,
                                 ReleaseParameters releaseParam,
                                 MemoryParameters memoryParam,
                                 MemoryArea memoryArea,
                                 ProcessingGroupParameters groupParam,
                                 boolean noHeap)
                          throws IllegalArgumentException
Creates a new ThreadedAsyncEventHandler instance with the specified parameters.

Parameters:
schedulingParam - a SchedulingParameters value which will be associated with the constructed instance of this. If null this will be assigned the reference to the SchedulingParameters of the current thread.
releaseParam - a ReleaseParameters value which will be associated with the constructed instance of this. If null this will have no ReleaseParameters.
memoryParam - a MemoryParameters value which will be associated with the constructed instance of this. If null this will have no MemoryParameters.
memoryArea - The MemoryArea for this ThreadedAsyncEventHandler. If null, inherit the current memory area at the time of construction. The initial memory area must be a reference to a ScopedMemory or ImmortalMemory object if noheap is true.
groupParam - A ProcessingGroupParameters object to which this will be associated. If null this will not be associated with any processing group.
noHeap - A flag meaning, when true, that this will have characteristics identical to a NoHeapRealtimeThread. A false value means this will have characteristics identical to a RealtimeThread. If true and the current thread is not a NoHeapRealtimeThread or a RealtimeThread executing within a ScopedMemory or ImmortalMemory scope then an IllegalArgumentException is thrown.
Throws:
IllegalArgumentException

ThreadedAsyncEventHandler

public ThreadedAsyncEventHandler(SchedulingParameters schedulingParam,
                                 ReleaseParameters releaseParam,
                                 MemoryParameters memoryParam,
                                 MemoryArea memoryArea,
                                 ProcessingGroupParameters groupParam,
                                 Runnable logic)
                          throws IllegalArgumentException
Creates a new ThreadedAsyncEventHandler instance with the specified parameters.

Parameters:
schedulingParam - a SchedulingParameters value which will be associated with the constructed instance of this. If null this will be assigned the reference to the SchedulingParameters of the current thread.
releaseParam - a ReleaseParameters value which will be associated with the constructed instance of this. If null this will have no ReleaseParameters.
memoryParam - a MemoryParameters value which will be associated with the constructed instance of this. If null this will have no MemoryParameters.
memoryArea - The MemoryArea for this ThreadedAsyncEventHandler. If null, inherit the current memory area at the time of construction. The initial memory area must be a reference to a ScopedMemory or ImmortalMemory object if noheap is true.
groupParam - A ProcessingGroupParameters object to which this will be associated. If null this will not be associated with any processing group.
logic - The java.lang.Runnable object whose run is executed by handleAsyncEvent.
Throws:
IllegalArgumentException

ThreadedAsyncEventHandler

public ThreadedAsyncEventHandler(SchedulingParameters schedulingParam,
                                 ReleaseParameters releaseParam,
                                 MemoryParameters memoryParam,
                                 MemoryArea memoryArea,
                                 ProcessingGroupParameters groupParam,
                                 boolean nonHeap,
                                 Runnable logic)
                          throws IllegalArgumentException
Creates a new ThreadedAsyncEventHandler instance with the specified parameters.

Parameters:
schedulingParam - a SchedulingParameters value which will be associated with the constructed instance of this. If null this will be assigned the reference to the SchedulingParameters of the current thread.
releaseParam - a ReleaseParameters value which will be associated with the constructed instance of this. If null this will have no ReleaseParameters.
memoryParam - a MemoryParameters value which will be associated with the constructed instance of this. If null this will have no MemoryParameters.
memoryArea - The MemoryArea for this ThreadedAsyncEventHandler. If null, inherit the current memory area at the time of construction. The initial memory area must be a reference to a ScopedMemory or ImmortalMemory object if noheap is true.
groupParam - A ProcessingGroupParameters object to which this will be associated. If null this will not be associated with any processing group.
nonHeap - A flag meaning, when true, that this will have characteristics identical to a NoHeapRealtimeThread. A false value means this will have characteristics identical to a RealtimeThread. If true and the current thread is not a NoHeapRealtimeThread or a RealtimeThread executing within a ScopedMemory or ImmortalMemory scope then an IllegalArgumentException is thrown.
logic - The java.lang.Runnable object whose run is executed by handleAsyncEvent.
Throws:
IllegalArgumentException
Method Detail

handleAsyncEvent

public void handleAsyncEvent()
If this handler was constructed using a separate Runnable logic object, then that Runnable object s run method is called; This method will be invoked repeatedly while fireCount is greater than zero.

Specified by:
handleAsyncEvent in class AsyncEventHandler

handleAsyncEventImpl

protected void handleAsyncEventImpl()

addIfFeasible

public boolean addIfFeasible()
Add to the feasibility of the already set scheduler if the resulting feasibility set is schedulable. If successful return true, if not return false. If there is not an assigned scheduler it will return false.

Returns:
If successful return true, if not return false. If there is not an assigned scheduler it will return false.

addToFeasibility

public boolean addToFeasibility()
Inform the scheduler and cooperating facilities that the resource demands (as expressed in the associated instances of SchedulingParameters, ReleaseParameters, MemoryParameters, and ProcessingGroupParameters) of this instance of Schedulable will be considered in the feasibility analysis of the associated Scheduler until further notice. Whether the resulting system is feasible or not, the addition is completed.

Returns:
true If the resulting system is feasible.

getMemoryParameters

public MemoryParameters getMemoryParameters()
Get the MemoryParameters of this schedulable object.

Returns:
a MemoryParameters value.

setMemoryParameters

public void setMemoryParameters(MemoryParameters memoryParam)
Set the MemoryParameters for this schedulable object.

Parameters:
memoryParam - the MemoryParameters for this schedulable object.

setMemoryParametersIfFeasible

public boolean setMemoryParametersIfFeasible(MemoryParameters memoryParam)
Returns true if, after considering the value of the parameter, the task set would still be feasible. In this case the values of the parameters are changed. Returns false if, after considering the value of the parameter, the task set would not be feasible. In this case the values of the parameters are not changed.

Parameters:
memoryParam - the MemoryParameters for this schedulable object.
Returns:
true if the requested change keeps the system feasible.

getProcessingGroupParameters

public ProcessingGroupParameters getProcessingGroupParameters()
Get the ProcessingGroupParameters of this schedulable object.

Returns:
a ProcessingGroupParameters value

setProcessingGroupParameters

public void setProcessingGroupParameters(ProcessingGroupParameters groupParam)
Set the ProcessingGroupParameters for this schedulable object.

Parameters:
groupParam - a ProcessingGroupParameters value

setProcessingGroupParametersIfFeasible

public boolean setProcessingGroupParametersIfFeasible(ProcessingGroupParameters groupParam)
Set the ProcessingGroupParameters of this schedulable object only if the resulting task set is feasible.

Parameters:
groupParam - a ProcessingGroupParameters value
Returns:
Returns true if, after considering the values of the parameters, the task set would still be feasible. In this case the values of the parameters are changed. Returns false if, after considering the values of the parameters, the task set would not be feasible. In this case the values of the parameters are not changed.

getReleaseParameters

public ReleaseParameters getReleaseParameters()
Get the ReleaseParameters of this schedulable object.

Returns:
a ReleaseParameters value

setReleaseParameters

public void setReleaseParameters(ReleaseParameters releaseParam)
Set the ReleaseParametersfor this schedulable object.

Parameters:
releaseParam - a ReleaseParameters value

setReleaseParametersIfFeasible

public boolean setReleaseParametersIfFeasible(ReleaseParameters releaseParam)
Returns true if, after considering the value of the parameter, the task set would still be feasible. In this case the values of the parameters are changed. Returns false if, after considering the value of the parameter, the task set would not be feasible. In this case the values of the parameters are not changed. the resulting task set is feasible.

Parameters:
releaseParam - a ReleaseParameters value

getScheduler

public Scheduler getScheduler()
Get the Scheduler for this schedulable object.

Returns:
a Scheduler value

setScheduler

public void setScheduler(Scheduler scheduler)
                  throws IllegalThreadStateException
Set the Scheduler for this schedulable object.

Parameters:
scheduler - the scheduler.
Throws:
IllegalThreadStateException

setScheduler

public void setScheduler(Scheduler scheduler,
                         SchedulingParameters schedulingParam,
                         ReleaseParameters releaseParam,
                         MemoryParameters memoryParam,
                         ProcessingGroupParameters groupParam)
                  throws IllegalThreadStateException
Set the Scheduler for this schedulable object.

Parameters:
scheduler - a Scheduler value
schedulingParam - a SchedulingParameters value
releaseParam - a ReleaseParameters value
memoryParam - a MemoryParameters value
groupParam - a ProcessingGroupParameters value
Throws:
IllegalThreadStateException - if an error occurs

getSchedulingParameters

public SchedulingParameters getSchedulingParameters()
Get the SchedulingParameters for this schedulable object.

Returns:
a SchedulingParameters value

setSchedulingParameters

public void setSchedulingParameters(SchedulingParameters schedulingParam)
Set the SchedulingParameters for this schedulable object only if the resulting task set is feasible.

Parameters:
schedulingParam - a SchedulingParameters value

setSchedulingParametersIfFeasible

public boolean setSchedulingParametersIfFeasible(SchedulingParameters schedulingParam)
Set the SchedulingParameters for this schedulable object.

Parameters:
schedulingParam - a SchedulingParameters value
Returns:
true if the change was feasible, false otherwise.

removeFromFeasibility

public boolean removeFromFeasibility()
Inform the scheduler and cooperating facilities that the resource demands, as expressed in the associated instances of SchedulingParameters, ReleaseParameters, MemoryParameters, and ProcessingGroupParameters, of this instance of Schedulable should no longer be considered in the feasibility analysis of the associated Scheduler. Whether the resulting system is feasible or not, the subtrac-tion is completed.

Returns:
true If the resulting system is feasible.

executionEligibility

public int executionEligibility()
Description copied from interface: Schedulable
NOTE: This method is not part of the RTSJ Specification. It is used internally by this RTSJ implementation.

Returns:
an int value used internally to represent a total ordering of the schedulable entities.


jRate is developed and maintained by the jRate project development team.
Copyright (c) 2001-2005 Angelo Corsaro and Morgan Deters.