Interface Session
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
CoherenceSession
NamedCaches, 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
Sessions. 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 Sessions are expected to maintain their
own references to Sessions. Coherence provides no mechanism to
identify and obtain previously created Sessions. Furthermore,
applications are expected to correctly close Sessions when they are
no longer required.
- Author:
- bo 2015.07.27
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Activate thisSession.voidclose(NamedCollection col) Close and release the aNamedCollection.static Sessioncreate()Obtain the default Session.static Sessioncreate(Session.Option... options) Deprecated.since 20.12 usecreate(SessionConfiguration)create(SessionConfiguration configuration) Possibly obtain aSessionbased on the specified configuration.create(SessionConfiguration configuration, Coherence.Mode mode) Possibly obtain aSessionbased on the specified configuration.create(SessionConfiguration configuration, Coherence.Mode mode, Iterable<? extends EventInterceptor<?>> interceptors) Possibly obtain aSessionbased on the specified configuration.default <V> Publisher<V> createPublisher(String sName) Create aPublisherthat can publish values into aNamedTopic.default <V> Publisher<V> createPublisher(String sName, Publisher.Option... options) Create aPublisherthat can publish values into aNamedTopic.default <V> Subscriber<V> createSubscriber(String sName) Create aSubscriberthat can subscribe to aNamedTopic.default <V> Subscriber<V> createSubscriber(String sName, Subscriber.Option... options) Create aSubscriberthat can subscribe to aNamedTopic.voiddestroy(NamedCollection col) Destroy aNamedCollection.static Sessionensure(SessionConfiguration configuration) Obtain aSessionbased on the specified configuration or throw anIllegalStateExceptionif a session could not be obtained.static Sessionensure(SessionConfiguration configuration, Coherence.Mode mode) Obtain aSessionbased on the specified configuration or throw anIllegalStateExceptionif a session could not be obtained.<K,V> NamedCache <K, V> getCache(String sName, NamedMap.Option... options) Return theInterceptorRegistryfor this session.<K,V> NamedMap <K, V> getMap(String sName, NamedMap.Option... options) getName()Return the name of this session, if available.Return theResourceRegistryfor this session.Return the scope name of this cache factory, if available.getService(String sServiceName) Returns a service for the given name ornullif no service exists in this session with the specified name.default <V> NamedTopic<V> Acquire aNamedTopicusing the specifiedValueTypeAssertion.<V> NamedTopic<V> getTopic(String sName, NamedCollection.Option... options) Acquire aNamedTopicusing the specifiedValueTypeAssertion.booleanisActive()Returntrueif thisSessionis active and has not been closed.booleanisCacheActive(String sCacheName, ClassLoader loader) Validate whether a cache with the given name is active in the context of the givenClassLoader.booleanisMapActive(String sMapName, ClassLoader loader) Validate whether a map with the given name is active in the context of the givenClassLoader.booleanisTopicActive(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 theNamedMapV- the type of values for theNamedMap- Parameters:
sName- the name of theNamedMapoptions- theNamedMap.Options- Returns:
- a
NamedMap
-
getCache
- Type Parameters:
K- the type of keys for theNamedCacheV- the type of values for theNamedCache- Parameters:
sName- the name of theNamedCacheoptions- theNamedMap.Options- Returns:
- a
NamedCache
-
getTopic
Acquire aNamedTopicusing 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 aNamedTopicusing 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 aPublisherthat can publish values into aNamedTopic.- Parameters:
sName- the name of theNamedTopicthePublisherwill publish to- Returns:
- a
Publisherthat can publish values aNamedTopic
-
createPublisher
Create aPublisherthat can publish values into aNamedTopic.- Parameters:
sName- the name of theNamedTopicthePublisherwill publish tooptions- thePublisher.Options controlling thePublisher- Returns:
- a
Publisherthat can publish values aNamedTopic
-
createSubscriber
Create aSubscriberthat can subscribe to aNamedTopic.- Parameters:
sName- the name of theNamedTopictheSubscriberwill subscribe to- Returns:
- a
Subscriberthat can publish values aNamedTopic
-
createSubscriber
Create aSubscriberthat can subscribe to aNamedTopic.- Parameters:
sName- the name of theNamedTopictheSubscriberwill subscribe tooptions- theSubscriber.Options controlling theSubscriber- Returns:
- a
Subscriberthat can publish values aNamedTopic
-
close
Close and release the aNamedCollection.- Parameters:
col- theNamedCollectionto close
-
destroy
Destroy aNamedCollection.Warning: This method is used to completely destroy the specified collection across the cluster. All references in the entire cluster to this collection will be invalidated, the collection data will be cleared, and all internal resources will be released.
- Parameters:
col- theNamedCollectionto destroy
-
getResourceRegistry
ResourceRegistry getResourceRegistry()Return theResourceRegistryfor this session.- Returns:
- the ResourceRegistry for this session
-
getInterceptorRegistry
InterceptorRegistry getInterceptorRegistry()Return theInterceptorRegistryfor this session.EventInterceptors registered with this session will be scoped to services and caches created by this session.- Returns:
- the
InterceptorRegistryfor 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;
nullotherwise
-
getScopeName
String getScopeName()Return the scope name of this cache factory, if available.- Returns:
- the scope name of this cache factory, if available;
nullotherwise
-
isActive
boolean isActive()Returntrueif thisSessionis active and has not been closed.- Returns:
trueif thisSessionis active
-
activate
void activate() -
getService
Returns a service for the given name ornullif no service exists in this session with the specified name.- Parameters:
sServiceName- the service name- Returns:
- the requested Service or
nullif 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 aSessionbased on the current calling context and providedSession.Options, using the default (auto-detected)SessionProvider,- Parameters:
options- theSession.Options for theSession- Returns:
- a
Session - Throws:
IllegalArgumentException- when aSessionorSessionProvidercan't be acquired using the specifiedSession.OptionsIllegalStateException- when aSessionProvidercan'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
Optionalcontaining theSessionor an emptyOptionif the default session could not be created. - Throws:
IllegalStateException- if the default session cannot be created
-
ensure
Obtain aSessionbased on the specified configuration or throw anIllegalStateExceptionif 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
Optionalcontaining theSessionor an emptyOptionif no session could be created from the specified configuration - Throws:
NullPointerException- if the configuration isnullIllegalStateException- if the default session cannot be created
-
ensure
Obtain aSessionbased on the specified configuration or throw anIllegalStateExceptionif a session could not be obtained.- Parameters:
configuration- the configuration for theSessionmode- the mode that Coherence is running in- Returns:
- an
Optionalcontaining theSessionor an emptyOptionif no session could be created from the specified configuration - Throws:
NullPointerException- if the configuration or mode arenullIllegalStateException- if the default session cannot be created
-
create
Possibly obtain aSessionbased 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
Optionalcontaining theSessionor an emptyOptionif no session could be created from the specified configuration - Throws:
NullPointerException- if the configuration isnull
-
create
Possibly obtain aSessionbased on the specified configuration.- Parameters:
configuration- the configuration for theSessionmode- the mode that Coherence is running in- Returns:
- an
Optionalcontaining theSessionor an emptyOptionif 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 aSessionbased on the specified configuration.- Parameters:
configuration- the configuration for theSessionmode- the mode that Coherence is running ininterceptors- optionalinterceptorsto add to the session in addition to any in the configuration- Returns:
- an
Optionalcontaining theSessionor an emptyOptionif no session could be created from the specified configuration - Throws:
NullPointerException- if the configuration or mode arenull
-
Session.Optionhas been replaced bySessionConfiguration