Package com.tangosol.net
Class DefaultCacheServer
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.net.DefaultCacheServer
-
public class DefaultCacheServer extends Base
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 Classes Modifier and Type Class Description protected class
DefaultCacheServer.LifecycleContext
-
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_WAIT_MILLIS
The default number of milliseconds between checks for service restart.protected boolean
m_fServicesStarted
Flag that indicates whether this instance of DefaultCacheServer has called start on the associated services.protected boolean
m_fShutdown
Flag that indicates whether of not the shutdown was initiated.protected List<com.tangosol.application.LifecycleListener>
m_listLifecycleListener
TheLifecycleListener
s to be notified of lifecycle events for thisDefaultCacheServer
.protected ServiceMonitor
m_serviceMon
The ServiceMonitor used to monitor services.protected Thread
m_threadShutdown
Shutdown hook thread.
-
Constructor Summary
Constructors Constructor Description DefaultCacheServer(ConfigurableCacheFactory factory)
Construct a DefaultCacheServer using the provided factory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
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>
ensureLifecycleListeners()
Returns the list ofLifecycleListener
s registered for thisDefaultCacheServer
.protected static ConfigurableCacheFactory
getConfigurableCacheFactory()
Gets a ConfigurableCacheFactory based on the default configuration.static DefaultCacheServer
getInstance()
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
handleEnsureServiceException(RuntimeException e)
Invoked if starting a service raises an exception.protected void
initialStartServices(long cWaitMillis)
Setup any necessary resources and start all services.boolean
isMonitoringServices()
Returntrue
if thisDefaultCacheServer
is monitoring services.boolean
isMonitorStopped()
Return theServiceMonitor
used by the cache server.static void
main(String[] asArg)
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
markServicesStarted()
Set the "services started" flag.protected void
monitorServices(long cWaitMillis)
Check the ServiceMonitor status ensuring it is monitoring services.protected boolean
notifyShutdown()
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
reportStarted()
Log the start message.protected void
reportStarted(Collection<Service> colServices)
Log the start message.static void
shutdown()
Shutdown the cache server.void
shutdownServer()
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
startDaemon()
Deprecated.usestartServerDaemon()
insteadvoid
startDaemon(long cWaitMillis)
Start the cache server and asynchronously check the service status periodically, restarting any services that have stopped.protected static void
startDaemon(DefaultCacheServer dcs)
Start the provided cache server on a dedicated daemon thread.static DefaultCacheServer
startServerDaemon()
Start the cache server on a dedicated daemon thread, using defaultConfigurableCacheFactory
.static DefaultCacheServer
startServerDaemon(ConfigurableCacheFactory ccf)
Start the cache server on a dedicated daemon thread, using specifiedConfigurableCacheFactory
.List<Service>
startServices()
Start all services that are declared as requiring an "autostart" in the configurable factory XML descriptor.protected Map<Service,String>
startServicesInternal()
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
stopMonitoring()
Ensures the DCS instance has shutdown and the associated ServiceMonitor is no longer monitoring services.protected void
stopServiceMonitor()
Stop the ServiceMonitor.void
waitForServiceStart()
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 Detail
-
DEFAULT_WAIT_MILLIS
public static final long DEFAULT_WAIT_MILLIS
The default number of milliseconds between checks for service restart.- See Also:
- Constant Field Values
-
m_serviceMon
protected volatile ServiceMonitor m_serviceMon
The ServiceMonitor used to monitor services.
-
m_fShutdown
protected volatile boolean m_fShutdown
Flag that indicates whether of not the shutdown was initiated.
-
m_fServicesStarted
protected boolean m_fServicesStarted
Flag that indicates whether this instance of DefaultCacheServer has called start on the associated services.- See Also:
initialStartServices(long)
-
m_threadShutdown
protected Thread m_threadShutdown
Shutdown hook thread.
-
m_listLifecycleListener
protected List<com.tangosol.application.LifecycleListener> m_listLifecycleListener
TheLifecycleListener
s to be notified of lifecycle events for thisDefaultCacheServer
.The
LifecycleListener
s will be discovered and loaded using theServiceLoader
.
-
-
Constructor Detail
-
DefaultCacheServer
public DefaultCacheServer(ConfigurableCacheFactory factory)
Construct a DefaultCacheServer using the provided factory.- Parameters:
factory
- the ConfigurableCacheFactory
-
-
Method Detail
-
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
public List<Service> 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:
ConfigurableCacheFactory.dispose()
-
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
public static DefaultCacheServer 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
public static DefaultCacheServer startServerDaemon(ConfigurableCacheFactory ccf)
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
public static void main(String[] asArg)
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
public static List 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
public static List start(ConfigurableCacheFactory factory)
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
protected List<com.tangosol.application.LifecycleListener> 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
protected void reportStarted(Collection<Service> colServices)
Log the start message.- Parameters:
colServices
- the collection of started services
-
startServicesInternal
protected Map<Service,String> 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
protected void handleEnsureServiceException(RuntimeException e)
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:
startServices()
-
getServiceBanner
protected String getServiceBanner(Collection<Service> colService)
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
protected static void startDaemon(DefaultCacheServer dcs)
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
protected static ConfigurableCacheFactory getConfigurableCacheFactory()
Gets a ConfigurableCacheFactory based on the default configuration.- Returns:
- a ConfigurableCacheFactory
-
ensureInstance
protected static DefaultCacheServer ensureInstance(ConfigurableCacheFactory factory)
Returns the DefaultCacheServer singleton, creating it if necessary.- Parameters:
factory
- the CacheFactory to use- Returns:
- the DefaultCacheServer singleton
-
getInstance
public static DefaultCacheServer getInstance()
Returns the DefaultCacheServer created by a previous invocation ofensureInstance(ConfigurableCacheFactory)
. Will throw an IllegalStateException if there is no instance.- Returns:
- the DefaultCacheServer
-
-