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 |
long |
__remoteId |
Scheduler |
__scheduler |
Actor |
__self |
boolean |
__stopped |
boolean |
__throwExAtBlock |
protected TicketMachine |
__ticketMachine |
static ThreadLocal<RemoteConnection> |
connection
contains remote connection if current message came from remote
|
static ThreadLocal<Actor> |
sender
contains sender of a message if one actor messages to another actor
|
CONT, DEFAULT_BOUNDED_QUEUE, DEFAULT_TIMOUT, defaultScheduler, delayedCalls, exec, instance, MAX_EXTERNAL_THREADS_POOL_SIZE, version| 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) |
boolean |
__dispatchRemoteCall(ObjectSocket objSocket,
RemoteCallEntry rce,
RemoteRegistry registry,
List<IPromise> createdFutures,
Object authContext,
BiFunction<Actor,String,Boolean> callInterceptor)
called if a message invokation from remote is received
|
Object |
__enqueueCall(Actor receiver,
String methodName,
Object[] args,
boolean isCB) |
Method |
__getCachedMethod(String methodName,
Actor actor,
BiFunction<Actor,String,Boolean> callInterceptor) |
void |
__removeRemoteConnection(RemoteConnection con) |
void |
__stop() |
protected void |
__stopImpl() |
void |
__submit(Runnable toRun) |
IPromise |
ask(String messageId,
Object... args)
generic method for untyped remoting.
|
IPromise |
askMsg(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.
|
protected void |
closeCurrentClient()
closes the connection to the remote client which has sent currently executing message.
|
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
WARNING: the similar named method exec() works different (bad naming)
|
SELF |
getActor() |
Actor |
getActorRef() |
int |
getCallbackSize()
WARNING: call rarely, this method might have O(n) runtime with default unbounded queues.
|
protected ConcurrentLinkedQueue<RemoteConnection> |
getConnections() |
DispatcherThread |
getCurrentDispatcher() |
ActorProxyFactory |
getFactory() |
int |
getMailboxSize()
WARNING: call rarely, this method might have O(n) runtime with default unbounded queues.
|
int |
getQSizes()
WARNING: call rarely, this method might have O(n) runtime with default unbounded queues.
|
IPromise |
getReport() |
Scheduler |
getScheduler() |
IPromise<Monitorable[]> |
getSubMonitorables() |
protected boolean |
getThrowExWhenBlocked() |
protected void |
hasStopped()
override to clean up / stop dependend actors
|
static boolean |
inside() |
protected <T> T |
inThread(Actor proxy,
T cbInterface)
wraps an interface into a proxy of that interface.
|
boolean |
isCallbackQPressured()
WARNING: call rarely, this method might have O(n) runtime with default unbounded queues.
|
boolean |
isEmpty() |
boolean |
isMailboxPressured()
WARNING: call rarely, this method might have O(n) runtime with default unbounded queues.
|
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,
Consumer<IPromise> toRun)
enforce serial execution of asynchronous tasks.
|
SELF |
setThrowExWhenBlocked(boolean b)
tellMsg 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 remoting.
|
void |
tellMsg(String messageId,
Object... args)
generic method for untyped messages.
|
void |
transferTo(Actor target)
only meaningful if this actor is a buffered actor (failover/reconnect scenarios).
|
AddDeadLetter, all, all, all, allMapped, AsActor, AsActor, AsActor, AsActor, AsBufferedActor, AsUntypedActor, awaitAll, awaitAll, awaitAll, awaitAll, complete, complete, DeadLetters, InThread, isComplete, isCont, isError, isErrorOrComplete, isResult, isTimeout, promise, race, race, reject, resolve, resolve, stream, SubmitDelayed, yield, yield, yieldCallbackspublic static ThreadLocal<Actor> sender
public static ThreadLocal<RemoteConnection> connection
public Queue __mailbox
public int __mbCapacity
public Queue __cbQueue
public Thread __currentDispatcher
public Scheduler __scheduler
public volatile boolean __stopped
public Actor __self
public long __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 askMsg(String messageId, Object... args)
messageId - public void tellMsg(String messageId, Object... args)
messageId - 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 boolean isEmpty()
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()
protected void closeCurrentClient()
public void asyncstop()
protected void hasStopped()
public void stopSafeClose()
public IPromise ping()
protected void serialOn(Object transactionKey, Consumer<IPromise> toRun)
transactionKey - toRun - public void transferTo(Actor target)
target - public SELF setThrowExWhenBlocked(boolean b)
b - protected boolean getThrowExWhenBlocked()
public boolean isPublished()
public void execute(Runnable command)
public DispatcherThread getCurrentDispatcher()
protected ConcurrentLinkedQueue<RemoteConnection> getConnections()
public void __addRemoteConnection(RemoteConnection con)
public void __removeRemoteConnection(RemoteConnection con)
public void __stop()
protected void __stopImpl()
public Object __enqueueCall(Actor receiver, String methodName, Object[] args, boolean isCB)
public Method __getCachedMethod(String methodName, Actor actor, BiFunction<Actor,String,Boolean> callInterceptor)
public boolean __dispatchRemoteCall(ObjectSocket objSocket, RemoteCallEntry rce, RemoteRegistry registry, List<IPromise> createdFutures, Object authContext, BiFunction<Actor,String,Boolean> callInterceptor)
public IPromise getReport()
getReport in interface Monitorablepublic IPromise<Monitorable[]> getSubMonitorables()
getSubMonitorables in interface MonitorableCopyright © 2017. All rights reserved.