Interface Session
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
CoherenceSession
NamedCache
s, from a deployed module.
Resources provided by a Session
are scoped to the Session
.
When a Session
is closed, all resources are closed.
Once closed, references to resources are no longer valid. Any
attempt to use a closed Session
or closed resource may throw an
IllegalStateException.
The effect of closing a resource is specific to the type of resource.
For example, resources provided by a Session
may represent
shared (ie: clustered) data-structures and services. In such circumstances,
closing these resources only closes the Session
-based representation,
not the underlying shared infrastructure, which may remain active for other
Session
s. Future requests of a Session
for previously closed
resources of this kind will likely yield a new reference to logically the
same underlying resource. To destroy such resources, instead of close,
resource-specific methods should be used.
Applications making use of Session
s are expected to maintain their
own references to Session
s. Coherence provides no mechanism to
identify and obtain previously created Session
s. Furthermore,
applications are expected to correctly close Session
s when they are
no longer required.
- Author:
- bo 2015.07.27
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Activate thisSession
.static Session
create()
Obtain the default Session.static Session
create
(Session.Option... options) Deprecated.since 20.12 usecreate(SessionConfiguration)
create
(SessionConfiguration configuration) Possibly obtain aSession
based on the specified configuration.create
(SessionConfiguration configuration, Coherence.Mode mode) Possibly obtain aSession
based on the specified configuration.create
(SessionConfiguration configuration, Coherence.Mode mode, Iterable<? extends EventInterceptor<?>> interceptors) Possibly obtain aSession
based on the specified configuration.default <V> Publisher
<V> createPublisher
(String sName) Create aPublisher
that can publish values into aNamedTopic
.default <V> Publisher
<V> createPublisher
(String sName, Publisher.Option... options) Create aPublisher
that can publish values into aNamedTopic
.default <V> Subscriber
<V> createSubscriber
(String sName) Create aSubscriber
that can subscribe to aNamedTopic
.default <V> Subscriber
<V> createSubscriber
(String sName, Subscriber.Option... options) Create aSubscriber
that can subscribe to aNamedTopic
.static Session
ensure
(SessionConfiguration configuration) Obtain aSession
based on the specified configuration or throw anIllegalStateException
if a session could not be obtained.static Session
ensure
(SessionConfiguration configuration, Coherence.Mode mode) Obtain aSession
based on the specified configuration or throw anIllegalStateException
if a session could not be obtained.<K,
V> NamedCache <K, V> getCache
(String sName, NamedMap.Option... options) Return theInterceptorRegistry
for this session.<K,
V> NamedMap <K, V> getMap
(String sName, NamedMap.Option... options) getName()
Return the name of this session, if available.Return theResourceRegistry
for this session.Return the scope name of this cache factory, if available.getService
(String sServiceName) Returns a service for the given name ornull
if no service exists in this session with the specified name.default <V> NamedTopic
<V> Acquire aNamedTopic
using the specifiedValueTypeAssertion
.<V> NamedTopic
<V> getTopic
(String sName, NamedCollection.Option... options) Acquire aNamedTopic
using the specifiedValueTypeAssertion
.boolean
isActive()
Returntrue
if thisSession
is active and has not been closed.boolean
isCacheActive
(String sCacheName, ClassLoader loader) Validate whether a cache with the given name is active in the context of the givenClassLoader
.boolean
isMapActive
(String sMapName, ClassLoader loader) Validate whether a map with the given name is active in the context of the givenClassLoader
.boolean
isTopicActive
(String sTopicName, ClassLoader loader) Validate whether a topic with the given name is active in the context of the givenClassLoader
.Methods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
getMap
- Type Parameters:
K
- the type of keys for theNamedMap
V
- the type of values for theNamedMap
- Parameters:
sName
- the name of theNamedMap
options
- theNamedMap.Option
s- Returns:
- a
NamedMap
-
getCache
- Type Parameters:
K
- the type of keys for theNamedCache
V
- the type of values for theNamedCache
- Parameters:
sName
- the name of theNamedCache
options
- theNamedMap.Option
s- Returns:
- a
NamedCache
-
getTopic
Acquire aNamedTopic
using the specifiedValueTypeAssertion
.- Type Parameters:
V
- the type of elements for theNamedTopic
- Parameters:
sName
- the name of theNamedTopic
- Returns:
- a
NamedCache
- Since:
- Coherence 14.1.2
-
getTopic
Acquire aNamedTopic
using the specifiedValueTypeAssertion
.- Type Parameters:
V
- the type of elements for theNamedTopic
- Parameters:
sName
- the name of theNamedTopic
- Returns:
- a
NamedCache
- Since:
- Coherence 14.1.1
-
createPublisher
Create aPublisher
that can publish values into aNamedTopic
.- Parameters:
sName
- the name of theNamedTopic
thePublisher
will publish to- Returns:
- a
Publisher
that can publish values aNamedTopic
-
createPublisher
Create aPublisher
that can publish values into aNamedTopic
.- Parameters:
sName
- the name of theNamedTopic
thePublisher
will publish tooptions
- thePublisher.Option
s controlling thePublisher
- Returns:
- a
Publisher
that can publish values aNamedTopic
-
createSubscriber
Create aSubscriber
that can subscribe to aNamedTopic
.- Parameters:
sName
- the name of theNamedTopic
theSubscriber
will subscribe to- Returns:
- a
Subscriber
that can publish values aNamedTopic
-
createSubscriber
Create aSubscriber
that can subscribe to aNamedTopic
.- Parameters:
sName
- the name of theNamedTopic
theSubscriber
will subscribe tooptions
- theSubscriber.Option
s controlling theSubscriber
- Returns:
- a
Subscriber
that can publish values aNamedTopic
-
getResourceRegistry
ResourceRegistry getResourceRegistry()Return theResourceRegistry
for this session.- Returns:
- the ResourceRegistry for this session
-
getInterceptorRegistry
InterceptorRegistry getInterceptorRegistry()Return theInterceptorRegistry
for this session.EventInterceptor
s registered with this session will be scoped to services and caches created by this session.- Returns:
- the
InterceptorRegistry
for this session
-
isMapActive
Validate whether a map with the given name is active in the context of the givenClassLoader
. The ClassLoader should be the same as provided to a previous call togetMap(String, NamedMap.Option...)
.- Parameters:
sMapName
- the map nameloader
- the ClassLoader used to originally obtain the map- Returns:
- true if map is active in context of the provided ClassLoader
-
isCacheActive
Validate whether a cache with the given name is active in the context of the givenClassLoader
. The ClassLoader should be the same as provided to a previous call togetCache(String, NamedCache.Option...)
.- Parameters:
sCacheName
- the cache nameloader
- the ClassLoader used to originally obtain the cache- Returns:
- true if cache is active in context of the provided ClassLoader
-
isTopicActive
Validate whether a topic with the given name is active in the context of the givenClassLoader
. The ClassLoader should be the same as provided to a previous call togetTopic(String, NamedTopic.Option...)
.- Parameters:
sTopicName
- the cache nameloader
- the ClassLoader used to originally obtain the topic- Returns:
- true if topic is active in context of the provided ClassLoader
-
getName
String getName()Return the name of this session, if available.- Returns:
- the name of this session, if available;
null
otherwise
-
getScopeName
String getScopeName()Return the scope name of this cache factory, if available.- Returns:
- the scope name of this cache factory, if available;
null
otherwise
-
isActive
boolean isActive()Returntrue
if thisSession
is active and has not been closed.- Returns:
true
if thisSession
is active
-
activate
void activate() -
getService
Returns a service for the given name ornull
if no service exists in this session with the specified name.- Parameters:
sServiceName
- the service name- Returns:
- the requested Service or
null
if no service exists in this session with the specified name
-
create
@Deprecated static Session create(Session.Option... options) throws IllegalArgumentException, IllegalStateException Deprecated.since 20.12 usecreate(SessionConfiguration)
Create aSession
based on the current calling context and providedSession.Option
s, using the default (auto-detected)SessionProvider
,- Parameters:
options
- theSession.Option
s for theSession
- Returns:
- a
Session
- Throws:
IllegalArgumentException
- when aSession
orSessionProvider
can't be acquired using the specifiedSession.Option
sIllegalStateException
- when aSessionProvider
can't be auto-detected- See Also:
-
create
Obtain the default Session.This method calls
ensure(SessionConfiguration, Coherence.Mode)
with a configuration ofSessionConfiguration.defaultSession()
and a mode ofCoherence.Mode.ClusterMember
. This will return an activated cluster member defaultSession
.- Returns:
- an
Optional
containing theSession
or an emptyOption
if the default session could not be created. - Throws:
IllegalStateException
- if the default session cannot be created
-
ensure
Obtain aSession
based on the specified configuration or throw anIllegalStateException
if a session could not be obtained.This method calls
ensure(SessionConfiguration, Coherence.Mode)
with a mode ofCoherence.Mode.ClusterMember
.- Parameters:
configuration
- the configuration for theSession
- Returns:
- an
Optional
containing theSession
or an emptyOption
if no session could be created from the specified configuration - Throws:
NullPointerException
- if the configuration isnull
IllegalStateException
- if the default session cannot be created
-
ensure
Obtain aSession
based on the specified configuration or throw anIllegalStateException
if a session could not be obtained.- Parameters:
configuration
- the configuration for theSession
mode
- the mode that Coherence is running in- Returns:
- an
Optional
containing theSession
or an emptyOption
if no session could be created from the specified configuration - Throws:
NullPointerException
- if the configuration or mode arenull
IllegalStateException
- if the default session cannot be created
-
create
Possibly obtain aSession
based on the specified configuration.This method calls
create(SessionConfiguration, Coherence.Mode)
with a mode ofCoherence.Mode.ClusterMember
.- Parameters:
configuration
- the configuration for theSession
- Returns:
- an
Optional
containing theSession
or an emptyOption
if no session could be created from the specified configuration - Throws:
NullPointerException
- if the configuration isnull
-
create
Possibly obtain aSession
based on the specified configuration.- Parameters:
configuration
- the configuration for theSession
mode
- the mode that Coherence is running in- Returns:
- an
Optional
containing theSession
or an emptyOption
if no session could be created from the specified configuration - Throws:
NullPointerException
- if the configuration or mode arenull
-
create
static Optional<Session> create(SessionConfiguration configuration, Coherence.Mode mode, Iterable<? extends EventInterceptor<?>> interceptors) Possibly obtain aSession
based on the specified configuration.- Parameters:
configuration
- the configuration for theSession
mode
- the mode that Coherence is running ininterceptors
- optionalinterceptors
to add to the session in addition to any in the configuration- Returns:
- an
Optional
containing theSession
or an emptyOption
if no session could be created from the specified configuration - Throws:
NullPointerException
- if the configuration or mode arenull
-
Session.Option
has been replaced bySessionConfiguration