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 |
ConnectionRegistry |
__clientConnection |
ConcurrentLinkedQueue<ConnectionRegistry> |
__connections |
Thread |
__currentDispatcher |
Queue |
__mailbox |
int |
__mailboxCapacity |
int |
__mbCapacity |
Actor |
__publishTarget |
long |
__remoteId |
Scheduler |
__scheduler |
Actor |
__self |
boolean |
__stopped |
protected TicketMachine |
__ticketMachine |
static ThreadLocal<ConnectionRegistry> |
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
|
Object |
userData
free for outer mechanics to use.
|
boolean |
zzRoutingGCEnabled |
Callback<RemoteCallEntry> |
zzServerMsgCallback |
CONT, 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(ConnectionRegistry con) |
void |
__addStopHandler(Callback<SELF> cb) |
boolean |
__dispatchRemoteCall(ObjectSocket objSocket,
RemoteCallEntry rce,
ConnectionRegistry 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(ConnectionRegistry 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 |
cyclic(long interval,
Callable<Boolean> toRun) |
void |
debounce(long timeout,
String tag,
Runnable toRun) |
void |
delayed(long millis,
Runnable toRun)
schedule an action or call delayed.
|
<T> IPromise<T> |
execInThreadPool(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 execInThreadPool() 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<ConnectionRegistry> |
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() |
Actor |
getUntypedRef() |
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
|
IPromise<Long> |
router$clientPing(long tim,
long[] publishedActorIds)
a krouter client should ping using this method.
|
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.
|
void |
setServerMsgCallback(Callback<RemoteCallEntry> cb)
cb is invoked once the server sends back messages to a client,
the client does not necessary have an actor running but might simply connect
using ordinary mt code
|
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 |
unpublish() |
void |
zzkrouterLostClient() |
void |
zzRoutingRefGC(long[] ids) |
AddDeadLetter, all, all, all, allMapped, AsActor, AsActor, AsActor, AsActor, AsUntypedActor, awaitAll, awaitAll, awaitAll, awaitAll, complete, complete, DeadLetters, flow, 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<ConnectionRegistry> connection
public Object userData
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 volatile ConcurrentLinkedQueue<ConnectionRegistry> __connections
public ConnectionRegistry __clientConnection
public boolean zzRoutingGCEnabled
public int __mailboxCapacity
protected TicketMachine __ticketMachine
public Callback<RemoteCallEntry> zzServerMsgCallback
public Actor __publishTarget
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> execInThreadPool(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 boolean isPublished()
public void execute(Runnable command)
public DispatcherThread getCurrentDispatcher()
protected ConcurrentLinkedQueue<ConnectionRegistry> getConnections()
public Actor getUntypedRef()
public void __addRemoteConnection(ConnectionRegistry con)
public void __removeRemoteConnection(ConnectionRegistry 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, ConnectionRegistry registry, List<IPromise> createdFutures, Object authContext, BiFunction<Actor,String,Boolean> callInterceptor)
public void unpublish()
public void setServerMsgCallback(Callback<RemoteCallEntry> cb)
cb - public IPromise<Long> router$clientPing(long tim, long[] publishedActorIds)
tim - publishedActorIds - - published actors of senderpublic void zzRoutingRefGC(long[] ids)
public void zzkrouterLostClient()
public IPromise getReport()
getReport in interface Monitorablepublic IPromise<Monitorable[]> getSubMonitorables()
getSubMonitorables in interface MonitorableCopyright © 2019. All rights reserved.