public class SimpleServiceMonitor extends Object implements ServiceMonitor
SimpleServiceMonitor
starts and monitors services that are
registered for monitoring.Modifier and Type | Field and Description |
---|---|
protected static Integer |
DEFAULT_WAIT_MILLIS
The default time interval by which we check the alive status.
|
protected ConfigurableCacheFactory |
m_ccf
A
ConfigurableCacheFactory instance used to start the service. |
protected long |
m_cWaitMillis
The number of milliseconds between checking the status of the services.
|
protected boolean |
m_fDisposed
Indicates that this
ServiceMonitor has been disposed. |
protected boolean |
m_fStarted
Indicates that the
ServiceMonitor has started. |
protected Map<Service,String> |
m_mapServices
A map of
Service s to be monitored with values being non-scoped service names. |
protected Thread |
m_thread
The
Thread we are using for monitoring the services periodically. |
Constructor and Description |
---|
SimpleServiceMonitor()
Construct a SimpleServiceMonitor with the default interval to check
that the registered services are running (
DEFAULT_WAIT_MILLIS ). |
SimpleServiceMonitor(long cWaitMillis)
Construct a SimpleServiceMonitor with the provided interval to check
that the registered services are running.
|
Modifier and Type | Method and Description |
---|---|
protected void |
assertNotDisposed()
Throws
IllegalStateException if this monitor has been disposed
via invocation of dispose() . |
void |
dispose()
Invoked when all resources owned by the implementer can safely be
released.
|
Thread |
getThread()
Return the thread used by this ServiceMonitor.
|
protected boolean |
isDisposed()
Return true if this
ServiceMonitor has been disposed via
invocation of dispose() . |
boolean |
isMonitoring()
Returns true iff the ServiceMonitor is monitoring a number of
services.
|
protected void |
monitorServices(long cWaitMillis)
Check the service status periodically (keep alive interval), restarting
any stopped services.
|
void |
registerServices(Map<Service,String> mapServices)
Adds a set of
Service s to be monitored providing life support. |
void |
setConfigurableCacheFactory(ConfigurableCacheFactory ccf)
Set the
ConfigurableCacheFactory a ServiceMonitor can
operate with. |
protected void |
start()
Start monitoring the services.
|
void |
stopMonitoring()
Stop monitoring all registered services.
|
void |
unregisterServices(Set<Service> setServices)
Removes the supplied set of
Service s from monitoring. |
protected static final Integer DEFAULT_WAIT_MILLIS
protected volatile boolean m_fStarted
ServiceMonitor
has started.protected Thread m_thread
Thread
we are using for monitoring the services periodically.protected boolean m_fDisposed
ServiceMonitor
has been disposed.protected ConfigurableCacheFactory m_ccf
ConfigurableCacheFactory
instance used to start the service.protected Map<Service,String> m_mapServices
Service
s to be monitored with values being non-scoped service names.protected final long m_cWaitMillis
public SimpleServiceMonitor()
DEFAULT_WAIT_MILLIS
).public SimpleServiceMonitor(long cWaitMillis)
cWaitMillis
- the number of milliseconds in between checking
that the registered services are runningpublic void registerServices(Map<Service,String> mapServices)
Service
s to be monitored providing life support.
If any of the services are not running they are started either via the
configured ConfigurableCacheFactory
iff provided or the
provided Service
.registerServices
in interface ServiceMonitor
mapServices
- a map of Service
s where values are non-scoped
service namespublic void unregisterServices(Set<Service> setServices)
Service
s from monitoring.
Note that the services are not being stopped; they are just removed
from the list of Service
s that are being monitored.unregisterServices
in interface ServiceMonitor
setServices
- the set of Service
s to be removed from monitoringpublic void stopMonitoring()
Service
s that are being monitored.stopMonitoring
in interface ServiceMonitor
public boolean isMonitoring()
isMonitoring
in interface ServiceMonitor
public void setConfigurableCacheFactory(ConfigurableCacheFactory ccf)
ConfigurableCacheFactory
a ServiceMonitor
can
operate with. Setting the ConfigurableCacheFactory
should
be performed prior to registering services or requires a
ServiceMonitor.stopMonitoring()
and ServiceMonitor.registerServices(Map)
call.setConfigurableCacheFactory
in interface ServiceMonitor
ccf
- the ConfigurableCacheFactory
used to start the
servicepublic Thread getThread()
getThread
in interface ServiceMonitor
public void dispose()
Once disposed of the object should no longer be considered to be usable.
Note the Disposable interface is compatible with try-with-resources which will automatically invoke this method.
dispose
in interface com.oracle.coherence.common.base.Disposable
protected void start()
protected void monitorServices(long cWaitMillis)
cWaitMillis
- the number of milliseconds between checksprotected boolean isDisposed()
ServiceMonitor
has been disposed via
invocation of dispose()
.protected void assertNotDisposed()
IllegalStateException
if this monitor has been disposed
via invocation of dispose()
.IllegalStateException
- if this monitor has been disposed