java.lang.Runnable
, DaemonService
public class BasicDaemon extends java.lang.Object implements DaemonService, java.lang.Runnable
Modifier and Type | Field | Description |
---|---|---|
private boolean |
awakened |
|
protected ContextManager |
contextMgr |
|
protected ContextService |
contextService |
|
private int |
earlyWakeupCount |
|
private java.util.List<ServiceRecord> |
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<ServiceRecord> |
normPQ |
|
private int |
numClients |
|
private static int |
OPTIMAL_QUEUE_SIZE |
|
private boolean |
running |
|
private boolean |
stopped |
|
private boolean |
stopRequested |
|
private java.util.Vector<ServiceRecord> |
subscription |
|
private boolean |
waiting |
true if I'm waiting, if this is false then I am running and a notify is not required.
|
DaemonOff, DaemonTrace, TIMER_DELAY
Constructor | Description |
---|---|
BasicDaemon(ContextService contextService) |
make a BasicDaemon
|
Modifier and Type | Method | Description |
---|---|---|
void |
clear() |
Get rid of all queued up Serviceable tasks.
|
boolean |
enqueue(Serviceable newClient,
boolean serviceNow) |
Request a one time service from the Daemon.
|
(package private) static ModuleFactory |
getMonitor() |
Privileged Monitor lookup.
|
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.
|
private static void |
setThreadPriority(ModuleFactory mf,
int priority) |
Change the priority of the current thread, but only if it was created
by
ModuleFactory.getDaemonThread(java.lang.Runnable, java.lang.String, boolean) . |
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) |
Removes a client from the list of subscribed clients.
|
void |
waitUntilQueueIsEmpty() |
|
protected void |
wakeUp() |
|
private void |
work(boolean urgentOnly) |
|
private void |
yield() |
private int numClients
private static final int OPTIMAL_QUEUE_SIZE
private final java.util.Vector<ServiceRecord> subscription
protected final ContextService contextService
protected final ContextManager contextMgr
private final java.util.List<ServiceRecord> highPQ
private final java.util.List<ServiceRecord> 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
public BasicDaemon(ContextService contextService)
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 requestpublic void unsubscribe(int clientNumber)
performWork()
method could be invoked even after the call to
unsubscribe()
has returned (but not more than once).unsubscribe
in interface DaemonService
clientNumber
- client identifierpublic void serviceNow(int clientNumber)
DaemonService
performWork()
method is guaranteed to be
invoked at some point in the future. However, there is no guarantee that
a subscriber's performWork()
is called the same number of
times as the subscriber calls this method. More precisely, if a
subscriber is waiting for this daemon service to invoke its
performWork()
method, the daemon service may, but is not
required to, ignore requests from that subscriber until the
performWork()
method has been invoked.serviceNow
in interface DaemonService
clientNumber
- the number that uniquely identifies 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()
private static void setThreadPriority(ModuleFactory mf, int priority)
ModuleFactory.getDaemonThread(java.lang.Runnable, java.lang.String, boolean)
.static ModuleFactory getMonitor()
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.