|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jicarilla.framework.AbstractActive
org.jicarilla.framework.AbstractExecutable
Provides generic support for the 'inner worker thread' coding pattern
where child classes are shielded from most of the processing mechanics.
Subclasses will need to implement work(), which will be called from
the inner worker thread.
Exactly how often or in what kind of thread configuration the
work() method can be customized by passing in a custom
Executor. If none is provided, a single new thread will be created.
The worker passed to this executor will never Thread.sleep(long),
but it will Thread.yield() after each call to
work().
Note that this class is Active, and extends from
AbstractActive. As such, you should not override the
AbstractActive.initialize() nor the AbstractActive.dispose() methods, but only ever
override doInitialize() and/or doDispose(). When you do,
make sure to call the overridden methods as well.
| Nested Class Summary | |
protected class |
AbstractExecutable.Worker
Private helper class that will be fed to an Executor. |
| Field Summary | |
protected Executor |
m_executor
The executor that will execute our worker. |
protected ExceptionListener |
m_listener
The recipient of errors thrown by work(). |
protected AbstractExecutable.Worker |
m_worker
The worker that calls work(). |
| Fields inherited from class org.jicarilla.framework.AbstractActive |
m_running, m_stopped |
| Constructor Summary | |
AbstractExecutable()
Create a new instance that uses the ThreadedExecutor. |
|
AbstractExecutable(Executor executor)
Create a new instance that uses the provided executor. |
|
AbstractExecutable(Executor executor,
ExceptionListener listener)
Create a new instance that uses the provided executor and sends all exceptions thrown by @{link #work()} to the provided listener. |
|
| Method Summary | |
protected void |
doDispose()
Stops the worker and disposes of all state. |
protected void |
doInitialize()
Creates a new worker and tells the executor to execute it. |
protected void |
work()
This method is called whenever your 'executable' class should perform 'a unit' of work. |
| Methods inherited from class org.jicarilla.framework.AbstractActive |
checkActive, dispose, initialize, isActive, isDisposed, isInitialized, lazyInitialization |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected Executor m_executor
protected AbstractExecutable.Worker m_worker
protected ExceptionListener m_listener
| Constructor Detail |
public AbstractExecutable()
ThreadedExecutor.
public AbstractExecutable(Executor executor)
executor - the executor to use.
public AbstractExecutable(Executor executor,
ExceptionListener listener)
executor - the executor to use.listener - the listener to send exceptions to.
May be null.| Method Detail |
protected void doInitialize()
throws java.lang.InterruptedException,
java.lang.Throwable
doInitialize in class AbstractActivejava.lang.InterruptedException - if the current thread has been
Thread.interrupt()ed
java.lang.Throwable - in case of a problem.protected void doDispose()
doDispose in class AbstractActive
protected void work()
throws java.lang.Throwable
java.lang.Throwable - if any problem occurs. The exception will be fed to
any exceptionlisteners that may exist.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||