Class EventSourceActor<Event>
- java.lang.Object
-
- co.paralleluniverse.actors.ActorImpl<Message>
-
- co.paralleluniverse.actors.Actor<java.lang.Object,java.lang.Void>
-
- co.paralleluniverse.actors.behaviors.BehaviorActor
-
- co.paralleluniverse.actors.behaviors.EventSourceActor<Event>
-
- All Implemented Interfaces:
ActorBuilder<java.lang.Object,java.lang.Void>
,Joinable<java.lang.Void>
,Port<java.lang.Object>
,PortAutoCloseable
,ReceivePort<java.lang.Object>
,Stranded
,SuspendableCallable<java.lang.Void>
,java.io.Serializable
,java.lang.AutoCloseable
public class EventSourceActor<Event> extends BehaviorActor
A behavior actor that can be notified of *event* messages, which are delivered to *event handlers* which may be registered with the actor. The event handlers are called synchronously on the same strand as the actor's, so they may delay processing by other handlers if they block the strand.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class co.paralleluniverse.actors.ActorImpl
ActorImpl.ActorLifecycleListener
-
Nested classes/interfaces inherited from interface co.paralleluniverse.strands.channels.ReceivePort
ReceivePort.EOFException
-
-
Field Summary
-
Fields inherited from class co.paralleluniverse.actors.ActorImpl
flightRecorder, ref
-
-
Constructor Summary
Constructors Constructor Description EventSourceActor()
Creates a new event-source actor.EventSourceActor(Initializer initializer)
Creates a new event-source actor.EventSourceActor(Initializer initializer, MailboxConfig mailboxConfig)
Creates a new event-source actor.EventSourceActor(MailboxConfig mailboxConfig)
Creates a new event-source actor.EventSourceActor(java.lang.String name)
Creates a new event-source actor.EventSourceActor(java.lang.String name, Initializer initializer)
Creates a new event-source actor.EventSourceActor(java.lang.String name, Initializer initializer, MailboxConfig mailboxConfig)
Creates a new event-source actor.EventSourceActor(java.lang.String name, Initializer initializer, Strand strand, MailboxConfig mailboxConfig)
Creates a new event-source actor.EventSourceActor(java.lang.String name, MailboxConfig mailboxConfig)
Creates a new event-source actor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
addHandler(EventHandler<Event> handler)
static <Event> EventSourceActor<Event>
currentEventSourceActor()
protected void
handleMessage(java.lang.Object m1)
Called by the defaultBehaviorActor.behavior()
method to handle each incoming message.org.slf4j.Logger
log()
TheLogger
object associated with this actor.protected EventSource<Event>
makeRef(ActorRef<java.lang.Object> ref)
protected void
notify(Event event)
protected void
onTerminate(java.lang.Throwable cause)
This method is called by theBehaviorActor
at the end ofBehaviorActor.doRun()
.EventSource<Event>
ref()
Returns the ActorRef to this actor, if it has been started.protected boolean
removeHandler(EventHandler<Event> handler)
protected EventSource<Event>
self()
Returns the ActorRef to this actor, if it has been started.EventSource<Event>
spawn()
Starts a new fiber and runs the actor in it.EventSource<Event>
spawn(FiberFactory ff)
Starts a new fiber using the given scheduler and runs the actor in it.EventSource<Event>
spawn(StrandFactory sf)
Starts a new fiber using the given scheduler and runs the actor in it.EventSource<Event>
spawnThread()
Starts a new thread and runs the actor in it.-
Methods inherited from class co.paralleluniverse.actors.behaviors.BehaviorActor
behavior, checkCodeSwap, doRun, getInitializer, handleLifecycleMessage, init, isRunning, onStart, shutdown, terminate
-
Methods inherited from class co.paralleluniverse.actors.Actor
addLifecycleListener, build, checkThrownIn, close, currentActor, filterMessage, get, get, getActor, getDeathCause, getMonitor, getName, getQueueLength, getStrand, hire, hire, internalSend, internalSendNonSuspendable, interrupt, isClosed, isDone, isInActor, isRegistered, isStarted, join, join, link, linked, mailbox, migrate, migrateAndRestart, monitor, monitorAddDeath, monitorAddMessage, monitorResetSkippedMessages, monitorSkippedMessage, newActor, newActor, onCodeChange, readResolve, receive, receive, receive, register, register, reinstantiate, removeLifecycleListener, removeObserverListeners, run, sendSync, setForwardWatch, setMonitor, setName, setStrand, start, stopMonitor, throwIn, toString, tryReceive, trySend, unlink, unlinked, unregister, unwatch, verifyInActor, verifyOnActorStrand, watch, writeReplace
-
Methods inherited from class co.paralleluniverse.actors.ActorImpl
close, getLifecycleListener, getMailbox, isRecordingLevel, record, record, record, record, record, record, record, sendOrInterrupt
-
-
-
-
Constructor Detail
-
EventSourceActor
public EventSourceActor(java.lang.String name, Initializer initializer, Strand strand, MailboxConfig mailboxConfig)
Creates a new event-source actor.- Parameters:
name
- the actor name (may benull
).initializer
- an optional delegate object that will be run upon actor initialization and termination. May benull
.strand
- this actor's strand.mailboxConfig
- this actor's mailbox settings.
-
EventSourceActor
public EventSourceActor(java.lang.String name, Initializer initializer, MailboxConfig mailboxConfig)
Creates a new event-source actor.- Parameters:
name
- the actor name (may benull
).initializer
- an optional delegate object that will be run upon actor initialization and termination. May benull
.mailboxConfig
- this actor's mailbox settings.
-
EventSourceActor
public EventSourceActor(java.lang.String name, Initializer initializer)
Creates a new event-source actor.- Parameters:
name
- the actor name (may benull
).initializer
- an optional delegate object that will be run upon actor initialization and termination. May benull
.
-
EventSourceActor
public EventSourceActor(Initializer initializer, MailboxConfig mailboxConfig)
Creates a new event-source actor.- Parameters:
initializer
- an optional delegate object that will be run upon actor initialization and termination. May benull
.mailboxConfig
- this actor's mailbox settings.
-
EventSourceActor
public EventSourceActor(Initializer initializer)
Creates a new event-source actor.- Parameters:
initializer
- an optional delegate object that will be run upon actor initialization and termination. May benull
.
-
EventSourceActor
public EventSourceActor(java.lang.String name, MailboxConfig mailboxConfig)
Creates a new event-source actor.- Parameters:
name
- the actor name (may benull
).mailboxConfig
- this actor's mailbox settings.
-
EventSourceActor
public EventSourceActor(java.lang.String name)
Creates a new event-source actor.- Parameters:
name
- the actor name (may benull
).
-
EventSourceActor
public EventSourceActor(MailboxConfig mailboxConfig)
Creates a new event-source actor.- Parameters:
mailboxConfig
- this actor's mailbox settings.
-
EventSourceActor
public EventSourceActor()
Creates a new event-source actor.
-
-
Method Detail
-
makeRef
protected EventSource<Event> makeRef(ActorRef<java.lang.Object> ref)
- Overrides:
makeRef
in classBehaviorActor
-
ref
public EventSource<Event> ref()
Description copied from class:Actor
Returns the ActorRef to this actor, if it has been started.- Overrides:
ref
in classBehaviorActor
- Returns:
- the ActorRef of this actor if it has been started, or
null
otherwise.
-
self
protected EventSource<Event> self()
Description copied from class:Actor
Returns the ActorRef to this actor, if it has been started.- Overrides:
self
in classBehaviorActor
- Returns:
- the ActorRef of this actor if it has been started, or
null
otherwise.
-
spawn
public EventSource<Event> spawn(StrandFactory sf)
Description copied from class:Actor
Starts a new fiber using the given scheduler and runs the actor in it. The fiber's name will be set to this actor's name.- Overrides:
spawn
in classBehaviorActor
- Parameters:
sf
- thefactory
(orscheduler
) that will be used to create the actor's fiber.- Returns:
- This actors' ActorRef
-
spawn
public EventSource<Event> spawn(FiberFactory ff)
Description copied from class:Actor
Starts a new fiber using the given scheduler and runs the actor in it. The fiber's name will be set to this actor's name.- Overrides:
spawn
in classBehaviorActor
- Parameters:
ff
- thefactory
(orscheduler
) that will be used to create the actor's fiber.- Returns:
- This actors' ActorRef
-
spawn
public EventSource<Event> spawn()
Description copied from class:Actor
Starts a new fiber and runs the actor in it. The fiber's name will be set to this actor's name.- Overrides:
spawn
in classBehaviorActor
- Returns:
- This actors' ActorRef
-
spawnThread
public EventSource<Event> spawnThread()
Description copied from class:Actor
Starts a new thread and runs the actor in it. The fiber's name will be set to this actor's name.- Overrides:
spawnThread
in classBehaviorActor
- Returns:
- This actors' ActorRef
-
currentEventSourceActor
public static <Event> EventSourceActor<Event> currentEventSourceActor()
-
log
public org.slf4j.Logger log()
Description copied from class:BehaviorActor
TheLogger
object associated with this actor.- Specified by:
log
in classBehaviorActor
-
addHandler
protected boolean addHandler(EventHandler<Event> handler) throws SuspendExecution, java.lang.InterruptedException
- Throws:
SuspendExecution
java.lang.InterruptedException
-
removeHandler
protected boolean removeHandler(EventHandler<Event> handler) throws SuspendExecution, java.lang.InterruptedException
- Throws:
SuspendExecution
java.lang.InterruptedException
-
notify
protected void notify(Event event) throws SuspendExecution
- Throws:
SuspendExecution
-
handleMessage
protected final void handleMessage(java.lang.Object m1) throws java.lang.InterruptedException, SuspendExecution
Description copied from class:BehaviorActor
Called by the defaultBehaviorActor.behavior()
method to handle each incoming message. By default, this method does nothing.- Overrides:
handleMessage
in classBehaviorActor
- Parameters:
m1
- the message received by the actor.- Throws:
java.lang.InterruptedException
SuspendExecution
-
onTerminate
protected void onTerminate(java.lang.Throwable cause) throws SuspendExecution, java.lang.InterruptedException
Description copied from class:BehaviorActor
This method is called by theBehaviorActor
at the end ofBehaviorActor.doRun()
. By default, this method callsterminate()
.- Overrides:
onTerminate
in classBehaviorActor
- Throws:
SuspendExecution
java.lang.InterruptedException
-
-