Interface Session
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
CoherenceSession
public interface Session extends AutoCloseable
A thread-safe mechanism to request Coherence-based resources, likeNamedCache
s, from a deployed module.Resources provided by a
Session
are scoped to theSession
. When aSession
is closed, all resources are closed. Once closed, references to resources are no longer valid. Any attempt to use a closedSession
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 theSession
-based representation, not the underlying shared infrastructure, which may remain active for otherSession
s. Future requests of aSession
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 toSession
s. Coherence provides no mechanism to identify and obtain previously createdSession
s. Furthermore, applications are expected to correctly closeSession
s when they are no longer required.- Author:
- bo 2015.07.27
- See Also:
SessionProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Session.Option
Deprecated.since 20.12Session.Option
has been replaced bySessionConfiguration
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
activate()
Activate thisSession
.static Session
create()
Obtain the default Session.static Session
create(Session.Option... options)
Deprecated.since 20.12 usecreate(SessionConfiguration)
static Optional<Session>
create(SessionConfiguration configuration)
Possibly obtain aSession
based on the specified configuration.static Optional<Session>
create(SessionConfiguration configuration, Coherence.Mode mode)
Possibly obtain aSession
based on the specified configuration.static Optional<Session>
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)
InterceptorRegistry
getInterceptorRegistry()
Return theInterceptorRegistry
for this session.<K,V>
NamedMap<K,V>getMap(String sName, NamedMap.Option... options)
String
getName()
Return the name of this session, if available.ResourceRegistry
getResourceRegistry()
Return theResourceRegistry
for this session.String
getScopeName()
Return the scope name of this cache factory, if available.Service
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>
getTopic(String sName)
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 Detail
-
getMap
<K,V> NamedMap<K,V> getMap(String sName, NamedMap.Option... options)
- 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
<K,V> NamedCache<K,V> getCache(String sName, NamedMap.Option... options)
- 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
default <V> NamedTopic<V> getTopic(String sName)
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
<V> NamedTopic<V> getTopic(String sName, NamedCollection.Option... options)
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
default <V> Publisher<V> createPublisher(String sName)
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
default <V> Publisher<V> createPublisher(String sName, Publisher.Option... options)
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
default <V> Subscriber<V> createSubscriber(String sName)
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
default <V> Subscriber<V> createSubscriber(String sName, Subscriber.Option... options)
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
boolean isMapActive(String sMapName, ClassLoader loader)
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
boolean isCacheActive(String sCacheName, ClassLoader loader)
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
boolean isTopicActive(String sTopicName, ClassLoader loader)
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
Service getService(String sServiceName)
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:
SessionProvider.createSession(Option...)
-
create
static Session 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
static Session ensure(SessionConfiguration configuration)
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
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.- 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
static Optional<Session> create(SessionConfiguration configuration)
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
static Optional<Session> create(SessionConfiguration configuration, Coherence.Mode mode)
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
-
-