Class Coherence
- java.lang.Object
-
- com.tangosol.net.Coherence
-
- All Implemented Interfaces:
AutoCloseable
public class Coherence extends Object implements AutoCloseable
ACoherence
instance encapsulates and controls one or moreSession
instances.A
Coherence
instance is typically created from aCoherenceConfiguration
which contains one or moreSessionConfiguration
instances. TheCoherence
instance is thenstarted
which in turn creates and starts the configuredSessions
. When theCoherence
instance isclosed
all of theSession
instances being managed are alsoclosed
.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:
CoherenceConfiguration
,SessionConfiguration
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Coherence.Builder
A builder to buildCoherence
instances.static interface
Coherence.LifecycleListener
An interface implemented by listeners ofCoherenceLifecycleEvents
.static class
Coherence.Mode
An enum representing the different modes that aCoherence
instance can run in.
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_NAME
The default session name.static String
DEFAULT_SCOPE
The default scope name.static com.oracle.coherence.common.util.Duration
DEFAULT_START_TIMEOUT
The default start up timeout.static String
PROP_START_TIMEOUT
The system property to use to set the default timeout to wait for Coherence instances to start.static String
SYS_CCF_URI
The name of the System configuration uri.static String
SYSTEM_SCOPE
The System scope name.static String
SYSTEM_SESSION
The System session name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Coherence
addSession(SessionConfiguration config)
Coherence
addSessionIfAbsent(SessionConfiguration config)
Coherence
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
clusterMember()
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
clusterMemberBuilder(CoherenceConfiguration config)
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.static Coherence
create(CoherenceConfiguration config, Coherence.Mode mode, ClassLoader loader)
Create a defaultCoherence
instance.static Optional<Session>
findSession(String sName)
static Collection<Session>
findSessionsByScope(String sScope)
static Coherence
fixedClient()
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
fixedClientBuilder(CoherenceConfiguration config)
Returns aCoherence.Builder
instance that can build aCoherence
instance using the specifiedCoherenceConfiguration
.Cluster
getCluster()
Return aCluster
object for Coherence services.CoherenceConfiguration
getConfiguration()
Returns the configuration used by thisCoherence
instance.static Coherence
getInstance()
static Coherence
getInstance(ClassLoader loader)
static Coherence
getInstance(String sName)
static Coherence
getInstance(String sName, ClassLoader loader)
static Collection<Coherence>
getInstances()
Returns all of theCoherence
instances.static Collection<Coherence>
getInstances(ClassLoader loader)
Returns all of theCoherence
instances.InterceptorRegistry
getInterceptorRegistry()
Return theInterceptorRegistry
for thisCoherence
instance.Registry
getManagement()
Returns the current management registry.Coherence.Mode
getMode()
Return theCoherence.Mode
that this instance is running as.String
getName()
Returns the name of thisCoherence
instance.ResourceRegistry
getResourceRegistry()
Return theResourceRegistry
for thisCoherence
instance.Session
getSession()
Session
getSession(String sName)
Optional<Session>
getSessionIfPresent(String sName)
Set<String>
getSessionNames()
Return a set of session names that thisCoherence
instance has.Set<String>
getSessionScopeNames()
Return a set of session scope names that thisCoherence
instance has.Collection<Session>
getSessionsWithScope(String sScope)
boolean
hasSession(String sName)
boolean
isActive()
boolean
isClosed()
Returntrue
if thisCoherence
instance has been closed.boolean
isStarted()
Returntrue
if thisCoherence
instance has been started.static void
main(String[] args)
Start a Coherence server.protected static void
removeInstance(String sName)
protected static void
removeInstance(String sName, ClassLoader loader)
CompletableFuture<Coherence>
start()
Asynchronously start thisCoherence
instance.Coherence
startAndWait()
Start thisCoherence
instance and block until Coherence has started.Coherence
startAndWait(com.oracle.coherence.common.util.Duration timeout)
Start thisCoherence
instance and block until Coherence has started.void
startOnCallingThread()
Start thisCoherence
instance.String
toString()
CompletableFuture<Void>
whenClosed()
Obtain aCompletableFuture
that will be completed when thisCoherence
instance has closed.CompletableFuture<Coherence>
whenStarted()
Obtain aCompletableFuture
that will be completed when thisCoherence
instance 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 defaultCoherence
instance, creating it if it does not already exist.- Returns:
- a default
Coherence
instance
-
create
public static Coherence create(CoherenceConfiguration config)
Create a defaultCoherence
instance.
-
create
public static Coherence create(CoherenceConfiguration config, Coherence.Mode mode)
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
-
create
public static Coherence create(CoherenceConfiguration config, Coherence.Mode mode, ClassLoader loader)
Create a defaultCoherence
instance.- Parameters:
config
- the configuration to use to create theCoherence
instancemode
- theCoherence.Mode
theCoherence
instance will run inloader
- theClassLoader
associated with theCoherence
instance- Returns:
- a default
Coherence
instance
-
builder
public static Coherence.Builder builder(CoherenceConfiguration config)
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
public static Coherence.Builder builder(CoherenceConfiguration config, Coherence.Mode mode)
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
public static Coherence 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
public static Coherence clusterMember(CoherenceConfiguration config)
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
public static Coherence 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
public static Coherence client(Coherence.Mode mode)
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
public static Coherence client(CoherenceConfiguration config)
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
public static Coherence 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
public static Coherence fixedClient(CoherenceConfiguration config)
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
public static Coherence.Builder clusterMemberBuilder(CoherenceConfiguration config)
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
public static Coherence.Builder clientBuilder(CoherenceConfiguration config)
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
public static Coherence.Builder clientBuilder(CoherenceConfiguration config, Coherence.Mode mode)
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
public static Coherence.Builder fixedClientBuilder(CoherenceConfiguration config)
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
public static Collection<Coherence> getInstances()
Returns all of theCoherence
instances.- Returns:
- all of the
Coherence
instances
-
getInstances
public static Collection<Coherence> getInstances(ClassLoader loader)
Returns all of theCoherence
instances.- Parameters:
loader
- theClassLoader
to obtain instances- Returns:
- all of the
Coherence
instances
-
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 namedCoherence
instance ornull
if the name isnull
or noCoherence
instance exists with the specified name.- Parameters:
sName
- the name of theCoherence
instance to returnloader
- theClassLoader
associated with theCoherence
instance- Returns:
- the named
Coherence
instance ornull
if noCoherence
instance exists with the specified name
-
getInstance
public static Coherence 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
-
getInstance
public static Coherence getInstance(ClassLoader loader)
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.- Parameters:
loader
- theClassLoader
associated with theCoherence
instance- Returns:
- a
Coherence
instance created
-
findSessionsByScope
public static Collection<Session> findSessionsByScope(String sScope)
-
closeAll
public static void closeAll()
-
getName
public String getName()
Returns the name of thisCoherence
instance.- Returns:
- the name of this
Coherence
instance
-
getMode
public Coherence.Mode getMode()
Return theCoherence.Mode
that this instance is running as.- Returns:
- the
Coherence.Mode
that this instance is running as
-
getConfiguration
public CoherenceConfiguration getConfiguration()
Returns the configuration used by thisCoherence
instance.- Returns:
- the configuration used by this
Coherence
instance
-
hasSession
public boolean hasSession(String sName)
-
getSessionNames
public Set<String> getSessionNames()
Return a set of session names that thisCoherence
instance has.- Returns:
- a set of session names that this
Coherence
instance has
-
getSessionScopeNames
public Set<String> 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
public Session getSession()
- Returns:
- the default
Session
- Throws:
IllegalStateException
- if this instance has been closed
-
getSession
public Session getSession(String sName)
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
public Coherence addSession(SessionConfiguration config)
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
public Coherence addSessionIfAbsent(SessionConfiguration config)
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
public Coherence addSessionIfAbsent(String sName, Supplier<SessionConfiguration> supplier)
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
public Collection<Session> getSessionsWithScope(String sScope)
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
public CompletableFuture<Coherence> 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
public CompletableFuture<Void> 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
public Coherence startAndWait() 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.
- 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
public CompletableFuture<Coherence> 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.
-
isActive
public boolean isActive()
-
close
public void close()
Close thisCoherence
instance.- Specified by:
close
in interfaceAutoCloseable
-
getResourceRegistry
public ResourceRegistry getResourceRegistry()
Return theResourceRegistry
for thisCoherence
instance.- Returns:
- the ResourceRegistry for this
Coherence
instance
-
getInterceptorRegistry
public InterceptorRegistry getInterceptorRegistry()
Return theInterceptorRegistry
for thisCoherence
instance.- Returns:
- the
InterceptorRegistry
for thisCoherence
instance
-
getCluster
public Cluster getCluster()
Return aCluster
object for Coherence services.- Returns:
- a
Cluster
object, which may or may not be running
-
getManagement
public Registry 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
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 aCoherence
instance with the default nameDEFAULT_NAME
and an unscopedSession
with the same default name.- Parameters:
args
- the program arguments.
-
-