Class Coherence
- All Implemented Interfaces:
 AutoCloseable
Coherence instance encapsulates and controls one or more
 Session instances.
 
 A Coherence instance is typically created from a CoherenceConfiguration
 which contains one or more SessionConfiguration instances.
 The Coherence instance is then started which in turn creates
 and starts the configured Sessions.
 When the Coherence instance is closed all of the Session
 instances being managed are also closed.
 
 An example of creating and starting a Coherence instance is shown below:
 
    SessionConfiguration session = SessionConfiguration.builder()
            .named("Prod")
            .withConfigUri("cache-config.xml")
            .build();
    CoherenceConfiguration cfg = CoherenceConfiguration.builder()
            .withSession(SessionConfiguration.defaultSession())
            .withSession(session)
            .build();
    Coherence coherence = Coherence.create(cfg);
    coherence.start();
 - Since:
 - 20.12
 - Author:
 - Jonathan Knight 2020.10.26
 - See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder to buildCoherenceinstances.static interfaceAn interface implemented by listeners ofCoherenceLifecycleEvents.static enumAn enum representing the different modes that aCoherenceinstance can run in. - 
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default session name.static final StringThe default scope name.static final com.oracle.coherence.common.util.DurationThe default start up timeout.static final StringThe system property to use to set the default timeout to wait for Coherence instances to start.static final StringThe name of the System configuration uri.static final StringThe System scope name.static final StringThe System session name. - 
Method Summary
Modifier and TypeMethodDescriptionaddSession(SessionConfiguration config) addSessionIfAbsent(String sName, Supplier<SessionConfiguration> supplier) static Coherence.Builderbuilder(CoherenceConfiguration config) Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.static Coherence.Builderbuilder(CoherenceConfiguration config, Coherence.Mode mode) Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.static Coherenceclient()Return the defaultCoherenceclient instance, creating it if it does not already exist.static Coherenceclient(Coherence.Mode mode) Return the defaultCoherenceclient instance, creating it if it does not already exist.static Coherenceclient(CoherenceConfiguration config) Create a clientCoherenceinstance from the specifiedCoherenceConfiguration.static Coherence.BuilderclientBuilder(CoherenceConfiguration config) Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.static Coherence.BuilderclientBuilder(CoherenceConfiguration config, Coherence.Mode mode) Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.voidclose()Close thisCoherenceinstance.static voidcloseAll()Close allCoherenceinstances.static CoherenceReturn the defaultCoherencecluster member instance, creating it if it does not already exist.static CoherenceclusterMember(CoherenceConfiguration config) Create aCoherenceinstance from the specifiedCoherenceConfiguration.static Coherence.BuilderReturns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.static Coherencecreate()Return the defaultCoherenceinstance, creating it if it does not already exist.static Coherencecreate(CoherenceConfiguration config) Create a defaultCoherenceinstance.static Coherencecreate(CoherenceConfiguration config, Coherence.Mode mode) Create a defaultCoherenceinstance.static Coherencecreate(CoherenceConfiguration config, Coherence.Mode mode, ClassLoader loader) Create a defaultCoherenceinstance.findSession(String sName) static Collection<Session> findSessionsByScope(String sScope) static CoherenceCreate a defaultCoherenceclient instance, creating it if it does not already exist.static CoherencefixedClient(CoherenceConfiguration config) Create a clientCoherenceinstance from the specifiedCoherenceConfiguration.static Coherence.BuilderReturns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.Return aClusterobject for Coherence services.Returns the configuration used by thisCoherenceinstance.static Coherencestatic CoherencegetInstance(ClassLoader loader) static CoherencegetInstance(String sName) static CoherencegetInstance(String sName, ClassLoader loader) static Collection<Coherence> Returns all of theCoherenceinstances.static Collection<Coherence> getInstances(ClassLoader loader) Returns all of theCoherenceinstances.Return theInterceptorRegistryfor thisCoherenceinstance.Returns the current management registry.getMode()Return theCoherence.Modethat this instance is running as.getName()Returns the name of thisCoherenceinstance.Return theResourceRegistryfor thisCoherenceinstance.getSession(String sName) getSessionIfPresent(String sName) Return a set of session names that thisCoherenceinstance has.Return a set of session scope names that thisCoherenceinstance has.getSessionsWithScope(String sScope) booleanhasSession(String sName) booleanisActive()booleanisClosed()Returntrueif thisCoherenceinstance has been closed.booleanReturntrueif thisCoherenceinstance has been started.static voidStart a Coherence server.protected static voidremoveInstance(String sName) protected static voidremoveInstance(String sName, ClassLoader loader) start()Asynchronously start thisCoherenceinstance.Start thisCoherenceinstance and block until Coherence has started.startAndWait(com.oracle.coherence.common.util.Duration timeout) Start thisCoherenceinstance and block until Coherence has started.voidStart thisCoherenceinstance.toString()Obtain aCompletableFuturethat will be completed when thisCoherenceinstance has closed.Obtain aCompletableFuturethat will be completed when thisCoherenceinstance has started. 
- 
Field Details
- 
SYS_CCF_URI
The name of the System configuration uri.- See Also:
 
 - 
SYSTEM_SCOPE
The System scope name.- See Also:
 
 - 
SYSTEM_SESSION
The System session name.- See Also:
 
 - 
DEFAULT_SCOPE
The default scope name.- See Also:
 
 - 
DEFAULT_NAME
The default session name.- See Also:
 
 - 
PROP_START_TIMEOUT
The system property to use to set the default timeout to wait for Coherence instances to start.- See Also:
 
 - 
DEFAULT_START_TIMEOUT
public static final com.oracle.coherence.common.util.Duration DEFAULT_START_TIMEOUTThe default start up timeout. 
 - 
 - 
Method Details
- 
create
Return the defaultCoherenceinstance, creating it if it does not already exist.- Returns:
 - a default 
Coherenceinstance 
 - 
create
Create a defaultCoherenceinstance. - 
create
Create a defaultCoherenceinstance.- Parameters:
 config- the configuration to use to create theCoherenceinstancemode- theCoherence.ModetheCoherenceinstance will run in- Returns:
 - a default 
Coherenceinstance 
 - 
create
public static Coherence create(CoherenceConfiguration config, Coherence.Mode mode, ClassLoader loader) Create a defaultCoherenceinstance.- Parameters:
 config- the configuration to use to create theCoherenceinstancemode- theCoherence.ModetheCoherenceinstance will run inloader- theClassLoaderassociated with theCoherenceinstance- Returns:
 - a default 
Coherenceinstance 
 - 
builder
Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.The
Coherenceinstance built by theBuilderwill be a cluster member. Coherence auto-start services will be managed by aDefaultCacheServerinstance for each configured session.- Parameters:
 config- theCoherenceConfigurationto use to build theCoherenceinstance- Returns:
 - a 
Coherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration 
 - 
builder
Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.The
Coherenceinstance built by theBuilderwill be a cluster member. Coherence auto-start services will be managed by aDefaultCacheServerinstance for each configured session.- Parameters:
 config- theCoherenceConfigurationto use to build theCoherenceinstancemode- theCoherence.ModetheCoherenceinstance will run in- Returns:
 - a 
Coherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration 
 - 
clusterMember
Return the defaultCoherencecluster member instance, creating it if it does not already exist.The
Coherenceinstance built by theBuilderwill be a cluster member.- Returns:
 - a default 
Coherenceinstance 
 - 
clusterMember
Create aCoherenceinstance from the specifiedCoherenceConfiguration.The
Coherenceinstance built by theBuilderwill be a cluster member.- Parameters:
 config- the configuration to use to create theCoherenceinstance- Returns:
 - a 
Coherenceinstance from the specifiedCoherenceConfiguration 
 - 
client
Return the defaultCoherenceclient instance, creating it if it does not already exist.If using the default Coherence cache configuration file, this will configure Coherence to be an Extend client.
If using the default Coherence Concurrent extensions, this will configure Coherence Concurrent to be an Extend client.
- Returns:
 - a default 
Coherenceinstance 
 - 
client
Return the defaultCoherenceclient instance, creating it if it does not already exist.If using the default Coherence cache configuration file, this will configure Coherence to be an Extend client.
If using the default Coherence Concurrent extensions, this will configure Coherence Concurrent to be an Extend client.
- Parameters:
 mode- the default mode to run the Coherence instance- Returns:
 - a default 
Coherenceinstance 
 - 
client
Create a clientCoherenceinstance from the specifiedCoherenceConfiguration.If using the default Coherence cache configuration file, this will configure Coherence to be an Extend client.
If using the default Coherence Concurrent extensions, this will configure Coherence Concurrent to be an Extend client.
- Parameters:
 config- the configuration to use to create theCoherenceinstance- Returns:
 - a 
Coherenceinstance from the specifiedCoherenceConfiguration 
 - 
fixedClient
Create a defaultCoherenceclient instance, creating it if it does not already exist.If using the default Coherence cache configuration file, this will configure Coherence to be an Extend client.
If using the default Coherence cache configuration file, this will configure Coherence to be an Extend client using a fixed address configured with the parameters
coherence.extend.addressandcoherence.extend.port.- Returns:
 - a default 
Coherenceinstance 
 - 
fixedClient
Create a clientCoherenceinstance from the specifiedCoherenceConfiguration.If using the default Coherence cache configuration file, this will configure Coherence to be an Extend client.
If using the default Coherence cache configuration file, this will configure Coherence to be an Extend client using a fixed address configured with the parameters
coherence.extend.addressandcoherence.extend.port.- Parameters:
 config- the configuration to use to create theCoherenceinstance- Returns:
 - a 
Coherenceinstance from the specifiedCoherenceConfiguration 
 - 
clusterMemberBuilder
Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.The
Coherenceinstance built by theBuilderwill be a cluster member. Coherence auto-start services will be managed by aDefaultCacheServerinstance for each configured session.- Returns:
 - a 
Coherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration 
 - 
clientBuilder
Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.The
Coherenceinstance built by theBuilderwill be a client, it will not start or join a Coherence cluster.If using the default Coherence cache configuration file, this will configure Coherence to be an Extend client.
If using the default Coherence Concurrent extensions, this will configure Coherence Concurrent to be an Extend client.
- Parameters:
 config- theCoherenceConfigurationto configure theCoherenceinstance- Returns:
 - a 
Coherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration 
 - 
clientBuilder
Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.The
Coherenceinstance built by theBuilderwill be a client, it will not start or join a Coherence cluster.If using the default Coherence cache configuration file, this will configure Coherence to be an Extend client.
If using the default Coherence Concurrent extensions, this will configure Coherence Concurrent to be an Extend client.
- Parameters:
 config- theCoherenceConfigurationto configure theCoherenceinstancemode- the default mode to run the Coherence instance- Returns:
 - a 
Coherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration 
 - 
fixedClientBuilder
Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.The
Coherenceinstance built by theBuilderwill be a client using a fixed Extend address, it will not start or join a Coherence cluster.If using the default Coherence cache configuration file, this will configure Coherence to be an Extend client using a fixed address configured with the parameters
coherence.extend.addressandcoherence.extend.port.If using the default Coherence Concurrent extensions, this will configure Coherence Concurrent to be an Extend client.
- Returns:
 - a 
Coherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration 
 - 
getInstances
Returns all of theCoherenceinstances.- Returns:
 - all of the 
Coherenceinstances 
 - 
getInstances
Returns all of theCoherenceinstances.- Parameters:
 loader- theClassLoaderto obtain instances- Returns:
 - all of the 
Coherenceinstances 
 - 
removeInstance
 - 
removeInstance
 - 
getInstance
 - 
getInstance
Returns the namedCoherenceinstance ornullif the name isnullor noCoherenceinstance exists with the specified name.- Parameters:
 sName- the name of theCoherenceinstance to returnloader- theClassLoaderassociated with theCoherenceinstance- Returns:
 - the named 
Coherenceinstance ornullif noCoherenceinstance exists with the specified name 
 - 
getInstance
Returns aCoherenceinstance created ornullif noCoherenceinstance exists.This method is useful if only a single
Coherenceinstance exists in an application. If multiple instances exists the actual instance returned is undetermined.- Returns:
 - a 
Coherenceinstance created 
 - 
getInstance
Returns aCoherenceinstance created ornullif noCoherenceinstance exists.This method is useful if only a single
Coherenceinstance exists in an application. If multiple instances exists the actual instance returned is undetermined.- Parameters:
 loader- theClassLoaderassociated with theCoherenceinstance- Returns:
 - a 
Coherenceinstance created 
 - 
findSession
 - 
findSessionsByScope
 - 
closeAll
public static void closeAll() - 
getName
Returns the name of thisCoherenceinstance.- Returns:
 - the name of this 
Coherenceinstance 
 - 
getMode
Return theCoherence.Modethat this instance is running as.- Returns:
 - the 
Coherence.Modethat this instance is running as 
 - 
getConfiguration
Returns the configuration used by thisCoherenceinstance.- Returns:
 - the configuration used by this 
Coherenceinstance 
 - 
hasSession
 - 
getSessionNames
Return a set of session names that thisCoherenceinstance has.- Returns:
 - a set of session names that this 
Coherenceinstance has 
 - 
getSessionScopeNames
Return a set of session scope names that thisCoherenceinstance has.- Returns:
 - a set of session scope names that this 
Coherenceinstance has 
 - 
getSession
- Returns:
 - the default 
Session - Throws:
 IllegalStateException- if this instance has been closed
 - 
getSessionIfPresent
 - 
getSession
Obtain theSessionfrom theCoherenceinstance that was configured with the specified configuration name.- Parameters:
 sName- the name of theSessionto return- Returns:
 - the named 
Session - Throws:
 IllegalArgumentException- if no session exists for the specified nameIllegalStateException- if this instance has been closed
 - 
addSession
Add asessionto thisCoherenceinstance.The
session namemust be globally unique across allCoherenceinstances.If this
Coherenceinstance is already running, then the session will be started immediately.- Parameters:
 config- theconfigurationof the session to add- Returns:
 - this 
Coherenceinstance - Throws:
 IllegalArgumentException- if the configuration does not have a nameIllegalStateException- if thisCoherenceinstance is closed
 - 
addSessionIfAbsent
Add asessionto thisCoherenceinstance, iff a session configuration is not already present in thisCoherenceinstance with the specified name.The
session namemust be globally unique across allCoherenceinstances.If this
Coherenceinstance is already running, then the session will be started immediately.- Parameters:
 config- theconfigurationof the session to add- Returns:
 - this 
Coherenceinstance - Throws:
 IllegalArgumentException- if the configuration does not have a nameIllegalStateException- if thisCoherenceinstance is closed
 - 
addSessionIfAbsent
Add asessionto thisCoherenceinstance, iff a session configuration is not already present in thisCoherenceinstance with the specified name.The
session namemust be globally unique across allCoherenceinstances.If this
Coherenceinstance is already running, then the session will be started immediately.- Parameters:
 sName- the name of the session to addsupplier- aSupplierused to provide theconfigurationof the session to add, if the session is not present- Returns:
 - this 
Coherenceinstance - Throws:
 IllegalArgumentException- if the configuration name does not match the name argumentIllegalArgumentException- if the configuration does not have a nameIllegalStateException- if thisCoherenceinstance is closed
 - 
getSessionsWithScope
Obtain all theSessionsfrom theCoherenceinstance that are configured with the specified scope name.- Parameters:
 sScope- the scope name of theSessionsto return- Returns:
 - the 
Sessioninstances with the specified scope or an emptyCollectionif noSessionshave the required scope name - Throws:
 IllegalStateException- if this instance has been closed
 - 
whenStarted
Obtain aCompletableFuturethat will be completed when thisCoherenceinstance has started.- Returns:
 - a 
CompletableFuturethat will be completed when thisCoherenceinstance has started 
 - 
whenClosed
Obtain aCompletableFuturethat will be completed when thisCoherenceinstance has closed.- Returns:
 - a 
CompletableFuturethat will be completed when thisCoherenceinstance has closed 
 - 
isStarted
public boolean isStarted()Returntrueif thisCoherenceinstance has been started.- Returns:
 trueif thisCoherenceinstance has been started
 - 
isClosed
public boolean isClosed()Returntrueif thisCoherenceinstance has been closed.- Returns:
 trueif thisCoherenceinstance has been closed
 - 
startAndWait
Start thisCoherenceinstance and block until Coherence has started.This method will wait for the specified timeout.
If this instance already been started and has not been closed this method call is a no-op.
- Returns:
 - the running 
Coherenceinstance - Throws:
 InterruptedException- if Coherence does not start within the timeout
 - 
startAndWait
public Coherence startAndWait(com.oracle.coherence.common.util.Duration timeout) throws InterruptedException Start thisCoherenceinstance and block until Coherence has started.This method will wait for the specified timeout.
If this instance already been started and has not been closed this method call is a no-op.
- Parameters:
 timeout- the timeout duration to wait for Coherence to start- Returns:
 - the running 
Coherenceinstance - Throws:
 InterruptedException- if Coherence does not start within the timeout
 - 
start
Asynchronously start thisCoherenceinstance.If this instance already been started and has not been closed this method call is a no-op.
- Returns:
 - a 
CompletableFuturethat will be completed when thisCoherenceinstance has started 
 - 
startOnCallingThread
public void startOnCallingThread()Start thisCoherenceinstance.If this instance already been started and has not been closed this method call is a no-op.
 - 
isActive
public boolean isActive() - 
close
public void close()Close thisCoherenceinstance.- Specified by:
 closein interfaceAutoCloseable
 - 
getResourceRegistry
Return theResourceRegistryfor thisCoherenceinstance.- Returns:
 - the ResourceRegistry for this 
Coherenceinstance 
 - 
getInterceptorRegistry
Return theInterceptorRegistryfor thisCoherenceinstance.- Returns:
 - the 
InterceptorRegistryfor thisCoherenceinstance 
 - 
getCluster
Return aClusterobject for Coherence services.- Returns:
 - a 
Clusterobject, which may or may not be running 
 - 
getManagement
Returns the current management registry.- Returns:
 - the current management registry or 
nullif the management is disabled on this node - Since:
 - 22.06
 
 - 
main
Start a Coherence server.This method will start Coherence configured with a single session that uses the default cache configuration file. This is effectively the same as running
DefaultCacheServer.main(String[])without any arguments but will additionally bootstrap aCoherenceinstance with the default nameDEFAULT_NAMEand an unscopedSessionwith the same default name.- Parameters:
 args- the program arguments.
 - 
toString
 
 -