|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.services.daemon.BasicDaemon
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 spurrious 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
Field Summary | |
private boolean |
awakened
|
protected ContextManager |
contextMgr
|
protected ContextService |
contextService
|
private int |
earlyWakeupCount
|
private java.util.List |
highPQ
Queues for the work to be done. |
private boolean |
inPause
|
private long |
lastServiceTime
|
private int |
nextService
which subscribed clients to service next? |
private java.util.List |
normPQ
|
private int |
numClients
|
private static int |
OPTIMAL_QUEUE_SIZE
|
private boolean |
running
|
private boolean |
stopped
|
private boolean |
stopRequested
|
private java.util.Vector |
subscription
|
private boolean |
waiting
true if I'm waiting, if this is false then I am running and a notify is not required. |
Fields inherited from interface org.apache.derby.iapi.services.daemon.DaemonService |
DaemonOff, DaemonTrace, TIMER_DELAY |
Constructor Summary | |
BasicDaemon(ContextService contextService)
make a BasicDaemon |
Method Summary | |
void |
clear()
Get rid of all queued up Serviceable tasks. |
boolean |
enqueue(Serviceable newClient,
boolean serviceNow)
Request a one time service from the Daemon. |
private boolean |
inPause()
|
protected ServiceRecord |
nextAssignment(boolean urgent)
|
void |
pause()
Pause. |
private boolean |
rest()
Returns true if awakened by some notification, false if wake up by timer |
void |
resume()
Resume service after a pause |
void |
run()
|
protected void |
serviceClient(ServiceRecord clientRecord)
|
void |
serviceNow(int clientNumber)
Service this subscription ASAP. |
void |
stop()
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. |
private boolean |
stopRequested()
|
int |
subscribe(Serviceable newClient,
boolean onDemandOnly)
Add a new client that this daemon needs to service |
void |
unsubscribe(int clientNumber)
Get rid of a client from the daemon. |
void |
waitUntilQueueIsEmpty()
|
protected void |
wakeUp()
|
private void |
work(boolean urgentOnly)
|
private void |
yield()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private int numClients
private static final int OPTIMAL_QUEUE_SIZE
private final java.util.Vector subscription
protected final ContextService contextService
protected final ContextManager contextMgr
private final java.util.List highPQ
private final java.util.List normPQ
private int nextService
private boolean awakened
private boolean waiting
private boolean inPause
private boolean running
private boolean stopRequested
private boolean stopped
private long lastServiceTime
private int earlyWakeupCount
Constructor Detail |
public BasicDaemon(ContextService contextService)
Method Detail |
public int subscribe(Serviceable newClient, boolean onDemandOnly)
DaemonService
subscribe
in interface DaemonService
newClient
- a Serviceable object this daemon will service from time to timeonDemandOnly
- only service this client when it ask for service with a serviceNow request
public void unsubscribe(int clientNumber)
DaemonService
unsubscribe
in interface DaemonService
clientNumber
- the number that uniquely identify the clientpublic void serviceNow(int clientNumber)
DaemonService
serviceNow
in interface DaemonService
clientNumber
- the number that uniquely identify the clientpublic boolean enqueue(Serviceable newClient, boolean serviceNow)
DaemonService
enqueue
in interface DaemonService
newClient
- the object that needs a one time serviceserviceNow
- if true, this client should be serviced ASAP, as if a
serviceNow has been issued. If false, then this client will be
serviced with the normal scheduled.
public void clear()
clear
in interface DaemonService
protected ServiceRecord nextAssignment(boolean urgent)
protected void serviceClient(ServiceRecord clientRecord)
public void run()
run
in interface java.lang.Runnable
public void pause()
DaemonService
pause
in interface DaemonService
public void resume()
DaemonService
resume
in interface DaemonService
public void stop()
stop
in interface DaemonService
public void waitUntilQueueIsEmpty()
waitUntilQueueIsEmpty
in interface DaemonService
private boolean stopRequested()
private boolean inPause()
protected void wakeUp()
private boolean rest()
private void work(boolean urgentOnly)
private void yield()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |