Package org.nustaq.kontraktor.impl
Class CallbackWrapper<T>
java.lang.Object
org.nustaq.kontraktor.impl.CallbackWrapper<T>
- All Implemented Interfaces:
Serializable,Callback<T>,IPromise<T>
If a promise or callback is wrapped by this, it will be treated correctly when remoted.
If callback/promises are part of an actor's async method signature (parameter), kontraktor will automatically
use this class to wrap such that remote calls work correctly.
However if a promise or callback is embedded inside some Pojo, and this pojo is sent over the network,
Promises and Callbacks do not work (performance issues, deep scan with many instanceof's required).
Note that identity of callbacks / promises gets lost when sent over network, e.g. when passing the
same callback twice to a remote actor, on the remote actor these callback objects will not be equal
(=> cannot hash on calbacks on remote side, e.g. for subscription schemes). Callbacks/Promises are lightweigt
remote objects while remote actor references are hashed and managed by the framework in order to be able
to detect identiy (remoteId).
- See Also:
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionawait(long timeout) schedule other events/messages until future is resolved/settled (Nonblocking delay).awaitPromise(long timeout) schedule other events/messages until future is resolved/settled (Nonblocking delay).<OUT> IPromise<OUT>catchError(Consumer<Object> function) called if an error has been signaled by one of the futures in the previous future chain.<OUT> IPromise<OUT>catchError(Function<Object, IPromise<OUT>> function) called if an error has been signaled by one of the futures in the previous future chain.voidset result or error. error might also contain flow indicators to signal end/continue of stream when remoting.get()Warning: this is different to JDK's BLOCKING futuregetError()booleanisRemote()booleanisRouted()booleanbooleanrelevant for remoted callback'scalled when an error is set as the result forwards to (new) "catchError" variant.Warning: this will not be called on error or timeoutcalled when the async call times out. see 'timeOutIn'Warning: this will not be called on error or timeout<OUT> IPromise<OUT>called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing.Warning: this will not be called on error or timeout<OUT> IPromise<OUT>called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing.called once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing.timeoutIn(long millis) tellMsg the future to call the onTimeout callback in N milliseconds if future is not settled until thenMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.nustaq.kontraktor.Callback
complete, finish, pipe, reject, resolve, resolveMethods inherited from interface org.nustaq.kontraktor.IPromise
await, awaitPromise, onTimeout
-
Constructor Details
-
CallbackWrapper
-
-
Method Details
-
isRouted
public boolean isRouted() -
complete
Description copied from interface:Callbackset result or error. error might also contain flow indicators to signal end/continue of stream when remoting. (Actor.FIN Actor.CONT) -
getRealCallback
-
then
Warning: this will not be called on error or timeout -
thenAnd
Description copied from interface:IPromisecalled once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing. e.g. actor.asyncMehod().then( () -> { furtherProcessing(); return new Promise("result"); } ); -
then
Warning: this will not be called on error or timeout -
onResult
Warning: this will not be called on error or timeout -
onError
Description copied from interface:IPromisecalled when an error is set as the result forwards to (new) "catchError" variant. -
onTimeout
Description copied from interface:IPromisecalled when the async call times out. see 'timeOutIn' -
thenAnd
Description copied from interface:IPromisecalled once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing. e.g. actor.asyncMehod().then( () -> { furtherProcessing(); return new Promise("result"); } ); -
then
Description copied from interface:IPromisecalled once any result of a future becomes available Can be used in case a sender is not interested in the actual result but when a remote method has finished processing. e.g. actor.asyncMethod().then( () -> { furtherProcessing(); return new Promise("result"); } ); -
catchError
Description copied from interface:IPromisecalled if an error has been signaled by one of the futures in the previous future chain. e.e. actor.async().then( ).then( ).then( ).catchError( error -> .. );- Specified by:
catchErrorin interfaceIPromise<T>
-
catchError
Description copied from interface:IPromisecalled if an error has been signaled by one of the futures in the previous future chain. e.e. actor.async().then( ).then( ).then( ).catchError( () -> .. );- Specified by:
catchErrorin interfaceIPromise<T>
-
get
Description copied from interface:IPromiseWarning: this is different to JDK's BLOCKING future -
await
Description copied from interface:IPromiseschedule other events/messages until future is resolved/settled (Nonblocking delay). In case this is called from a non-actor thread, the current thread is blocked until the result is avaiable. If the future is rejected (resolves to an error) an excpetion is raised. if timeout is 0l - wait forever. -
awaitPromise
Description copied from interface:IPromiseschedule other events/messages until future is resolved/settled (Nonblocking delay). In case this is called from a non-actor thread, the current thread is blocked until the result is avaiable.- Specified by:
awaitPromisein interfaceIPromise<T>- Returns:
- the settled promise. No Exception is thrown, but the exception can be obtained by IPromise.getError()
-
getError
-
timeoutIn
Description copied from interface:IPromisetellMsg the future to call the onTimeout callback in N milliseconds if future is not settled until then -
isSettled
public boolean isSettled() -
isRemote
public boolean isRemote() -
isTerminated
public boolean isTerminated()Description copied from interface:Callbackrelevant for remoted callback's- Specified by:
isTerminatedin interfaceCallback<T>- Returns:
- if the corresponding remote connection is closed if any
-