|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.realtime.AsyncEventHandler
An asynchronous event handler encapsulates code that gets run at some
time after an AsyncEvent
occurs.
It is essentially a Runnable
with a set of parameter objects, making it very much like a
RealtimeThread
. The expectation is that
there may be thousands of events, with corresponding handlers, averaging
about one handler per event. The number of unblocked (i.e., scheduled)
handlers is expected to be relatively small.
It is guaranteed that multiple firings of an event handler will be
serialized. It is also guaranteed that (unless the handler explicitly
chooses otherwise) for each firing of the handler, there will be one
execution of the handleAsyncEvent()
method.
There is no restriction on what handlers may do. They may run for a long or short time, and they may block. (Note: blocked handlers may hold system resources.)
Normally, handlers are bound to an execution context dynamically,
when their AsyncEvent
occurs.
This can introduce a (small) time penalty. For critical handlers that can
not afford the expense, and where this penalty is a problem, use a
BoundAsyncEventHandler
.
Constructor Summary | |
AsyncEventHandler()
Create a handler whose SchedulingParameters are
inherited from the current thread and does not have
either ReleaseParameters or MemoryParameters . |
|
AsyncEventHandler(boolean nonheap)
Create a handler whose parameters are inherited from the current thread, if it is a RealtimeThread ,
or null otherwise. |
|
AsyncEventHandler(boolean nonheap,
java.lang.Runnable logic)
Create a handler whose parameters are inherited from the current thread, if it is a RealtimeThread ,
or null otherwise. |
|
AsyncEventHandler(java.lang.Runnable logic)
Create a handler whose SchedulingParameters are
inherited from the current thread and does not have
either ReleaseParameters or MemoryParameters . |
|
AsyncEventHandler(SchedulingParameters scheduling,
ReleaseParameters release,
MemoryParameters memory,
MemoryArea area,
ProcessingGroupParameters group,
boolean nonheap,
java.lang.Runnable logic)
Create a handler with the specified parameters. |
|
AsyncEventHandler(SchedulingParameters scheduling,
ReleaseParameters release,
MemoryParameters memory,
MemoryArea area,
ProcessingGroupParameters group,
java.lang.Runnable logic)
Create a handler with the specified parameters. |
Method Summary | |
boolean |
addIfFeasible()
add the the feasibility of the already set scheduler if the resulting feasibility set is schedulable. |
boolean |
addToFeasibility()
Inform the scheduler and cooperating facilities that this thread's feasibility parameters should be considered in feasibility analysis until further notified. |
protected int |
getAndClearPendingFireCount()
Atomically set to zero the number of pending executions of this handler and returns the value from before it was cleared. |
protected int |
getAndDecrementPendingFireCount()
Atomically decrements the number of pending executions of this handler (if it was non-zero) and returns the value from before the decrement. |
protected int |
getAndIncrementPendingFireCount()
Atomically increments the number of pending executions of this handler and returns the value from before the increment. |
MemoryArea |
getMemoryArea()
Get the current memory area. |
MemoryParameters |
getMemoryParameters()
Get the memory parameters associated with this handler. |
protected int |
getPendingFireCount()
Return the number of pending executions of this handler |
ProcessingGroupParameters |
getProcessingGroupParameters()
Returns a reference to the ProcessingGroupParameters object. |
ReleaseParameters |
getReleaseParameters()
Get the release parameters associated with this handler. |
Scheduler |
getScheduler()
Return the Scheduler for this handler. |
SchedulingParameters |
getSchedulingParameters()
Returns a reference to the scheduling parameters object. |
void |
handleAsyncEvent()
If this handler was constructed using a seperate Runnable
logic object, then that Runnable object's run
method is called; This method will be invoked repeatedly while
fireCount is greater than zero. |
boolean |
removeFromFeasibility()
Inform the scheduler and cooperating facilities that this thread's feasibility parameters should not be considered in feasibility analysis until further notified. |
void |
run()
Used by the asynchronous event mechanism, see AsyncEvent . |
boolean |
setIfFeasible(ReleaseParameters release,
MemoryParameters memory)
|
boolean |
setIfFeasible(ReleaseParameters release,
MemoryParameters memory,
ProcessingGroupParameters group)
|
boolean |
setIfFeasible(ReleaseParameters release,
ProcessingGroupParameters group)
|
void |
setMemoryParameters(MemoryParameters memory)
Set the memory parameters associated with this handler. |
boolean |
setMemoryParametersIfFeasible(MemoryParameters memory)
Set the MemoryParameters of this schedulable object. |
void |
setProcessingGroupParameters(ProcessingGroupParameters group)
Sets the reference to the ProcessingGroupParameters object. |
boolean |
setProcessingGroupParametersIfFeasible(ProcessingGroupParameters group)
Set the ProcessingGroupParameters of this schedulable object only if the resulting
task set is feasible. |
void |
setReleaseParameters(ReleaseParameters release)
Set the release parameters associated with this handler. |
boolean |
setReleaseParametersIfFeasible(ReleaseParameters release)
Set the ReleaseParameters for this schedulable object only if the resulting
task set is feasible. |
void |
setScheduler(Scheduler scheduler)
Set the scheduler for this handler. |
void |
setScheduler(Scheduler scheduler,
SchedulingParameters scheduling,
ReleaseParameters release,
MemoryParameters memoryParameters,
ProcessingGroupParameters processingGroup)
Set the scheduler for this handler. |
void |
setSchedulingParameters(SchedulingParameters scheduling)
Set the scheduling parameters associated with this handler. |
boolean |
setSchedulingParametersIfFeasible(SchedulingParameters sched)
Set the SchedulingParameters of this scheduable object only if the resulting task
set is feasible. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public AsyncEventHandler()
SchedulingParameters
are
inherited from the current thread and does not have
either ReleaseParameters
or MemoryParameters
.public AsyncEventHandler(java.lang.Runnable logic)
SchedulingParameters
are
inherited from the current thread and does not have
either ReleaseParameters
or MemoryParameters
.logic
- The Runnable
object whose run
is executed by handleAsyncEvent.public AsyncEventHandler(SchedulingParameters scheduling, ReleaseParameters release, MemoryParameters memory, MemoryArea area, ProcessingGroupParameters group, java.lang.Runnable logic)
release
- A ReleaseParameters
object which will be associated with the
constructed instance of this. If null this will have no ReleaseParameters
.scheduling
- A SchedulingParameters
object 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.memory
- A MemoryParameters
object which will be associated with the
constructed instance of this. If null this will have no MemoryParameters
.area
- The MemoryArea
for this. If null the memory area will be that of the
current thread.group
- A ProcessingGroupParameters
object to which this will be associated. If
null this will not be associated with any processing group.logic
- The Runnable
object whose run
is executed by handleAsyncEvent.public AsyncEventHandler(boolean nonheap)
RealtimeThread
,
or null otherwise.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.public AsyncEventHandler(boolean nonheap, java.lang.Runnable logic)
RealtimeThread
,
or null otherwise.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 Runnable
object whose run
is executed by handleAsyncEvent.public AsyncEventHandler(SchedulingParameters scheduling, ReleaseParameters release, MemoryParameters memory, MemoryArea area, ProcessingGroupParameters group, boolean nonheap, java.lang.Runnable logic)
scheduling
- A SchedulingParameters
object 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.release
- A ReleaseParameters
object which will be associated with the
constructed instance of this. If null this will have no ReleaseParameters
.memory
- A MemoryParameters
object which will be associated with the
constructed instance of this. If null this will have no MemoryParameters
.area
- The MemoryArea
for this. Must be a reference to
a ScopedMemory
or ImmortalMemory
object if noheap
is true.group
- 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
.Method Detail |
public void handleAsyncEvent()
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 final int getPendingFireCount()
protected final int getAndClearPendingFireCount()
public void handleAsyncEvent() { int fireCount = getAndClearPendingFireCount(); <handle the events> }
protected int getAndDecrementPendingFireCount()
handleAsyncEvent()
method in this form to handle multiple firings:public void handleAsyncEvent() { <setup> do { <handle the event> } while(getAndDecrementPendingFireCount()>0); }This construction is necessary only in the case where one wishes to avoid the setup costs since the framework guarantees that
handleAsyncEvent()
will be invoked the appropriate number of times.protected int getAndIncrementPendingFireCount()
handleAsyncEvent()
method does not need to do this,
since the surrounding
framework guarantees that the handler will be re-executed the
appropriate number of times. It is only of value when there
is common setup code that is expensive.public final void run()
AsyncEvent
.
This method invokes handleAsyncEvent()
repeatedly while
the fire count is greater than zero. Applications cannot override this
method and should thus override handleAsyncEvent()
in
subclasses with the logic of the handler.public MemoryArea getMemoryArea()
public boolean addToFeasibility()
public boolean addIfFeasible()
public boolean setIfFeasible(ReleaseParameters release, MemoryParameters memory)
public boolean setIfFeasible(ReleaseParameters release, MemoryParameters memory, ProcessingGroupParameters group)
public boolean setReleaseParametersIfFeasible(ReleaseParameters release)
ReleaseParameters
for this schedulable object only if the resulting
task set is feasible.release
- The ReleaseParameters
object. If null nothing happens.public boolean setProcessingGroupParametersIfFeasible(ProcessingGroupParameters group)
ProcessingGroupParameters
of this schedulable object only if the resulting
task set is feasible.groupParameters
- The ProcessingGroupParameters
object.public boolean setIfFeasible(ReleaseParameters release, ProcessingGroupParameters group)
public boolean setMemoryParametersIfFeasible(MemoryParameters memory)
MemoryParameters
of this schedulable object.memory
- The MemoryParameters
object. If null nothing happens.public MemoryParameters getMemoryParameters()
MemoryParameters
object associated with this.public ReleaseParameters getReleaseParameters()
ReleaseParameters
object associated with this.public Scheduler getScheduler()
Scheduler
for this handler.public SchedulingParameters getSchedulingParameters()
SchedulingParameters
object associated with this.public ProcessingGroupParameters getProcessingGroupParameters()
ProcessingGroupParameters
object.public boolean removeFromFeasibility()
public void setMemoryParameters(MemoryParameters memory)
run()
of this handler.memory
- A MemoryParameters
object which will become the MemoryParameters
associated with this after the method call.public void setReleaseParameters(ReleaseParameters release)
run()
of this handler.
Since this affects the constraints expressed in the release parameters of the existing schedulable objects, this may change the feasibility of the current schedule.
parameters
- A ReleaseParameters
object which will become the ReleaseParameters
associated with this after the method call.public void setScheduler(Scheduler scheduler) throws java.lang.IllegalThreadStateException
scheduler
- An instance of Scheduler
(or subclasses) which will manage the
execution of this thread. If scheduler
is null nothing happens.public void setScheduler(Scheduler scheduler, SchedulingParameters scheduling, ReleaseParameters release, MemoryParameters memoryParameters, ProcessingGroupParameters processingGroup) throws java.lang.IllegalThreadStateException
scheduler
- An instance of Scheduler
(or subclasses) which will manage the
execution of this thread. If scheduler
is null nothing happens.public void setSchedulingParameters(SchedulingParameters scheduling)
run()
of this handler.parameters
- A SchedulingParameters
object which will become the SchedulingParameters
object associated with this after the method call.public void setProcessingGroupParameters(ProcessingGroupParameters group)
ProcessingGroupParameters
object.groupParameters
- The ProcessingGroupParameters
object. If null nothing happens.public boolean setSchedulingParametersIfFeasible(SchedulingParameters sched)
SchedulingParameters
of this scheduable object only if the resulting task
set is feasible.scheduling
- The SchedulingParameters
object. If null nothing happens.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |