| java.lang.Object org.apache.derby.impl.services.daemon.BasicDaemon
BasicDaemon | public class BasicDaemon implements DaemonService,Runnable(Code) | | A BasicDaemon is a background worker thread which does asynchronous I/O and
general clean up. It should not be used as a general worker thread for
parallel execution.
One cannot count on the order of request or count on when the daemon will
wake up, even with serviceNow requests. Request are not persistent and not
recoverable, they are all lost when the system crashes or is shutdown.
System shutdown, even orderly ones, do not wait for daemons to finish its
work or empty its queue. Furthermore, any Serviceable subscriptions,
including onDemandOnly, must tolerate spurious services. The BasicDaemon
will setup a context manager with no context on it. The Serviceable
object's performWork must provide useful context on the context manager to
do its work. The BasicDaemon will wrap performWork call with try / catch
block and will use the ContextManager's error handling to clean up any
error. The BasicDaemon will guarentee serviceNow request will not be lost
as long as the jbms does not crash - however, if N serviceNow requests are
made by the same client, it may only be serviced once, not N times.
Many Serviceable object will subscribe to the same BasicDaemon. Their
performWork method should be well behaved - in other words, it should not
take too long or hog too many resources or deadlock with anyone else. And
it cannot (should not) error out.
The BasicDaemon implementation manages the DaemonService's data structure,
handles subscriptions and enqueues requests, and determine the service
schedule for its Serviceable objects. The BasicDaemon keeps an array
(Vector) of Serviceable subscriptions it also keeps 2 queues for clients
that uses it for one time service - the 1st queue is for a serviceNow
enqueue request, the 2nd queue is for non serviceNow enqueue request.
This BasicDaemon services its clients in the following order:
1. any subscribed client that have made a serviceNow request that has not
been fulfilled
2. serviceable clients on the 1st queue
3. all subscribed clients that are not onDemandOnly
4. serviceable clients 2nd queue
|
clear | public synchronized void clear()(Code) | | Get rid of all queued up Serviceable tasks.
|
pause | public void pause()(Code) | | |
resume | public void resume()(Code) | | |
serviceNow | public void serviceNow(int clientNumber)(Code) | | |
stop | public void stop()(Code) | | Finish what we are doing and at the next convenient moment, get rid of
the thread and make the daemon object goes away if possible.
remember we are calling from another thread
|
unsubscribe | public void unsubscribe(int clientNumber)(Code) | | Removes a client from the list of subscribed clients. The call does not
wait for the daemon to finish the work it is currently performing.
Therefore, the client must tolerate that its performWork()
method could be invoked even after the call to
unsubscribe() has returned (but not more than once).
Parameters: clientNumber - client identifier |
waitUntilQueueIsEmpty | public void waitUntilQueueIsEmpty()(Code) | | |
wakeUp | protected synchronized void wakeUp()(Code) | | |
|
|