Package org.nustaq.kontraktor
Class Actors
java.lang.Object
org.nustaq.kontraktor.Actors
- Direct Known Subclasses:
Actor
Copyright (c) 2012, Ruediger Moeller. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA
Date: 04.01.14
Time: 19:50
A set of static async helper methods. Note Actor inherits from this class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringuse value as error to indicate more messages are to come (else remoting will close channel).static intstatic Timerstatic ThreadPoolExecutorstatic ActorsImplstatic intstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidsimilar to es6 Promise.all method, however non-IPromise objects are not allowed returns a future which is settled once all promises provided are settledsimilar to es6 Promise.all method, however non-IPromise objects are not allowed returns a future which is settled once all promises provided are settledsimilar all but map promises to their content returns a future which is settled once all promises provided are settledstatic <T extends Actor>
Tcreate an new actor.static <T extends Actor>
Tcreate an new actor.static <T extends Actor>
Tcreate an new actor dispatched in the given DispatcherThreadstatic <T extends Actor>
Tcreate an new actor dispatched in the given DispatcherThreadstatic ActorAsUntypedActor(Actor instance) static <T> Stream<T>static <T> Stream<T>await until all futures are settled and stream their resultsstatic <T> Stream<T>static <T> Stream<T>await until all futures are settled and stream their results.static IPromisecomplete()abbreviation for Promise creation to make code more concisestatic <T> IPromise<T>abbreviation for Promise creation to make code more concisemessages that have been dropped or have been sent to stopped actorsstatic <T> KFlow<T>flow()static <T> TInThread(T anInterface) in case called from an actor, wraps the given interface instance into a proxy such that all calls on the interface get scheduled on the calling actors thread (avoids accidental multithreading when handing out callback/listener interfaces from an actor) if called from outside an actor thread, NOPstatic booleanisComplete(Object error) static booleanhelper to check for "special" error object "CONT". cont signals further callback results might be sent (important for remoting as channels need to get cleaned up)static booleanhelper to check for "special" error objects.static booleanisErrorOrComplete(Object error) return if given error Object signals an error or a 'complete' signalstatic booleanstatic booleanstatic voidkYield()processes messages from mailbox / callbackqueue until no messages are left NOP if called from non actor thread.static voidkYield(long timeout) process messages on the mailbox/callback queue until timeout is reached.static <T> Promise<T>promise()shorthand constructorstatic <T> IPromise<T>race(Collection<IPromise<T>> futures) similar to es6 Promise.race method, however non-IPromise objects are not allowed returns a future which is settled once one of the futures provided gets settledstatic <T> IPromise<T>similar to es6 Promise.race method, however non-IPromise objects are not allowed returns a future which is settled once one of the futures provided gets settledstatic <T> IPromise<T>abbreviation for Promise creation to make code more concisestatic <T> IPromise<T>resolve()abbreviation for Promise creation to make code more concisestatic <T> IPromise<T>resolve(T res) abbreviation for Promise creation to make code more concisestatic <T> Stream<T>stream(T... t) utility addition to java 8 streamsstatic voidSubmitDelayed(long millis, Runnable task) utility function.static voidyieldCallbacks(long timeout) only process callbacks until timeout or cbQ is empty.
-
Field Details
-
MAX_EXTERNAL_THREADS_POOL_SIZE
public static int MAX_EXTERNAL_THREADS_POOL_SIZE -
DEFAULT_TIMOUT
public static int DEFAULT_TIMOUT -
exec
-
version
- See Also:
-
instance
-
delayedCalls
-
defaultScheduler
-
CONT
use value as error to indicate more messages are to come (else remoting will close channel).- See Also:
-
-
Constructor Details
-
Actors
public Actors()
-
-
Method Details
-
isErrorOrComplete
return if given error Object signals an error or a 'complete' signal- Parameters:
error-- Returns:
-
isTimeout
-
isComplete
-
isCont
helper to check for "special" error object "CONT". cont signals further callback results might be sent (important for remoting as channels need to get cleaned up)- Parameters:
o-- Returns:
-
isResult
-
isError
helper to check for "special" error objects.- Parameters:
err-- Returns:
-
SubmitDelayed
utility function. Executed in foreign thread. Use Actor::delayed() to have the runnable executed inside actor thread -
AddDeadLetter
-
InThread
public static <T> T InThread(T anInterface) in case called from an actor, wraps the given interface instance into a proxy such that all calls on the interface get scheduled on the calling actors thread (avoids accidental multithreading when handing out callback/listener interfaces from an actor) if called from outside an actor thread, NOP- Type Parameters:
T-- Parameters:
anInterface-- Returns:
-
DeadLetters
messages that have been dropped or have been sent to stopped actors- Returns:
- queue of dead letters. Note: only strings are recorded to avoid accidental references.
-
AsActor
create an new actor. If this is called outside an actor, a new DispatcherThread will be scheduled. If called from inside actor code, the new actor will share the thread+queue with the caller.- Type Parameters:
T-- Parameters:
actorClazz-- Returns:
-
AsUntypedActor
-
AsActor
create an new actor. If this is called outside an actor, a new DispatcherThread will be scheduled. If called from inside actor code, the new actor will share the thread+queue with the caller.- Type Parameters:
T-- Parameters:
actorClazz-- Returns:
-
AsActor
create an new actor dispatched in the given DispatcherThread- Type Parameters:
T-- Parameters:
actorClazz-- Returns:
-
AsActor
create an new actor dispatched in the given DispatcherThread- Type Parameters:
T-- Parameters:
actorClazz-- Returns:
-
all
-
all
similar to es6 Promise.all method, however non-IPromise objects are not allowed returns a future which is settled once all promises provided are settled -
all
similar to es6 Promise.all method, however non-IPromise objects are not allowed returns a future which is settled once all promises provided are settled -
allMapped
similar all but map promises to their content returns a future which is settled once all promises provided are settled -
awaitAll
await until all futures are settled and stream their results -
awaitAll
await until all futures are settled and stream their results. Uses Actors.DEFAULT_TIMEOUT -
awaitAll
-
awaitAll
-
race
similar to es6 Promise.race method, however non-IPromise objects are not allowed returns a future which is settled once one of the futures provided gets settled -
race
similar to es6 Promise.race method, however non-IPromise objects are not allowed returns a future which is settled once one of the futures provided gets settled -
stream
utility addition to java 8 streams- Type Parameters:
T-- Parameters:
t-- Returns:
-
flow
-
resolve
abbreviation for Promise creation to make code more concise- Type Parameters:
T-- Parameters:
res-- Returns:
-
reject
abbreviation for Promise creation to make code more concise -
promise
shorthand constructor- Type Parameters:
T-- Returns:
-
complete
abbreviation for Promise creation to make code more concise -
complete
abbreviation for Promise creation to make code more concise -
resolve
abbreviation for Promise creation to make code more concise -
kYield
public static void kYield()processes messages from mailbox / callbackqueue until no messages are left NOP if called from non actor thread. -
kYield
public static void kYield(long timeout) process messages on the mailbox/callback queue until timeout is reached. In case timeout is 0, process until mailbox+callback queue is empty. If called from a non-actor thread, either sleep until timeout or (if timeout == 0) its a NOP.- Parameters:
timeout-
-
yieldCallbacks
public static void yieldCallbacks(long timeout) only process callbacks until timeout or cbQ is empty. Messages are not polled and processed. Useful in order to stall a producer, but preserve message processing order.- Parameters:
timeout-
-