Package com.tangosol.net
Class DefaultCacheServer
java.lang.Object
com.tangosol.util.Base
com.tangosol.net.DefaultCacheServer
DefaultCacheServer is a simple command line facility and convenience API
that starts all services that are declared as requiring an "autostart" in
the configurable factory XML descriptor.
DefaultCacheServer can also monitor services it started to ensure they exist. Monitoring services is enabled by default.
- Since:
- Coherence 2.2
- Author:
- gg/yc/hr
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
The default number of milliseconds between checks for service restart.protected boolean
Flag that indicates whether this instance of DefaultCacheServer has called start on the associated services.protected boolean
Flag that indicates whether of not the shutdown was initiated.protected List
<com.tangosol.application.LifecycleListener> TheLifecycleListener
s to be notified of lifecycle events for thisDefaultCacheServer
.protected ServiceMonitor
The ServiceMonitor used to monitor services.protected Thread
Shutdown hook thread. -
Constructor Summary
ConstructorDescriptionConstruct a DefaultCacheServer using the provided factory. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLifecycleListener
(com.tangosol.application.LifecycleListener listener) Add aLifecycleListener
that will be notified of lifecycle events for thisDefaultCacheServer
.protected static DefaultCacheServer
ensureInstance
(ConfigurableCacheFactory factory) Returns the DefaultCacheServer singleton, creating it if necessary.protected List
<com.tangosol.application.LifecycleListener> Returns the list ofLifecycleListener
s registered for thisDefaultCacheServer
.protected static ConfigurableCacheFactory
Gets a ConfigurableCacheFactory based on the default configuration.static DefaultCacheServer
Returns the DefaultCacheServer created by a previous invocation ofensureInstance(ConfigurableCacheFactory)
.protected String
getServiceBanner
(Collection<Service> colService) Return a service banner for a collection of services.protected void
Invoked if starting a service raises an exception.protected void
initialStartServices
(long cWaitMillis) Setup any necessary resources and start all services.boolean
Returntrue
if thisDefaultCacheServer
is monitoring services.boolean
Return theServiceMonitor
used by the cache server.static void
Entry point: start the cache server under two possible contexts: With a "coherence-cache-config.xsd" compliant configuration file. With a GAR file or a directory containing the contents of a GAR file and optionally an application name and comma-delimited list of tenant names. If both are provided the latter takes precedence.protected void
Set the "services started" flag.protected void
monitorServices
(long cWaitMillis) Check the ServiceMonitor status ensuring it is monitoring services.protected boolean
Ensure the DCS instance has shutdown.void
removeLifecycleListener
(com.tangosol.application.LifecycleListener listener) Remove aLifecycleListener
so that it will no longer be notified of lifecycle events for thisDefaultCacheServer
.protected void
Log the start message.protected void
reportStarted
(Collection<Service> colServices) Log the start message.static void
shutdown()
Shutdown the cache server.void
Shutdown the DefaultCacheServer and Coherence cluster.static List
start()
Start all services that are declared as requiring an "autostart" in the default configurable factory XML descriptor.static List
start
(ConfigurableCacheFactory factory) Start all services that are declared as requiring an "autostart" in the configurable factory XML descriptor.void
startAndMonitor
(long cWaitMillis) Start the cache server and check the service status periodically, restarting any stopped services.static void
Deprecated.void
startDaemon
(long cWaitMillis) Start the cache server and asynchronously check the service status periodically, restarting any services that have stopped.protected static void
Start the provided cache server on a dedicated daemon thread.static DefaultCacheServer
Start the cache server on a dedicated daemon thread, using defaultConfigurableCacheFactory
.static DefaultCacheServer
Start the cache server on a dedicated daemon thread, using specifiedConfigurableCacheFactory
.Start all services that are declared as requiring an "autostart" in the configurable factory XML descriptor.Starts the services marked with autostart returning a map of a service name to the started service.void
stop()
Stop this DefaultCacheServer and dispose theConfigurableCacheFactory
that this server wraps.protected boolean
Ensures the DCS instance has shutdown and the associated ServiceMonitor is no longer monitoring services.protected void
Stop the ServiceMonitor.void
Block the calling thread until DefaultCacheServer has called start on all associated services.Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
Field Details
-
DEFAULT_WAIT_MILLIS
public static final long DEFAULT_WAIT_MILLISThe default number of milliseconds between checks for service restart.- See Also:
-
m_serviceMon
The ServiceMonitor used to monitor services. -
m_fShutdown
protected volatile boolean m_fShutdownFlag that indicates whether of not the shutdown was initiated. -
m_fServicesStarted
protected boolean m_fServicesStartedFlag that indicates whether this instance of DefaultCacheServer has called start on the associated services.- See Also:
-
m_threadShutdown
Shutdown hook thread. -
m_listLifecycleListener
TheLifecycleListener
s to be notified of lifecycle events for thisDefaultCacheServer
.The
LifecycleListener
s will be discovered and loaded using theServiceLoader
.
-
-
Constructor Details
-
DefaultCacheServer
Construct a DefaultCacheServer using the provided factory.- Parameters:
factory
- the ConfigurableCacheFactory
-
-
Method Details
-
addLifecycleListener
public void addLifecycleListener(com.tangosol.application.LifecycleListener listener) Add aLifecycleListener
that will be notified of lifecycle events for thisDefaultCacheServer
.- Parameters:
listener
- the listener to add
-
removeLifecycleListener
public void removeLifecycleListener(com.tangosol.application.LifecycleListener listener) Remove aLifecycleListener
so that it will no longer be notified of lifecycle events for thisDefaultCacheServer
.Listeners are stored in a
List
and will be removed based on a simple object equality check.- Parameters:
listener
- the listener to remove
-
startAndMonitor
public void startAndMonitor(long cWaitMillis) Start the cache server and check the service status periodically, restarting any stopped services.This method will block the calling thread.
- Parameters:
cWaitMillis
- the number of milliseconds between checks
-
startDaemon
public void startDaemon(long cWaitMillis) Start the cache server and asynchronously check the service status periodically, restarting any services that have stopped.- Parameters:
cWaitMillis
- the number of milliseconds between checks- Since:
- Coherence 12.1.2
-
startServices
Start all services that are declared as requiring an "autostart" in the configurable factory XML descriptor.- Returns:
- list of services that have been successfully started
-
shutdownServer
public void shutdownServer()Shutdown the DefaultCacheServer and Coherence cluster. -
stop
public void stop()Stop this DefaultCacheServer and dispose theConfigurableCacheFactory
that this server wraps.- See Also:
-
waitForServiceStart
public void waitForServiceStart()Block the calling thread until DefaultCacheServer has called start on all associated services. Upon control being returned services may not be running due to possible error on start or concurrent shutdown.- Throws:
IllegalStateException
- iff the services were not attempted to be started, which could be due to concurrent shutdown
-
markServicesStarted
protected void markServicesStarted()Set the "services started" flag. -
shutdown
public static void shutdown()Shutdown the cache server.- Since:
- Coherence 3.2
-
startDaemon
public static void startDaemon()Deprecated.usestartServerDaemon()
insteadStart the cache server on a dedicated daemon thread. This method is intended to be used within managed containers.- Since:
- Coherence 3.2
-
startServerDaemon
Start the cache server on a dedicated daemon thread, using defaultConfigurableCacheFactory
. This method is intended to be used within managed containers.- Returns:
- the instance of the
DefaultCacheServer
started - Since:
- Coherence 12.1.2
-
startServerDaemon
Start the cache server on a dedicated daemon thread, using specifiedConfigurableCacheFactory
. This method is intended to be used within managed containers.- Parameters:
ccf
- theConfigurableCacheFactory
to use- Returns:
- the instance of the
DefaultCacheServer
started - Since:
- 20.06
-
main
Entry point: start the cache server under two possible contexts:- With a "coherence-cache-config.xsd" compliant configuration file.
- With a GAR file or a directory containing the contents of a GAR file and optionally an application name and comma-delimited list of tenant names.
Default configuration file is "coherence-cache-config.xml"; default keep alive interval is 5 sec.
Example: java -server -Xms512m -Xmx512m com.tangosol.net.DefaultCacheServer cache-config.xml 5 GAR Example: java -server -Xms512m -Xmx512m com.tangosol.net.DefaultCacheServer my-app.gar MyApp 5
- Parameters:
asArg
- the command line arguments
-
start
Start all services that are declared as requiring an "autostart" in the default configurable factory XML descriptor.This method will not create a ServiceMonitor for started services.
- Returns:
- list of services that have been successfully started
-
start
Start all services that are declared as requiring an "autostart" in the configurable factory XML descriptor.This method will not create a ServiceMonitor for started services.
- Parameters:
factory
- ConfigurableCacheFactory to use- Returns:
- list of services that have been successfully started
-
stopMonitoring
protected boolean stopMonitoring()Ensures the DCS instance has shutdown and the associated ServiceMonitor is no longer monitoring services. return true if the monitoring was active and has been stopped as a result of this call; false if the monitoring was not active -
stopServiceMonitor
protected void stopServiceMonitor()Stop the ServiceMonitor. -
notifyShutdown
protected boolean notifyShutdown()Ensure the DCS instance has shutdown. return true if DCS instance was called to start on the associated services -
initialStartServices
protected void initialStartServices(long cWaitMillis) Setup any necessary resources and start all services.- Parameters:
cWaitMillis
- the interval, in milliseconds, to monitor services
-
ensureLifecycleListeners
Returns the list ofLifecycleListener
s registered for thisDefaultCacheServer
.If the list of listeners does not yet exist it will be created and initially populated using the
ServiceLoader
to discover and load listeners.- Returns:
- the list of
LifecycleListener
s registered for thisDefaultCacheServer
-
reportStarted
protected void reportStarted()Log the start message. -
reportStarted
Log the start message.- Parameters:
colServices
- the collection of started services
-
startServicesInternal
Starts the services marked with autostart returning a map of a service name to the started service.- Returns:
- a map holding all started services keyed by names
-
monitorServices
protected void monitorServices(long cWaitMillis) Check the ServiceMonitor status ensuring it is monitoring services. This method blocks the caller's thread until the DefaultCacheServer is shutdown and monitoring stops.- Parameters:
cWaitMillis
- the number of milliseconds between checks
-
handleEnsureServiceException
Invoked if starting a service raises an exception. Re-throws the exception. Override, for example, to log the exception and continue starting services.- Parameters:
e
- the RuntimeException- See Also:
-
getServiceBanner
Return a service banner for a collection of services.- Parameters:
colService
- the collection of services- Returns:
- a service banner for a collection of services
-
isMonitorStopped
public boolean isMonitorStopped()Return theServiceMonitor
used by the cache server.- Returns:
- the ServiceMonitor
-
isMonitoringServices
public boolean isMonitoringServices()Returntrue
if thisDefaultCacheServer
is monitoring services.- Returns:
true
if thisDefaultCacheServer
is monitoring services
-
startDaemon
Start the provided cache server on a dedicated daemon thread. This method is intended to be used within managed containers.- Parameters:
dcs
- the cache server to start
-
getConfigurableCacheFactory
Gets a ConfigurableCacheFactory based on the default configuration.- Returns:
- a ConfigurableCacheFactory
-
ensureInstance
Returns the DefaultCacheServer singleton, creating it if necessary.- Parameters:
factory
- the CacheFactory to use- Returns:
- the DefaultCacheServer singleton
-
getInstance
Returns the DefaultCacheServer created by a previous invocation ofensureInstance(ConfigurableCacheFactory)
. Will throw an IllegalStateException if there is no instance.- Returns:
- the DefaultCacheServer
-
startServerDaemon()
instead