Interface Session
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
CoherenceSession
public interface Session extends AutoCloseable
A thread-safe mechanism to request Coherence-based resources, likeNamedCaches, from a deployed module.Resources provided by a
Sessionare scoped to theSession. When aSessionis closed, all resources are closed. Once closed, references to resources are no longer valid. Any attempt to use a closedSessionor 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
Sessionmay 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 otherSessions. Future requests of aSessionfor 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 toSessions. Coherence provides no mechanism to identify and obtain previously createdSessions. Furthermore, applications are expected to correctly closeSessions 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 interfaceSession.OptionDeprecated.since 20.12Session.Optionhas been replaced bySessionConfiguration
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description voidactivate()Activate thisSession.static Sessioncreate()Obtain the default Session.static Sessioncreate(Session.Option... options)Deprecated.since 20.12 usecreate(SessionConfiguration)static Optional<Session>create(SessionConfiguration configuration)Possibly obtain aSessionbased on the specified configuration.static Optional<Session>create(SessionConfiguration configuration, Coherence.Mode mode)Possibly obtain aSessionbased on the specified configuration.static Optional<Session>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.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)InterceptorRegistrygetInterceptorRegistry()Return theInterceptorRegistryfor this session.<K,V>
NamedMap<K,V>getMap(String sName, NamedMap.Option... options)StringgetName()Return the name of this session, if available.ResourceRegistrygetResourceRegistry()Return theResourceRegistryfor this session.StringgetScopeName()Return the scope name of this cache factory, if available.ServicegetService(String sServiceName)Returns a service for the given name ornullif no service exists in this session with the specified name.default <V> NamedTopic<V>getTopic(String sName)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 Detail
-
getMap
<K,V> NamedMap<K,V> getMap(String sName, NamedMap.Option... options)
- 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
<K,V> NamedCache<K,V> getCache(String sName, NamedMap.Option... options)
- 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
default <V> NamedTopic<V> getTopic(String sName)
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
<V> NamedTopic<V> getTopic(String sName, NamedCollection.Option... options)
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
default <V> Publisher<V> createPublisher(String sName)
Create aPublisherthat can publish values into aNamedTopic.- Parameters:
sName- the name of theNamedTopicthePublisherwill publish to- Returns:
- a
Publisherthat can publish values aNamedTopic
-
createPublisher
default <V> Publisher<V> createPublisher(String sName, Publisher.Option... options)
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
default <V> Subscriber<V> createSubscriber(String sName)
Create aSubscriberthat can subscribe to aNamedTopic.- Parameters:
sName- the name of theNamedTopictheSubscriberwill subscribe to- Returns:
- a
Subscriberthat can publish values aNamedTopic
-
createSubscriber
default <V> Subscriber<V> createSubscriber(String sName, Subscriber.Option... options)
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
-
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
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;
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
Service getService(String sServiceName)
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:
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
Optionalcontaining theSessionor an emptyOptionif the default session could not be created. - Throws:
IllegalStateException- if the default session cannot be created
-
ensure
static Session ensure(SessionConfiguration configuration)
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
static Session ensure(SessionConfiguration configuration, Coherence.Mode mode)
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
static Optional<Session> create(SessionConfiguration configuration)
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
static Optional<Session> create(SessionConfiguration configuration, Coherence.Mode mode)
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
-
-