org.jactr.core.buffer.delegate
Class AsynchronousRequestDelegate
java.lang.Object
org.jactr.core.buffer.delegate.AsynchronousRequestDelegate
- All Implemented Interfaces:
- IRequestDelegate
- Direct Known Subclasses:
- AbstractRequestDelegate, AddChunkRequestDelegate, AddChunkTypeRequestDelegate, ImaginalSlotRequestDelegate, OldAsynchronousRequestDelegate, RetrievalRequestDelegate
public abstract class AsynchronousRequestDelegate
- extends java.lang.Object
- implements IRequestDelegate
abstract request delegate that splits requests into two part process
startRequest(IRequest, IActivationBuffer, double) and
finishRequest(IRequest, IActivationBuffer, Object). This makes it
easier to implement asynchronous requests that start a computation and then
later harvest the results.
To make derived classes asynchronous, merely override
isAsynchronous() to return true, and use
computeCompletionTime(double, IRequest, IActivationBuffer) to return
when the system should call
finishRequest(IRequest, IActivationBuffer, Object).
If finishRequest(IRequest, IActivationBuffer, Object) requires some
value from startRequest(IRequest, IActivationBuffer, double) they both have
an object that can be passed from one to the other.
The asynchrony is implemented by calling
startRequest(IRequest, IActivationBuffer, double) and then queueing up a
ITimedEvent that will fire at
computeCompletionTime(double, IRequest, IActivationBuffer) which
will then call finishRequest(IRequest, IActivationBuffer, Object).
You can also configure the delegate to use blocking timed events to ensure
that the model clock does not advance beyond the harvest time (instead of relying
upon some blocking mechanism in finishRequest(IRequest, IActivationBuffer, Object).
However, if you do enable blocking timed events (setUseBlockingTimedEvents(boolean)),
you must be sure that you call release() in response to some event, otherwise
the model will deadlock.
- Author:
- harrison
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
AsynchronousRequestDelegate
public AsynchronousRequestDelegate()
setUseBlockingTimedEvents
public void setUseBlockingTimedEvents(boolean use)
isUsingBlockingTimedEvents
public boolean isUsingBlockingTimedEvents()
isDelayingStart
public boolean isDelayingStart()
setDelayStart
public void setDelayStart(boolean delayStart)
clear
public void clear()
- Description copied from interface:
IRequestDelegate
- clear/cancel any pending requests
- Specified by:
clear in interface IRequestDelegate
setAsynchronous
public final void setAsynchronous(boolean isAsynch)
isAsynchronous
public final boolean isAsynchronous()
- override to return true if the request should be split in time. be sure to
override
computeCompletionTime(double, IRequest, IActivationBuffer) as well
- Returns:
request
public final boolean request(IRequest request,
IActivationBuffer buffer,
double requestTime)
- make the buffer request. If synchronous
startRequest(IRequest, IActivationBuffer, double) and
finishRequest(IRequest, IActivationBuffer, Object) will be called
immediately. If not, start will be called and a timed event will be posted
that will handle
finishRequest(IRequest, IActivationBuffer, Object)
- Specified by:
request in interface IRequestDelegate
- Parameters:
request - buffer -
- Returns:
- See Also:
org.jactr.core.buffer.delegate.IRequestDelegate#request(org.jactr.core.production.request.IRequest,
org.jactr.core.buffer.IActivationBuffer)