P
- The type of parameter you provide to make the object that will be created. It should implement Object.hashCode()
and Object.equals(Object)
if you want to get the value early.T
- The type of object you provide. This is created in stage 1, and passed to stage 2, 3, and returned if get() is called.C
- The type of callback you provide. You may register many of these to be passed to the provider in stage 3, one at a time.E
- A type of exception you may throw and expect to be handled by the main threadpublic final class AsynchronousExecutor<P,T,C,E extends java.lang.Throwable>
extends java.lang.Object
finishActive()
or the get(Object)
methods.
Modifier and Type | Class and Description |
---|---|
static interface |
AsynchronousExecutor.CallBackProvider<P,T,C,E extends java.lang.Throwable> |
Constructor and Description |
---|
AsynchronousExecutor(AsynchronousExecutor.CallBackProvider<P,T,C,E> provider,
int coreSize)
Uses a thread pool to pass executions to the provider.
|
Modifier and Type | Method and Description |
---|---|
void |
add(P parameter,
C callback)
Adds a callback to the parameter provided, adding parameter to the queue if needed.
|
boolean |
drop(P parameter,
C callback)
This removes a particular callback from the specified parameter.
|
void |
finishActive()
This is the 'heartbeat' that should be called synchronously to finish any pending tasks
|
T |
get(P parameter)
This method attempts to skip the waiting period for said parameter.
|
T |
getSkipQueue(P parameter)
Processes a parameter as if it was in the queue, without ever passing to another thread.
|
T |
getSkipQueue(P parameter,
C... callbacks)
Processes a parameter as if it was in the queue, without ever passing to another thread.
|
T |
getSkipQueue(P parameter,
C callback)
Processes a parameter as if it was in the queue, without ever passing to another thread.
|
T |
getSkipQueue(P parameter,
java.lang.Iterable<C> callbacks)
Processes a parameter as if it was in the queue, without ever passing to another thread.
|
void |
setActiveThreads(int coreSize) |
public AsynchronousExecutor(AsynchronousExecutor.CallBackProvider<P,T,C,E> provider, int coreSize)
AsynchronousExecutor
public void add(P parameter, C callback)
This should always be synchronous.
public boolean drop(P parameter, C callback) throws java.lang.IllegalStateException
If no callbacks remain for a given parameter, then the CallBackProvider's
stages may be omitted from execution.
Stage 3 will have no callbacks, stage 2 will be skipped unless a get(Object)
is used, and stage 1 will be avoided on a best-effort basis.
Subsequent calls to getSkipQueue(Object)
will always work.
Subsequent calls to get(Object)
might work.
This should always be synchronous
finishActive()
for the parameter, and get(Object)
will throw an IllegalStateException
, false otherwisejava.lang.IllegalStateException
- if parameter is not in the queue anymorejava.lang.IllegalStateException
- if the callback was not specified for given parameterpublic T get(P parameter) throws E extends java.lang.Throwable, java.lang.IllegalStateException
This should always be synchronous.
java.lang.IllegalStateException
- if the parameter is not in the queue anymore, or sometimes if called from asynchronous threadE extends java.lang.Throwable
public T getSkipQueue(P parameter) throws E extends java.lang.Throwable
E extends java.lang.Throwable
public T getSkipQueue(P parameter, C callback) throws E extends java.lang.Throwable
E extends java.lang.Throwable
public T getSkipQueue(P parameter, C... callbacks) throws E extends java.lang.Throwable
E extends java.lang.Throwable
public T getSkipQueue(P parameter, java.lang.Iterable<C> callbacks) throws E extends java.lang.Throwable
E extends java.lang.Throwable
public void finishActive() throws E extends java.lang.Throwable
E extends java.lang.Throwable
public void setActiveThreads(int coreSize)