MessageType
- The type of messages accepted by the actor.public abstract class Actor<MessageType> extends Object implements HjActor<MessageType>
Concrete subclasses are required to implement the process(Message) method. Typical uses will have sequential code inside process(), but this implementations allows use of any of the HJ parallel primitives inside the process() body.
This actor implementation uses ordered sends:
If actor A1 sends two messages M1 and M2 to Actor A2, A2 will
process M1 before M2. No guarantee is however provided for ordering while processing messages from another actor A3
with respect to messages from A1.
Details: Integrating Task Parallelism with Actors. Shams Imam, Vivek Sarkar. Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), October 2012.
Modifier and Type | Class and Description |
---|---|
static class |
Actor.EventType |
protected static class |
Actor.MessageData<MessageType> |
Modifier and Type | Field and Description |
---|---|
int |
actorId |
Modifier | Constructor and Description |
---|---|
protected |
Actor()
No-args constructor.
|
protected |
Actor(boolean pAlwaysSequentialBody)
Constructor for Actor.
|
Modifier and Type | Method and Description |
---|---|
void |
exit()
Call this to signal intention for the actor to terminate.
|
protected void |
handleThrowable(Throwable th)
handleThrowable.
|
boolean |
hasStarted()
Returns true if the actor has laready been started;
|
protected void |
onPostExit()
Convenience: specify code to be executed after actor is terminated
|
protected void |
onPostStart()
Convenience: specify code to be executed after actor is started
|
protected void |
onPreExit()
Convenience: specify code to be executed before actor is terminated
|
protected void |
onPreStart()
Convenience: specify code to be executed before actor is started
|
void |
pause()
Pauses the actor, i.e. the actors stops processing messages in its mailbox.
|
protected abstract void |
process(MessageType theMsg)
Callback allowing user to have custom behavior while processing messages.
|
void |
resume()
Resumes a paused actor, i.e. the actor resumes processing messages from its mailbox.
|
void |
send(MessageType message)
Sends a message to the Actor.
|
void |
start()
Causes the actor to start processing messages that have been sent to it. pause() messages before the actor was
started are ignored.
|
void |
start(HjPlace hjPlace)
Causes the actor to start processing messages that have been sent to it. pause() messages before the actor was
started are ignored.
|
protected void |
tryProcessMessage()
Try and process message from an active mailbox.
|
protected Actor()
protected Actor(boolean pAlwaysSequentialBody)
Constructor for Actor.
pAlwaysSequentialBody
- (Optimization flag) Explicit notification from user for sequential message
processing bodypublic final boolean hasStarted()
public final void start()
start
in interface HjActor<MessageType>
public final void start(HjPlace hjPlace)
start
in interface HjActor<MessageType>
public final void exit()
exit
in interface HjActor<MessageType>
public final void send(MessageType message)
send
in interface HjActor<MessageType>
message
- The message to send to this actorIllegalArgumentException
- if the message is nullpublic void pause()
This method is not thread safe, should only be called in threadsafe manner to avoid data races
pause
in interface HjActor<MessageType>
public void resume() throws IllegalStateException
resume
in interface HjActor<MessageType>
IllegalStateException
- when resume() called when the actor is not in a paused stateprotected void onPreStart()
protected void onPostStart()
protected void onPreExit()
protected void onPostExit()
protected abstract void process(MessageType theMsg)
theMsg
- message to processprotected void tryProcessMessage()
protected void handleThrowable(Throwable th)
handleThrowable.
th
- The exception that occurred while processing a message.Copyright © 2015 Rice University - Department of Computer Science. All rights reserved.