Interface DaemonService
- All Known Implementing Classes:
BasicDaemon
public interface DaemonService
A DaemonService provides a background service which is suitable for
asynchronous I/O and general clean up. It should not be used as a general
worker thread for parallel execution. A DaemonService can be subscribe to by
many Serviceable objects and a DaemonService will call that object's
performWork from time to time. The performWork method is defined by the
client object and 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.
It is up to each DaemonService
implementation to define its
level of service, including
- how quickly and how often the clients should expect to be be serviced
- how the clients are prioritized
- whether the clients need to tolerate spurious services
MT - all routines on the interface must be MT-safe.
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear all the queued up work from this daemon.boolean
enqueue
(Serviceable newClient, boolean serviceNow) Request a one time service from the Daemon.void
pause()
Pause.void
resume()
Resume service after a pausevoid
serviceNow
(int clientNumber) Service this subscription ASAP.void
stop()
End this daemon serviceint
subscribe
(Serviceable newClient, boolean onDemandOnly) Add a new client that this daemon needs to servicevoid
unsubscribe
(int clientNumber) Get rid of a client from the daemon.void
-
Field Details
-
TIMER_DELAY
static final int TIMER_DELAY- See Also:
-
DaemonTrace
Trace flag that can be used by Daemons to print stuff out -
DaemonOff
Trace flag that can be used to turn off background daemons If DaemonOff is set, background Daemon will not attempt to do anything.
-
-
Method Details
-
subscribe
Add a new client that this daemon needs to service- Parameters:
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- Returns:
- a client number that uniquely identifies this client (this subscription)
-
unsubscribe
void unsubscribe(int clientNumber) Get rid of a client from the daemon. If a client is being serviced when the call is made, the implementation may choose whether or not the call should block until the client has completed its work. If the call does not block, the client must be prepared to handle calls to itsperformWork()
method even afterunsubscribe()
has returned.- Parameters:
clientNumber
- the number that uniquely identify the client
-
serviceNow
void serviceNow(int clientNumber) Service this subscription ASAP. When this method is called, the subscriber'sperformWork()
method is guaranteed to be invoked at some point in the future. However, there is no guarantee that a subscriber'sperformWork()
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 itsperformWork()
method, the daemon service may, but is not required to, ignore requests from that subscriber until theperformWork()
method has been invoked.- Parameters:
clientNumber
- the number that uniquely identifies the client
-
enqueue
Request a one time service from the Daemon. Unless performWork returns REQUEUE (see Serviceable), the daemon will service this client once and then it will get rid of this client. Since no client number is associated with this client, it cannot request to be serviced or be unsubscribed. The work is always added to the deamon, regardless of the state it returns.- Parameters:
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.- Returns:
- true if the daemon indicates it is being overloaded, false it's happy.
-
pause
void pause()Pause. No new service is performed until a resume is issued. -
resume
void resume()Resume service after a pause -
stop
void stop()End this daemon service -
clear
void clear()Clear all the queued up work from this daemon. Subscriptions are not affected. -
waitUntilQueueIsEmpty
void waitUntilQueueIsEmpty()
-