public class Actor<SELF extends Actor> extends Actors implements Serializable, Monitorable, Executor
public class MyActor extends ActorNote that unlike in other actor libraries, processing of Callback and Promise is transfered to the current actor thread, so its safe to close over actor state.{ // public async API public IPromise init() {..} public void asyncMessage(String arg) { .. } public IPromise asyncMessage(String arg) { .. } public void asyncMessage(int arg, Callback aCallback) { .. } // synchronous methods (safe as cannot be called by foreign threads) protected String syncMethod() { .. } } MyActor act = Actors.AsActor(MyActor.class); act.init().then( () -> { System.out.println("done"); } Object res = act.asyncMessage("Hello").await();
| Modifier and Type | Class and Description |
|---|---|
static class |
Actor.ActorReport |
| Modifier and Type | Field and Description |
|---|---|
Queue |
__cbQueue |
RemoteConnection |
__clientConnection |
ConcurrentLinkedQueue<RemoteConnection> |
__connections |
Thread |
__currentDispatcher |
Queue |
__mailbox |
int |
__mailboxCapacity |
int |
__mbCapacity |
int |
__remoteId |
Scheduler |
__scheduler |
Actor |
__self |
boolean |
__stopped |
boolean |
__throwExAtBlock |
protected TicketMachine |
__ticketMachine |
static ThreadLocal<Actor> |
sender
contains sender of a message if one actor messages to another actor
|
CONT, DEFAULT_TIMOUT, defaultScheduler, delayedCalls, exec, FIN, FINSILENT, instance, MAX_EXTERNAL_THREADS_POOL_SIZE| Constructor and Description |
|---|
Actor()
required by bytecode magic.
|
| Modifier and Type | Method and Description |
|---|---|
void |
__addDeadLetter(Actor receiver,
String methodName) |
void |
__addRemoteConnection(RemoteConnection con) |
void |
__addStopHandler(Callback<SELF> cb) |
Object |
__enqueueCall(Actor receiver,
String methodName,
Object[] args,
boolean isCB) |
Method |
__getCachedMethod(String methodName,
Actor actor) |
void |
__removeRemoteConnection(RemoteConnection con) |
void |
__stop() |
void |
__submit(Runnable toRun) |
IPromise |
ask(String messageId,
Object... args)
generic method for untyped messages.
|
void |
asyncstop() |
protected void |
checkThread()
Debug method.
|
void |
close()
closes associated remote connection(s) if present.
|
static Actor |
current() |
void |
delayed(long millis,
Runnable toRun)
schedule an action or call delayed.
|
<T> IPromise<T> |
exec(Callable<T> callable)
execute a callable asynchronously (in a different thread) and return a future
of the result (delivered in caller thread).
|
void |
execute(Runnable command)
just enqueue given runable to this actors mailbox and execute on the actor's thread
|
SELF |
getActor() |
Actor |
getActorRef() |
int |
getCallbackSize() |
DispatcherThread |
getCurrentDispatcher() |
ActorProxyFactory |
getFactory() |
int |
getMailboxSize() |
int |
getQSizes() |
IPromise |
getReport() |
Scheduler |
getScheduler() |
IPromise<Monitorable[]> |
getSubMonitorables() |
protected boolean |
getThrowExWhenBlocked() |
static boolean |
inside() |
protected <T> T |
inThread(Actor proxy,
T cbInterface)
wraps an interface into a proxy of that interface.
|
boolean |
isCallbackQPressured() |
boolean |
isMailboxPressured() |
boolean |
isProxy() |
boolean |
isPublished() |
boolean |
isRemote() |
boolean |
isStopped()
synchronous method returning true in case this actor is stopped
|
IPromise |
ping()
can be used to wait for all messages having been processed and get a signal from the returned future once this is complete
|
protected SELF |
self()
use this to call public methods using actor-dispatch instead of direct in-thread call.
|
protected void |
serialOn(Object transactionKey,
java.util.function.Consumer<IPromise> toRun)
enforce serial execution of asynchronous tasks.
|
SELF |
setThrowExWhenBlocked(boolean b)
tell the execution machinery to throw an ActorBlockedException in case the actor is blocked trying to
put a message on an overloaded actor's mailbox/queue.
|
void |
stop()
stop receiving events.
|
void |
stopSafeClose()
avoids exception when closing an actor after stop has been called.
|
void |
tell(String messageId,
Object... args)
generic method for untyped messages.
|
AddDeadLetter, all, all, AsActor, AsActor, AsActor, AsActor, awaitAll, awaitAll, awaitAll, awaitAll, complete, complete, DeadLetters, InThread, isCont, isError, isFinal, isResult, isSilentFinal, race, race, reject, resolve, resolve, stream, SubmitDelayed, yield, yieldpublic static ThreadLocal<Actor> sender
public Queue __mailbox
public int __mbCapacity
public Queue __cbQueue
public Thread __currentDispatcher
public Scheduler __scheduler
public volatile boolean __stopped
public Actor __self
public int __remoteId
public boolean __throwExAtBlock
public volatile ConcurrentLinkedQueue<RemoteConnection> __connections
public RemoteConnection __clientConnection
public int __mailboxCapacity
protected TicketMachine __ticketMachine
public Actor()
public static Actor current()
public static boolean inside()
public void __submit(Runnable toRun)
protected SELF self()
public ActorProxyFactory getFactory()
public SELF getActor()
public void stop()
public boolean isStopped()
public boolean isProxy()
public IPromise ask(String messageId, Object... args)
messageId - public void tell(String messageId, Object... args)
messageId - public <T> IPromise<T> exec(Callable<T> callable)
T - callable - public void delayed(long millis,
Runnable toRun)
public boolean isMailboxPressured()
public Scheduler getScheduler()
public boolean isCallbackQPressured()
public int getMailboxSize()
public int getQSizes()
public int getCallbackSize()
protected <T> T inThread(Actor proxy, T cbInterface)
T - proxy - cbInterface - protected final void checkThread()
public Actor getActorRef()
public boolean isRemote()
public void close()
public void asyncstop()
public void stopSafeClose()
public IPromise ping()
protected void serialOn(Object transactionKey, java.util.function.Consumer<IPromise> toRun)
transactionKey - toRun - public SELF setThrowExWhenBlocked(boolean b)
b - protected boolean getThrowExWhenBlocked()
public boolean isPublished()
public void __addRemoteConnection(RemoteConnection con)
public void __removeRemoteConnection(RemoteConnection con)
public void __stop()
public Object __enqueueCall(Actor receiver, String methodName, Object[] args, boolean isCB)
public void execute(Runnable command)
public DispatcherThread getCurrentDispatcher()
public IPromise getReport()
getReport in interface Monitorablepublic IPromise<Monitorable[]> getSubMonitorables()
getSubMonitorables in interface MonitorableCopyright © 2015. All rights reserved.