public abstract class ReaderWriterActor<MsgType> extends Selector<ReadWriteEnum.ReaderWriterMessage<MsgType>>
Messages are sent to this actor using the sendReadMessage()
and sendWriteMessage()
methods. Users
are discouraged from using the send()
method directly to send messages.
Policy decisions in the implementation: The messages are processed using an arrival-order policy, reader-first policy, or writer-first policy. By default we use the writer-first policy (i.e. writer messages get processed before reader messages). A writer is given preference as writes are expected to be short and infrequent. Preference to the writer can reduce the potential for concurrency. As soon as a write message is seen, any subsequent messages are prevented from being processed. The runtime waits until all in-flight read messages have been completely processed, then the write message is processed before enabling processing of messages following the write message.
The actual implementation uses DataDrivenControl
instances to wait and
trigger the execution of write messages when there are read messages in-flight.
numClassifiers
Modifier | Constructor and Description |
---|---|
protected |
ReaderWriterActor() |
protected |
ReaderWriterActor(ReaderWriterPolicy policy) |
Modifier and Type | Method and Description |
---|---|
protected void |
process(ReadWriteEnum.ReaderWriterMessage<MsgType> theMsg)
Callback allowing user to have custom behavior while processing messages.
|
protected abstract void |
processRead(MsgType theMsg)
Callback allowing user to have custom behavior while processing 'read' messages.
|
protected abstract void |
processWrite(MsgType theMsg)
Callback allowing user to have custom behavior while processing 'write' messages.
|
void |
sendReadMessage(MsgType message) |
void |
sendWriteMessage(MsgType message) |
disable, disable, disableAllExcept, disableAllExcept, enable, enable, enableAll, exit, handleThrowable, hasStarted, isEnabled, isEnabled, onPostExit, onPostStart, onPreExit, onPreStart, send, send, start, start, tryProcessMessage
protected ReaderWriterActor()
NullPointerException
- if enumClass is nullIllegalArgumentException
- if enumClass does not represent an enumprotected ReaderWriterActor(ReaderWriterPolicy policy)
policy
- The reader-writer policy to useNullPointerException
- if enumClass is nullIllegalArgumentException
- if enumClass does not represent an enumpublic final void sendWriteMessage(MsgType message)
public final void sendReadMessage(MsgType message)
protected final void process(ReadWriteEnum.ReaderWriterMessage<MsgType> theMsg)
Selector
process
in class Selector<ReadWriteEnum.ReaderWriterMessage<MsgType>>
theMsg
- message to processprotected abstract void processWrite(MsgType theMsg)
theMsg
- message to processprotected abstract void processRead(MsgType theMsg)
theMsg
- message to processCopyright © 2015 Rice University - Department of Computer Science. All rights reserved.