Package com.tangosol.net
Class DefaultCacheServer
- java.lang.Object
 - 
- com.tangosol.util.Base
 - 
- com.tangosol.net.DefaultCacheServer
 
 
 
- 
- Direct Known Subclasses:
 DefaultCacheServer.GarServer
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 static classDefaultCacheServer.GarServerGarServer provides the functionality of DefaultCacheServer under the context of a GAR file.protected classDefaultCacheServer.LifecycleContextstatic classDefaultCacheServer.SimpleContextSimple ContainerContext implementation.- 
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter 
 - 
 
- 
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_WAIT_MILLISThe default number of milliseconds between checks for service restart.protected booleanm_fServicesStartedFlag that indicates whether this instance of DefaultCacheServer has called start on the associated services.protected booleanm_fShutdownFlag that indicates whether of not the shutdown was initiated.protected List<LifecycleListener>m_listLifecycleListenerTheLifecycleListeners to be notified of lifecycle events for thisDefaultCacheServer.protected ServiceMonitorm_serviceMonThe ServiceMonitor used to monitor services.protected Threadm_threadShutdownShutdown 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 voidaddLifecycleListener(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 static DefaultCacheServer.GarServerensureInstance(File fileGar, String sAppName, String[] asTenant)Returns the GarServer singleton, creating it if necessary.protected List<LifecycleListener>ensureLifecycleListeners()Returns the list ofLifecycleListeners registered for thisDefaultCacheServer.protected static ConfigurableCacheFactorygetConfigurableCacheFactory()Gets a ConfigurableCacheFactory based on the default configuration.static DefaultCacheServergetInstance()Returns the DefaultCacheServer created by a previous invocation ofensureInstance(ConfigurableCacheFactory).protected StringgetServiceBanner(Collection<Service> colService)Return a service banner for a collection of services.protected voidhandleEnsureServiceException(RuntimeException e)Invoked if starting a service raises an exception.protected voidinitialStartServices(long cWaitMillis)Setup any necessary resources and start all services.protected ContainerContextinstantiateContext(String sTenant, ContainerAdapter adapter)Factory pattern: instantiate the SimpleContextbooleanisMonitoringServices()Returntrueif thisDefaultCacheServeris monitoring services.booleanisMonitorStopped()Return theServiceMonitorused by the cache server.static voidmain(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 voidmarkServicesStarted()Set the "services started" flag.protected voidmonitorServices(long cWaitMillis)Check the ServiceMonitor status ensuring it is monitoring services.protected booleannotifyShutdown()Ensure the DCS instance has shutdown.voidremoveLifecycleListener(LifecycleListener listener)Remove aLifecycleListenerso that it will no longer be notified of lifecycle events for thisDefaultCacheServer.protected voidreportStarted()Log the start message.protected voidreportStarted(Collection<Service> colServices)Log the start message.static voidshutdown()Shutdown the cache server.voidshutdownServer()Shutdown 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 voidstartDaemon()Deprecated.usestartServerDaemon()insteadvoidstartDaemon(long cWaitMillis)Start the cache server and asynchronously check the service status periodically, restarting any services that have stopped.protected static voidstartDaemon(DefaultCacheServer dcs)Start the provided cache server on a dedicated daemon thread.static voidstartDaemon(File fileGar)Deprecated.usestartServerDaemon(File)insteadstatic voidstartDaemon(File fileGar, String sAppName)Deprecated.usestartServerDaemon(File, String)insteadstatic DefaultCacheServerstartServerDaemon()Start the cache server on a dedicated daemon thread, using defaultConfigurableCacheFactory.static DefaultCacheServerstartServerDaemon(ConfigurableCacheFactory ccf)Start the cache server on a dedicated daemon thread, using specifiedConfigurableCacheFactory.static DefaultCacheServer.GarServerstartServerDaemon(File fileGar)Start the cache server on a dedicated daemon thread using the given File reference to a GAR.static DefaultCacheServer.GarServerstartServerDaemon(File fileGar, String sAppName)Start the cache server on a dedicated daemon thread using the given File reference to a GAR.static DefaultCacheServer.GarServerstartServerDaemon(File fileGar, String sAppName, String[] asTenant)Start the cache server on a dedicated daemon thread using the given File reference to a GAR.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.voidstop()Stop this DefaultCacheServer and dispose theConfigurableCacheFactorythat this server wraps.protected booleanstopMonitoring()Ensures the DCS instance has shutdown and the associated ServiceMonitor is no longer monitoring services.protected voidstopServiceMonitor()Stop the ServiceMonitor.voidwaitForServiceStart()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<LifecycleListener> m_listLifecycleListener
TheLifecycleListeners to be notified of lifecycle events for thisDefaultCacheServer.The
LifecycleListeners 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(LifecycleListener listener)
Add aLifecycleListenerthat will be notified of lifecycle events for thisDefaultCacheServer.- Parameters:
 listener- the listener to add
 
- 
removeLifecycleListener
public void removeLifecycleListener(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
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 theConfigurableCacheFactorythat 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
 
 
- 
startDaemon
public static void startDaemon(File fileGar)
Deprecated.usestartServerDaemon(File)insteadStart the cache server on a dedicated daemon thread using the given File reference to a GAR. The file reference may be to a GAR file complying to the GAR file structure or a directory containing contents complying to the same structure. This method is intended to be used within managed containers.- Parameters:
 fileGar- file reference to either a GAR file or a directory containing the contents of the GAR- Since:
 - Coherence 12.1.2
 
 
- 
startDaemon
public static void startDaemon(File fileGar, String sAppName)
Deprecated.usestartServerDaemon(File, String)insteadStart the cache server on a dedicated daemon thread using the given File reference to a GAR. The file reference may be to a GAR file complying to the GAR file structure or a directory containing contents complying to the same structure. This method is intended to be used within managed containers.- Parameters:
 fileGar- file reference to either a GAR file or a directory containing the contents of the GARsAppName- name to be used for the application- Since:
 - Coherence 12.1.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 
DefaultCacheServerstarted - 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- theConfigurableCacheFactoryto use- Returns:
 - the instance of the 
DefaultCacheServerstarted - Since:
 - 20.06
 
 
- 
startServerDaemon
public static DefaultCacheServer.GarServer startServerDaemon(File fileGar)
Start the cache server on a dedicated daemon thread using the given File reference to a GAR. The file reference may be to a GAR file complying to the GAR file structure or a directory containing contents complying to the same structure. This method is intended to be used within managed containers.- Parameters:
 fileGar- file reference to either a GAR file or a directory containing the contents of the GAR- Returns:
 - an instance of the 
DefaultCacheServer.GarServerstarted - Since:
 - Coherence 12.1.2
 
 
- 
startServerDaemon
public static DefaultCacheServer.GarServer startServerDaemon(File fileGar, String sAppName)
Start the cache server on a dedicated daemon thread using the given File reference to a GAR. The file reference may be to a GAR file complying to the GAR file structure or a directory containing contents complying to the same structure. This method is intended to be used within managed containers.- Parameters:
 fileGar- file reference to either a GAR file or a directory containing the contents of the GARsAppName- name to be used for the application- Returns:
 - an instance of the 
DefaultCacheServer.GarServerstarted - Since:
 - Coherence 12.1.2
 
 
- 
startServerDaemon
public static DefaultCacheServer.GarServer startServerDaemon(File fileGar, String sAppName, String[] asTenant)
Start the cache server on a dedicated daemon thread using the given File reference to a GAR. The file reference may be to a GAR file complying to the GAR file structure or a directory containing contents complying to the same structure. This method is intended to be used within managed containers.- Parameters:
 fileGar- file reference to either a GAR file or a directory containing the contents of the GARsAppName- name to be used for the applicationasTenant- (optional) Domain Partition names- Returns:
 - an instance of the 
DefaultCacheServer.GarServerstarted - Since:
 - Coherence 12.2.1
 
 
- 
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<LifecycleListener> 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
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 theServiceMonitorused by the cache server.- Returns:
 - the ServiceMonitor
 
 
- 
isMonitoringServices
public boolean isMonitoringServices()
Returntrueif thisDefaultCacheServeris monitoring services.- Returns:
 trueif thisDefaultCacheServeris 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
 
 
- 
ensureInstance
protected static DefaultCacheServer.GarServer ensureInstance(File fileGar, String sAppName, String[] asTenant)
Returns the GarServer singleton, creating it if necessary.- Parameters:
 fileGar- file reference to either a GAR file or a directory containing the contents of the GARsAppName- application nameasTenant- (optional) Domain Partition names- Returns:
 - the GarServer 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
 
 
- 
instantiateContext
protected ContainerContext instantiateContext(String sTenant, ContainerAdapter adapter)
Factory pattern: instantiate the SimpleContext- Parameters:
 sTenant- the domain partition nameadapter- the corresponding adapter- Returns:
 - a new instance of the context
 
 
 - 
 
 -