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
Nested ClassesModifier and TypeClassDescriptionprotected classNested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default number of milliseconds between checks for service restart.protected booleanFlag that indicates whether this instance of DefaultCacheServer has called start on the associated services.protected booleanFlag that indicates whether of not the shutdown was initiated.protected List<com.tangosol.application.LifecycleListener> TheLifecycleListeners to be notified of lifecycle events for thisDefaultCacheServer.protected ServiceMonitorThe ServiceMonitor used to monitor services.protected ThreadShutdown hook thread. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a DefaultCacheServer using the provided factory. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLifecycleListener(com.tangosol.application.LifecycleListener listener) Add aLifecycleListenerthat will be notified of lifecycle events for thisDefaultCacheServer.protected static DefaultCacheServerensureInstance(ConfigurableCacheFactory factory) Returns the DefaultCacheServer singleton, creating it if necessary.protected List<com.tangosol.application.LifecycleListener> Returns the list ofLifecycleListeners registered for thisDefaultCacheServer.protected static ConfigurableCacheFactoryGets a ConfigurableCacheFactory based on the default configuration.static DefaultCacheServerReturns the DefaultCacheServer created by a previous invocation ofensureInstance(ConfigurableCacheFactory).protected StringgetServiceBanner(Collection<Service> colService) Return a service banner for a collection of services.protected voidInvoked if starting a service raises an exception.protected voidinitialStartServices(long cWaitMillis) Setup any necessary resources and start all services.booleanReturntrueif thisDefaultCacheServeris monitoring services.booleanReturn theServiceMonitorused by the cache server.static voidEntry 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 voidSet the "services started" flag.protected voidmonitorServices(long cWaitMillis) Check the ServiceMonitor status ensuring it is monitoring services.protected booleanEnsure the DCS instance has shutdown.voidremoveLifecycleListener(com.tangosol.application.LifecycleListener listener) Remove aLifecycleListenerso that it will no longer be notified of lifecycle events for thisDefaultCacheServer.protected voidLog the start message.protected voidreportStarted(Collection<Service> colServices) Log the start message.static voidshutdown()Shutdown the cache server.voidShutdown the DefaultCacheServer and Coherence cluster.static Liststart()Start all services that are declared as requiring an "autostart" in the default configurable factory XML descriptor.static Liststart(ConfigurableCacheFactory factory) Start all services that are declared as requiring an "autostart" in the configurable factory XML descriptor.voidstartAndMonitor(long cWaitMillis) Start the cache server and check the service status periodically, restarting any stopped services.static voidDeprecated.voidstartDaemon(long cWaitMillis) Start the cache server and asynchronously check the service status periodically, restarting any services that have stopped.protected static voidStart the provided cache server on a dedicated daemon thread.static DefaultCacheServerStart the cache server on a dedicated daemon thread, using defaultConfigurableCacheFactory.static DefaultCacheServerStart 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.voidstop()Stop this DefaultCacheServer and dispose theConfigurableCacheFactorythat this server wraps.protected booleanEnsures the DCS instance has shutdown and the associated ServiceMonitor is no longer monitoring services.protected voidStop the ServiceMonitor.voidBlock 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, newHashMap, newHashMap, newHashSet, newHashSet, 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
TheLifecycleListeners to be notified of lifecycle events for thisDefaultCacheServer.The
LifecycleListeners 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 aLifecycleListenerthat will be notified of lifecycle events for thisDefaultCacheServer.- Parameters:
listener- the listener to add
-
removeLifecycleListener
public void removeLifecycleListener(com.tangosol.application.LifecycleListener listener) Remove aLifecycleListenerso that it will no longer be notified of lifecycle events for thisDefaultCacheServer.Listeners are stored in a
Listand 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 theConfigurableCacheFactorythat 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
DefaultCacheServerstarted - 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- theConfigurableCacheFactoryto use- Returns:
- the instance of the
DefaultCacheServerstarted - 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 ofLifecycleListeners registered for thisDefaultCacheServer.If the list of listeners does not yet exist it will be created and initially populated using the
ServiceLoaderto discover and load listeners.- Returns:
- the list of
LifecycleListeners 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 theServiceMonitorused by the cache server.- Returns:
- the ServiceMonitor
-
isMonitoringServices
public boolean isMonitoringServices()Returntrueif thisDefaultCacheServeris monitoring services.- Returns:
trueif thisDefaultCacheServeris 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