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
Modifier and TypeClassDescriptionstatic class
A builder to buildCoherence
instances.static interface
An interface implemented by listeners ofCoherenceLifecycleEvents
.static enum
An enum representing the different modes that aCoherence
instance can run in. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The default session name.static final String
The default scope name.static final com.oracle.coherence.common.util.Duration
The default start up timeout.static final String
The system property to use to set the default timeout to wait for Coherence instances to start.static final String
The name of the System configuration uri.static final String
The System scope name.static final String
The System session name. -
Method Summary
Modifier and TypeMethodDescriptionaddSession
(SessionConfiguration config) addSessionIfAbsent
(String sName, Supplier<SessionConfiguration> supplier) static Coherence.Builder
builder
(CoherenceConfiguration config) Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.static Coherence.Builder
builder
(CoherenceConfiguration config, Coherence.Mode mode) Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.static Coherence
client()
Return the defaultCoherence
client instance, creating it if it does not already exist.static Coherence
client
(Coherence.Mode mode) Return the defaultCoherence
client instance, creating it if it does not already exist.static Coherence
client
(CoherenceConfiguration config) Create a clientCoherence
instance from the specifiedCoherenceConfiguration
.static Coherence.Builder
clientBuilder
(CoherenceConfiguration config) Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.static Coherence.Builder
clientBuilder
(CoherenceConfiguration config, Coherence.Mode mode) Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.void
close()
Close thisCoherence
instance.static void
closeAll()
Close allCoherence
instances.static Coherence
Return the defaultCoherence
cluster member instance, creating it if it does not already exist.static Coherence
clusterMember
(CoherenceConfiguration config) Create aCoherence
instance from the specifiedCoherenceConfiguration
.static Coherence.Builder
Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.static Coherence
create()
Return the defaultCoherence
instance, creating it if it does not already exist.static Coherence
create
(CoherenceConfiguration config) Create a defaultCoherence
instance.static Coherence
create
(CoherenceConfiguration config, Coherence.Mode mode) Create a defaultCoherence
instance.findSession
(String sName) static Collection
<Session> findSessionsByScope
(String sScope) static Coherence
Create a defaultCoherence
client instance, creating it if it does not already exist.static Coherence
fixedClient
(CoherenceConfiguration config) Create a clientCoherence
instance from the specifiedCoherenceConfiguration
.static Coherence.Builder
Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.Return aCluster
object for Coherence services.Returns the configuration used by thisCoherence
instance.static Coherence
static Coherence
getInstance
(String sName) static Collection
<Coherence> Returns all of theCoherence
instances.Return theInterceptorRegistry
for thisCoherence
instance.Returns the current management registry.getMode()
Return theCoherence.Mode
that this instance is running as.getName()
Returns the name of thisCoherence
instance.Return theResourceRegistry
for thisCoherence
instance.getSession
(String sName) getSessionIfPresent
(String sName) Return a set of session names that thisCoherence
instance has.Return a set of session scope names that thisCoherence
instance has.getSessionsWithScope
(String sScope) boolean
hasSession
(String sName) boolean
isClosed()
Returntrue
if thisCoherence
instance has been closed.boolean
Returntrue
if thisCoherence
instance has been started.static void
Start a Coherence server.start()
Asynchronously start thisCoherence
instance.Start thisCoherence
instance and block until Coherence has started.startAndWait
(com.oracle.coherence.common.util.Duration timeout) Start thisCoherence
instance and block until Coherence has started.void
Start thisCoherence
instance.toString()
Obtain aCompletableFuture
that will be completed when thisCoherence
instance has closed.Obtain aCompletableFuture
that will be completed when thisCoherence
instance 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 defaultCoherence
instance, creating it if it does not already exist.- Returns:
- a default
Coherence
instance
-
create
Create a defaultCoherence
instance. -
create
Create a defaultCoherence
instance.- Parameters:
config
- the configuration to use to create theCoherence
instancemode
- theCoherence.Mode
theCoherence
instance will run in- Returns:
- a default
Coherence
instance
-
builder
Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.The
Coherence
instance built by theBuilder
will be a cluster member. Coherence auto-start services will be managed by aDefaultCacheServer
instance for each configured session.- Parameters:
config
- theCoherenceConfiguration
to use to build theCoherence
instance- Returns:
- a
Coherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
-
builder
Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.The
Coherence
instance built by theBuilder
will be a cluster member. Coherence auto-start services will be managed by aDefaultCacheServer
instance for each configured session.- Parameters:
config
- theCoherenceConfiguration
to use to build theCoherence
instancemode
- theCoherence.Mode
theCoherence
instance will run in- Returns:
- a
Coherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
-
clusterMember
Return the defaultCoherence
cluster member instance, creating it if it does not already exist.The
Coherence
instance built by theBuilder
will be a cluster member.- Returns:
- a default
Coherence
instance
-
clusterMember
Create aCoherence
instance from the specifiedCoherenceConfiguration
.The
Coherence
instance built by theBuilder
will be a cluster member.- Parameters:
config
- the configuration to use to create theCoherence
instance- Returns:
- a
Coherence
instance from the specifiedCoherenceConfiguration
-
client
Return the defaultCoherence
client 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
Coherence
instance
-
client
Return the defaultCoherence
client 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
Coherence
instance
-
client
Create a clientCoherence
instance 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 theCoherence
instance- Returns:
- a
Coherence
instance from the specifiedCoherenceConfiguration
-
fixedClient
Create a defaultCoherence
client 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.address
andcoherence.extend.port
.- Returns:
- a default
Coherence
instance
-
fixedClient
Create a clientCoherence
instance 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.address
andcoherence.extend.port
.- Parameters:
config
- the configuration to use to create theCoherence
instance- Returns:
- a
Coherence
instance from the specifiedCoherenceConfiguration
-
clusterMemberBuilder
Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.The
Coherence
instance built by theBuilder
will be a cluster member. Coherence auto-start services will be managed by aDefaultCacheServer
instance for each configured session.- Returns:
- a
Coherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
-
clientBuilder
Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.The
Coherence
instance built by theBuilder
will 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
- theCoherenceConfiguration
to configure theCoherence
instance- Returns:
- a
Coherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
-
clientBuilder
Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.The
Coherence
instance built by theBuilder
will 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
- theCoherenceConfiguration
to configure theCoherence
instancemode
- the default mode to run the Coherence instance- Returns:
- a
Coherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
-
fixedClientBuilder
Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.The
Coherence
instance built by theBuilder
will 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.address
andcoherence.extend.port
.If using the default Coherence Concurrent extensions, this will configure Coherence Concurrent to be an Extend client.
- Returns:
- a
Coherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
-
getInstances
Returns all of theCoherence
instances.- Returns:
- all of the
Coherence
instances
-
getInstance
-
getInstance
Returns aCoherence
instance created ornull
if noCoherence
instance exists.This method is useful if only a single
Coherence
instance exists in an application. If multiple instances exists the actual instance returned is undetermined.- Returns:
- a
Coherence
instance created
-
findSession
-
findSessionsByScope
-
closeAll
public static void closeAll() -
getName
Returns the name of thisCoherence
instance.- Returns:
- the name of this
Coherence
instance
-
getMode
Return theCoherence.Mode
that this instance is running as.- Returns:
- the
Coherence.Mode
that this instance is running as
-
getConfiguration
Returns the configuration used by thisCoherence
instance.- Returns:
- the configuration used by this
Coherence
instance
-
hasSession
-
getSessionNames
Return a set of session names that thisCoherence
instance has.- Returns:
- a set of session names that this
Coherence
instance has
-
getSessionScopeNames
Return a set of session scope names that thisCoherence
instance has.- Returns:
- a set of session scope names that this
Coherence
instance has
-
getSession
- Returns:
- the default
Session
- Throws:
IllegalStateException
- if this instance has been closed
-
getSessionIfPresent
-
getSession
Obtain theSession
from theCoherence
instance that was configured with the specified configuration name.- Parameters:
sName
- the name of theSession
to return- Returns:
- the named
Session
- Throws:
IllegalArgumentException
- if no session exists for the specified nameIllegalStateException
- if this instance has been closed
-
addSession
Add asession
to thisCoherence
instance.The
session name
must be globally unique across allCoherence
instances.If this
Coherence
instance is already running, then the session will be started immediately.- Parameters:
config
- theconfiguration
of the session to add- Returns:
- this
Coherence
instance - Throws:
IllegalArgumentException
- if the configuration does not have a nameIllegalStateException
- if thisCoherence
instance is closed
-
addSessionIfAbsent
Add asession
to thisCoherence
instance, iff a session configuration is not already present in thisCoherence
instance with the specified name.The
session name
must be globally unique across allCoherence
instances.If this
Coherence
instance is already running, then the session will be started immediately.- Parameters:
config
- theconfiguration
of the session to add- Returns:
- this
Coherence
instance - Throws:
IllegalArgumentException
- if the configuration does not have a nameIllegalStateException
- if thisCoherence
instance is closed
-
addSessionIfAbsent
Add asession
to thisCoherence
instance, iff a session configuration is not already present in thisCoherence
instance with the specified name.The
session name
must be globally unique across allCoherence
instances.If this
Coherence
instance is already running, then the session will be started immediately.- Parameters:
sName
- the name of the session to addsupplier
- aSupplier
used to provide theconfiguration
of the session to add, if the session is not present- Returns:
- this
Coherence
instance - Throws:
IllegalArgumentException
- if the configuration name does not match the name argumentIllegalArgumentException
- if the configuration does not have a nameIllegalStateException
- if thisCoherence
instance is closed
-
getSessionsWithScope
Obtain all theSessions
from theCoherence
instance that are configured with the specified scope name.- Parameters:
sScope
- the scope name of theSessions
to return- Returns:
- the
Session
instances with the specified scope or an emptyCollection
if noSessions
have the required scope name - Throws:
IllegalStateException
- if this instance has been closed
-
whenStarted
Obtain aCompletableFuture
that will be completed when thisCoherence
instance has started.- Returns:
- a
CompletableFuture
that will be completed when thisCoherence
instance has started
-
whenClosed
Obtain aCompletableFuture
that will be completed when thisCoherence
instance has closed.- Returns:
- a
CompletableFuture
that will be completed when thisCoherence
instance has closed
-
isStarted
public boolean isStarted()Returntrue
if thisCoherence
instance has been started.- Returns:
true
if thisCoherence
instance has been started
-
isClosed
public boolean isClosed()Returntrue
if thisCoherence
instance has been closed.- Returns:
true
if thisCoherence
instance has been closed
-
startAndWait
Start thisCoherence
instance 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
Coherence
instance - Throws:
InterruptedException
- if Coherence does not start within the timeout
-
startAndWait
public Coherence startAndWait(com.oracle.coherence.common.util.Duration timeout) throws InterruptedException Start thisCoherence
instance 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
Coherence
instance - Throws:
InterruptedException
- if Coherence does not start within the timeout
-
start
Asynchronously start thisCoherence
instance.If this instance already been started and has not been closed this method call is a no-op.
- Returns:
- a
CompletableFuture
that will be completed when thisCoherence
instance has started
-
startOnCallingThread
public void startOnCallingThread()Start thisCoherence
instance.If this instance already been started and has not been closed this method call is a no-op.
-
close
public void close()Close thisCoherence
instance.- Specified by:
close
in interfaceAutoCloseable
-
getResourceRegistry
Return theResourceRegistry
for thisCoherence
instance.- Returns:
- the ResourceRegistry for this
Coherence
instance
-
getInterceptorRegistry
Return theInterceptorRegistry
for thisCoherence
instance.- Returns:
- the
InterceptorRegistry
for thisCoherence
instance
-
getCluster
Return aCluster
object for Coherence services.- Returns:
- a
Cluster
object, which may or may not be running
-
getManagement
Returns the current management registry.- Returns:
- the current management registry or
null
if 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 aCoherence
instance with the default nameDEFAULT_NAME
and an unscopedSession
with the same default name.- Parameters:
args
- the program arguments.
-
toString
-