Class Coherence
- java.lang.Object
-
- com.tangosol.net.Coherence
-
- All Implemented Interfaces:
AutoCloseable
public class Coherence extends Object implements AutoCloseable
ACoherenceinstance encapsulates and controls one or moreSessioninstances.A
Coherenceinstance is typically created from aCoherenceConfigurationwhich contains one or moreSessionConfigurationinstances. TheCoherenceinstance is thenstartedwhich in turn creates and starts the configuredSessions. When theCoherenceinstance isclosedall of theSessioninstances being managed are alsoclosed.An example of creating and starting a
Coherenceinstance 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:
CoherenceConfiguration,SessionConfiguration
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCoherence.BuilderA builder to buildCoherenceinstances.static interfaceCoherence.LifecycleListenerAn interface implemented by listeners ofCoherenceLifecycleEvents.static classCoherence.ModeAn enum representing the different modes that aCoherenceinstance can run in.
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_NAMEThe default session name.static StringDEFAULT_SCOPEThe default scope name.static com.oracle.coherence.common.util.DurationDEFAULT_START_TIMEOUTThe default start up timeout.static StringPROP_START_TIMEOUTThe system property to use to set the default timeout to wait for Coherence instances to start.static StringSYS_CCF_URIThe name of the System configuration uri.static StringSYSTEM_SCOPEThe System scope name.static StringSYSTEM_SESSIONThe System session name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CoherenceaddSession(SessionConfiguration config)CoherenceaddSessionIfAbsent(SessionConfiguration config)CoherenceaddSessionIfAbsent(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 CoherenceclusterMember()Return the defaultCoherencecluster member instance, creating it if it does not already exist.static CoherenceclusterMember(CoherenceConfiguration config)Create aCoherenceinstance from the specifiedCoherenceConfiguration.static Coherence.BuilderclusterMemberBuilder(CoherenceConfiguration config)Returns 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.static Optional<Session>findSession(String sName)static Collection<Session>findSessionsByScope(String sScope)static CoherencefixedClient()Create a defaultCoherenceclient instance, creating it if it does not already exist.static CoherencefixedClient(CoherenceConfiguration config)Create a clientCoherenceinstance from the specifiedCoherenceConfiguration.static Coherence.BuilderfixedClientBuilder(CoherenceConfiguration config)Returns aCoherence.Builderinstance that can build aCoherenceinstance using the specifiedCoherenceConfiguration.ClustergetCluster()Return aClusterobject for Coherence services.CoherenceConfigurationgetConfiguration()Returns the configuration used by thisCoherenceinstance.static CoherencegetInstance()static CoherencegetInstance(ClassLoader loader)static CoherencegetInstance(String sName)static CoherencegetInstance(String sName, ClassLoader loader)static Collection<Coherence>getInstances()Returns all of theCoherenceinstances.static Collection<Coherence>getInstances(ClassLoader loader)Returns all of theCoherenceinstances.InterceptorRegistrygetInterceptorRegistry()Return theInterceptorRegistryfor thisCoherenceinstance.RegistrygetManagement()Returns the current management registry.Coherence.ModegetMode()Return theCoherence.Modethat this instance is running as.StringgetName()Returns the name of thisCoherenceinstance.ResourceRegistrygetResourceRegistry()Return theResourceRegistryfor thisCoherenceinstance.SessiongetSession()SessiongetSession(String sName)Optional<Session>getSessionIfPresent(String sName)Set<String>getSessionNames()Return a set of session names that thisCoherenceinstance has.Set<String>getSessionScopeNames()Return a set of session scope names that thisCoherenceinstance has.Collection<Session>getSessionsWithScope(String sScope)booleanhasSession(String sName)booleanisActive()booleanisClosed()Returntrueif thisCoherenceinstance has been closed.booleanisStarted()Returntrueif thisCoherenceinstance has been started.static voidmain(String[] args)Start a Coherence server.protected static voidremoveInstance(String sName)protected static voidremoveInstance(String sName, ClassLoader loader)CompletableFuture<Coherence>start()Asynchronously start thisCoherenceinstance.CoherencestartAndWait()Start thisCoherenceinstance and block until Coherence has started.CoherencestartAndWait(com.oracle.coherence.common.util.Duration timeout)Start thisCoherenceinstance and block until Coherence has started.voidstartOnCallingThread()Start thisCoherenceinstance.StringtoString()CompletableFuture<Void>whenClosed()Obtain aCompletableFuturethat will be completed when thisCoherenceinstance has closed.CompletableFuture<Coherence>whenStarted()Obtain aCompletableFuturethat will be completed when thisCoherenceinstance has started.
-
-
-
Field Detail
-
SYS_CCF_URI
public static final String SYS_CCF_URI
The name of the System configuration uri.- See Also:
- Constant Field Values
-
SYSTEM_SCOPE
public static final String SYSTEM_SCOPE
The System scope name.- See Also:
- Constant Field Values
-
SYSTEM_SESSION
public static final String SYSTEM_SESSION
The System session name.- See Also:
- Constant Field Values
-
DEFAULT_SCOPE
public static final String DEFAULT_SCOPE
The default scope name.- See Also:
- Constant Field Values
-
DEFAULT_NAME
public static final String DEFAULT_NAME
The default session name.- See Also:
- Constant Field Values
-
PROP_START_TIMEOUT
public static final String PROP_START_TIMEOUT
The system property to use to set the default timeout to wait for Coherence instances to start.- See Also:
- Constant Field Values
-
DEFAULT_START_TIMEOUT
public static final com.oracle.coherence.common.util.Duration DEFAULT_START_TIMEOUT
The default start up timeout.
-
-
Method Detail
-
create
public static Coherence create()
Return the defaultCoherenceinstance, creating it if it does not already exist.- Returns:
- a default
Coherenceinstance
-
create
public static Coherence create(CoherenceConfiguration config)
Create a defaultCoherenceinstance.
-
create
public static Coherence create(CoherenceConfiguration config, Coherence.Mode mode)
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
public static Coherence.Builder builder(CoherenceConfiguration config)
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
public static Coherence.Builder builder(CoherenceConfiguration config, Coherence.Mode mode)
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
public static Coherence 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
public static Coherence clusterMember(CoherenceConfiguration config)
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
public static Coherence 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
public static Coherence client(Coherence.Mode mode)
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
public static Coherence client(CoherenceConfiguration config)
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
public static Coherence 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
public static Coherence fixedClient(CoherenceConfiguration config)
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
public static Coherence.Builder clusterMemberBuilder(CoherenceConfiguration config)
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
public static Coherence.Builder clientBuilder(CoherenceConfiguration config)
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
public static Coherence.Builder clientBuilder(CoherenceConfiguration config, Coherence.Mode mode)
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
public static Coherence.Builder fixedClientBuilder(CoherenceConfiguration config)
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
public static Collection<Coherence> getInstances()
Returns all of theCoherenceinstances.- Returns:
- all of the
Coherenceinstances
-
getInstances
public static Collection<Coherence> getInstances(ClassLoader loader)
Returns all of theCoherenceinstances.- Parameters:
loader- theClassLoaderto obtain instances- Returns:
- all of the
Coherenceinstances
-
removeInstance
protected static void removeInstance(String sName)
-
removeInstance
protected static void removeInstance(String sName, ClassLoader loader)
-
getInstance
public static Coherence getInstance(String sName, ClassLoader loader)
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
public static Coherence 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
public static Coherence getInstance(ClassLoader loader)
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
-
findSessionsByScope
public static Collection<Session> findSessionsByScope(String sScope)
-
closeAll
public static void closeAll()
-
getName
public String getName()
Returns the name of thisCoherenceinstance.- Returns:
- the name of this
Coherenceinstance
-
getMode
public Coherence.Mode getMode()
Return theCoherence.Modethat this instance is running as.- Returns:
- the
Coherence.Modethat this instance is running as
-
getConfiguration
public CoherenceConfiguration getConfiguration()
Returns the configuration used by thisCoherenceinstance.- Returns:
- the configuration used by this
Coherenceinstance
-
hasSession
public boolean hasSession(String sName)
-
getSessionNames
public Set<String> getSessionNames()
Return a set of session names that thisCoherenceinstance has.- Returns:
- a set of session names that this
Coherenceinstance has
-
getSessionScopeNames
public Set<String> getSessionScopeNames()
Return a set of session scope names that thisCoherenceinstance has.- Returns:
- a set of session scope names that this
Coherenceinstance has
-
getSession
public Session getSession()
- Returns:
- the default
Session - Throws:
IllegalStateException- if this instance has been closed
-
getSession
public Session getSession(String sName)
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
public Coherence addSession(SessionConfiguration config)
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
public Coherence addSessionIfAbsent(SessionConfiguration config)
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
public Coherence addSessionIfAbsent(String sName, Supplier<SessionConfiguration> supplier)
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
public Collection<Session> getSessionsWithScope(String sScope)
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
public CompletableFuture<Coherence> whenStarted()
Obtain aCompletableFuturethat will be completed when thisCoherenceinstance has started.- Returns:
- a
CompletableFuturethat will be completed when thisCoherenceinstance has started
-
whenClosed
public CompletableFuture<Void> 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
public Coherence startAndWait() 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.
- 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
public CompletableFuture<Coherence> 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
public ResourceRegistry getResourceRegistry()
Return theResourceRegistryfor thisCoherenceinstance.- Returns:
- the ResourceRegistry for this
Coherenceinstance
-
getInterceptorRegistry
public InterceptorRegistry getInterceptorRegistry()
Return theInterceptorRegistryfor thisCoherenceinstance.- Returns:
- the
InterceptorRegistryfor thisCoherenceinstance
-
getCluster
public Cluster getCluster()
Return aClusterobject for Coherence services.- Returns:
- a
Clusterobject, which may or may not be running
-
getManagement
public Registry getManagement()
Returns the current management registry.- Returns:
- the current management registry or
nullif the management is disabled on this node - Since:
- 22.06
-
main
public static void main(String[] args)
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.
-
-