public abstract class ConcurrencyServiceAbstract extends Object implements ConcurrencyService
| Modifier and Type | Class and Description |
|---|---|
protected class |
ConcurrencyServiceAbstract.EnviroMap |
protected class |
ConcurrencyServiceAbstract.WrappedRunnable |
| Constructor and Description |
|---|
ConcurrencyServiceAbstract() |
| Modifier and Type | Method and Description |
|---|---|
protected <T> void |
callback(Future<T> future,
ReceivesValue<T> receiver) |
protected ConcurrentEnvironment |
currentEnvironment() |
boolean |
flush(Thread thread,
int timeout)
Flushes all jobs for a given thread, up to a given millisecond timeout.
|
protected Thread |
getFuturesThread()
Allows multi-threaded environments to have a single thread dedicated to
monitoring futures for completion.
|
protected abstract ConcurrentEnvironment |
initializeEnvironment(Thread key,
Thread.UncaughtExceptionHandler params) |
protected ConcurrencyServiceAbstract.EnviroMap |
initMap() |
boolean |
isMultiThreaded() |
boolean |
kill(Thread thread,
int timeout)
Flushes all jobs for the given thread, and then kills it.
|
<T> ProcessController<T> |
newProcess(Process<T> process)
Experimental; may replace
ConcurrencyService.newThread(Runnable). |
Thread |
newThread(Runnable cmd)
Experimental; may be deprecated.
|
double |
now() |
<T> void |
resolve(Future<T> future,
ReceivesValue<T> receiver)
Resolves a future in another thread / using a shared poller.
|
void |
runDeferred(Runnable cmd)
Runs the given command in a new environment, after all finalies have been
processed.
|
void |
runEventually(Runnable cmd)
Runs the command eventually, most likely on an unused thread.
|
void |
runFinally(Runnable cmd)
Runs the given command after the work queue for the current environment
is drained.
|
protected int |
threadFlushTime() |
double |
threadStartTime(Thread thread)
Tells what time the current process for the current thread started.
|
boolean |
trySleep(float millis)
Attempts to sleep, if the current thread is not interrupted.
|
protected ConcurrencyServiceAbstract.WrappedRunnable |
wrap(Runnable cmd)
Allow all subclasses to wrap Runnables for custom behavior.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitnewLock, runTimeoutprotected abstract ConcurrentEnvironment initializeEnvironment(Thread key, Thread.UncaughtExceptionHandler params)
protected int threadFlushTime()
public Thread newThread(Runnable cmd)
ConcurrencyServicenewThread in interface ConcurrencyServicecmd - - The command to wrap in a new thread.protected ConcurrencyServiceAbstract.WrappedRunnable wrap(Runnable cmd)
cmd - - The supplied Runnable to execute.protected ConcurrentEnvironment currentEnvironment()
protected ConcurrencyServiceAbstract.EnviroMap initMap()
public <T> ProcessController<T> newProcess(Process<T> process)
ConcurrencyServiceConcurrencyService.newThread(Runnable).
Accepts an instance of Process, and returns a ProcessController.
Designed to give an abstract action-oriented workflow that functions in
both threadsafe and singlethreaded environments.newProcess in interface ConcurrencyServicepublic <T> void resolve(Future<T> future, ReceivesValue<T> receiver)
ConcurrencyServiceresolve in interface ConcurrencyServicefuture - - The future to wait upon.receiver - - The handler to receive the value.
If received is an instanceof ErrorHandler, it will receive
any exceptions caused by the future (after unwrapping ExecutionException
and RuntimeException).protected Thread getFuturesThread()
protected <T> void callback(Future<T> future, ReceivesValue<T> receiver)
public boolean kill(Thread thread, int timeout)
ConcurrencyServicekill in interface ConcurrencyServicethread - - The thread to finish and then kill.timeout - - How many milliseconds to wait for a graceful shutdown.public boolean trySleep(float millis)
ConcurrencyServicetrySleep in interface ConcurrencyServicemillis - - The millis to wait. Floating point converts to nanos.public boolean flush(Thread thread, int timeout)
ConcurrencyServiceflush in interface ConcurrencyServicethread - - The thread to finish.timeout - - The maximum time to take. Send 0 to wait indefinitely.public double now()
now in interface ConcurrencyServiceTimeService.birth().public double threadStartTime(Thread thread)
ConcurrencyServicethreadStartTime in interface ConcurrencyServicethread - - The thread who's start time to check.public boolean isMultiThreaded()
public void runDeferred(Runnable cmd)
ConcurrencyServicerunDeferred in interface ConcurrencyServicecmd - - The task to run.public void runEventually(Runnable cmd)
ConcurrencyServicerunEventually in interface ConcurrencyServicecmd - - A command to run whenever there is time.
No guarantee is made about how soon or how later the process is run.
A best-effort is made to use warm threads with nothing better to do
to process eventually commands.public void runFinally(Runnable cmd)
ConcurrencyServicerunFinally in interface ConcurrencyServicecmd - - The command to run after the work queue is drained.Copyright © December 07, 2012–2015 The Internet Party. All rights reserved.