public class Callbacks extends Object
Modifier and Type | Method and Description |
---|---|
static <IN,OUT> Callable |
callableCallback(Callback<IN,OUT> callback,
Exception ex,
IN inData,
Object... more)
Convert any Callback into a Callable
|
static Callable |
callableRunASync(ExecutorService xs,
Callback first,
Object inData,
Object... more)
By wrapping runASyncInLine() in a Callable, we can now run *everything* off the original thread.
|
static Callable |
callableRunSync(Callback first,
Object inData,
Object... more)
Wraps runSync() in a Callable so it can be run in another thread
|
static Callback |
chainUp(Callback first,
Callback... others)
Create a chain of Callbacks, by setting nextCallback along the line...
|
static Exception |
getCause(ExecutionException ee)
Utility to get the cause from an ExecutionException as an Exception, not a Throwable
|
static Object[] |
getMore(Callback callback)
Utility to get the more results (or an empty []) from a callback
|
static Object |
runASyncInLine(ExecutorService xs,
Callback callback,
Object data,
Object... more)
Runs a completedCallback (and any associated chain) using an ExecutorService
However, since we wait for the Futures "in line" here, no real speed gain (see runASyncInLine)
|
static Object |
runSync(Callback callback,
Object data,
Object... more)
Runs a callback (and any associated chain) synchronously
|
public static Callback chainUp(Callback first, Callback... others)
first
- others
- public static Object runSync(Callback callback, Object data, Object... more) throws Exception
callback
- first callback, if null, data will be returned immediatelydata
- input to first callbackException
public static Callable callableRunSync(Callback first, Object inData, Object... more)
first
- if null, returns inDatainData
- inputs to the first callbackmore
- inputs to the first callbackpublic static Object runASyncInLine(ExecutorService xs, Callback callback, Object data, Object... more) throws Exception
xs
- if null, they get run synccallback
- if null, returns inDatadata
- inputs to the first callbackmore
- inputs to the first callbackException
public static Callable callableRunASync(ExecutorService xs, Callback first, Object inData, Object... more)
xs
- first
- inData
- for a better alternative
public static <IN,OUT> Callable callableCallback(Callback<IN,OUT> callback, Exception ex, IN inData, Object... more)
callback
- if null this returns nullex
- input to the CallbackinData
- input to the Callbackpublic static Object[] getMore(Callback callback)
callback
- non-nullpublic static Exception getCause(ExecutionException ee)
ee
- may be nullError
- if ee wrapped an Error