com.threerings.util
Class Resulting<T>

java.lang.Object
  extended by com.samskivert.util.Invoker.Unit
      extended by com.threerings.util.Resulting<T>
All Implemented Interfaces:
ResultListener<T>, InvocationService.ConfirmListener, InvocationService.InvocationListener, InvocationService.ResultListener, Runnable

public class Resulting<T>
extends Invoker.Unit
implements ResultListener<T>, InvocationService.ConfirmListener, InvocationService.ResultListener

A chainable ResultListener, InvocationListener, and Invoker.Unit all in one. TODO: add some examples of different usages.


Nested Class Summary
protected static class Resulting.ReusableInvocationException
           
protected static class Resulting.StopException
           
 
Nested classes/interfaces inherited from interface com.samskivert.util.ResultListener
ResultListener.NOOP<T>
 
Field Summary
protected  ResultListener<T> _chain
           
protected  Exception _error
           
protected  InvocationService.InvocationListener _invChain
          Our invocation chain, if any.
protected  Logger _log
           
protected  Object[] _logArgs
           
protected  T _result
           
protected static ThreadLocal<Resulting.ReusableInvocationException> INV_EX
           
protected static ThreadLocal<Resulting.StopException> STOP
           
static Function<Object,Void> TO_VOID
          A handy Object->Void function for when you wish to chain to a ResultListener.
 
Fields inherited from class com.samskivert.util.Invoker.Unit
_name, queueStamp
 
Fields inherited from interface com.samskivert.util.ResultListener
NOOP
 
Constructor Summary
Resulting(InvocationService.InvocationListener chain)
           
Resulting(Resulting<T> chain)
           
Resulting(ResultListener<Q> chain, Function<? super T,? extends Q> xform)
           
Resulting(ResultListener<T> chain)
           
Resulting(String name)
           
Resulting(String name, InvocationService.InvocationListener chain)
           
Resulting(String name, Logger log, Object... logArgs)
           
Resulting(String name, Resulting<T> chain)
           
Resulting(String name, ResultListener<Q> chain, Function<? super T,? extends Q> xform)
           
Resulting(String name, ResultListener<T> chain)
           
 
Method Summary
 IntResultListener asIntResultListener()
          Construct your Resulting, overriding what you need to, then call this to adapt it.
 void handleResult()
           
 boolean invoke()
           
 T invokePersist()
          Override this if you are using a Resulting as an Invoker unit.
 void requestCompleted(T result)
          Override this to handle a request completion in your own way.
 void requestFailed(Exception cause)
          Override this to handle a request failed in your own way.
 void requestFailed(String error)
          Called to report request failure.
 void requestProcessed()
          Indicates that the request was successfully processed.
 void requestProcessed(Object result)
          Indicates that the request was successfully processed.
protected  T stop()
          Call this from your invokePersist() to suppress returning to the dobj thread.
 
Methods inherited from class com.samskivert.util.Invoker.Unit
getDetail, getLongThreshold, run, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TO_VOID

public static final Function<Object,Void> TO_VOID
A handy Object->Void function for when you wish to chain to a ResultListener.


_invChain

protected InvocationService.InvocationListener _invChain
Our invocation chain, if any.


_chain

protected ResultListener<T> _chain

_log

protected Logger _log

_logArgs

protected Object[] _logArgs

_result

protected T _result

_error

protected Exception _error

INV_EX

protected static final ThreadLocal<Resulting.ReusableInvocationException> INV_EX

STOP

protected static final ThreadLocal<Resulting.StopException> STOP
Constructor Detail

Resulting

public Resulting(String name)

Resulting

public Resulting(String name,
                 Resulting<T> chain)

Resulting

public Resulting(Resulting<T> chain)

Resulting

public Resulting(String name,
                 ResultListener<T> chain)

Resulting

public Resulting(ResultListener<T> chain)

Resulting

public Resulting(String name,
                 InvocationService.InvocationListener chain)

Resulting

public Resulting(InvocationService.InvocationListener chain)

Resulting

public Resulting(String name,
                 ResultListener<Q> chain,
                 Function<? super T,? extends Q> xform)

Resulting

public Resulting(ResultListener<Q> chain,
                 Function<? super T,? extends Q> xform)

Resulting

public Resulting(String name,
                 Logger log,
                 Object... logArgs)
Method Detail

asIntResultListener

public final IntResultListener asIntResultListener()
Construct your Resulting, overriding what you need to, then call this to adapt it.


invokePersist

public T invokePersist()
                throws Exception
Override this if you are using a Resulting as an Invoker unit.

Throws:
Exception

invoke

public final boolean invoke()
Specified by:
invoke in class Invoker.Unit

stop

protected final T stop()
                throws Resulting.StopException
Call this from your invokePersist() to suppress returning to the dobj thread.

Throws:
Resulting.StopException - every time.

handleResult

public final void handleResult()
Overrides:
handleResult in class Invoker.Unit

requestFailed

public final void requestFailed(String error)
Description copied from interface: InvocationService.InvocationListener
Called to report request failure. If the invocation services system detects failure of any kind, it will report it via this callback. Particular services may also make use of this callback to report failures of their own, or they may opt to define more specific failure callbacks.

Specified by:
requestFailed in interface InvocationService.InvocationListener

requestProcessed

public final void requestProcessed()
Description copied from interface: InvocationService.ConfirmListener
Indicates that the request was successfully processed.

Specified by:
requestProcessed in interface InvocationService.ConfirmListener

requestProcessed

public final void requestProcessed(Object result)
Description copied from interface: InvocationService.ResultListener
Indicates that the request was successfully processed.

Specified by:
requestProcessed in interface InvocationService.ResultListener

requestFailed

public void requestFailed(Exception cause)
Override this to handle a request failed in your own way.

Specified by:
requestFailed in interface ResultListener<T>

requestCompleted

public void requestCompleted(T result)
Override this to handle a request completion in your own way.

Specified by:
requestCompleted in interface ResultListener<T>