Class AbstractSession
- Direct Known Subclasses:
ProviderSession
,Session
Sessions manage access to services either by requests and responses or subscriptions. A Session can dispatch events and replies in either a synchronous or asynchronous mode. The mode of a Session is determined when it is constructed and cannot be changed subsequently.
Service Identifier
A service identifier is the fully qualified service name which uniquely identifies the service in the API infrastructure. A service must be of the form"//<namespace>/<local-name>"
where
'<namespace>'
and '<local-name>'
are non-empty strings of characters from the set
[-_.a-zA-Z0-9]
. Service identifiers are case-insensitive, but clients are encouraged
to prefer identifiers without upper-case characters. Note that the <namespace>
and
<service-name>
cannot contain the character /
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Enumerations for controlled shutdown of the session -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel
(CorrelationID correlationId) Cancel an outstanding request or a subscription represented by the specified correlationIdvoid
cancel
(CorrelationID correlationId, String requestLabel) Cancel an outstanding request or a subscription represented by the specified correlationIdvoid
cancel
(List<CorrelationID> correlators) Cancel outstanding requests or subscriptions represented by the specified list of correlationIdsvoid
cancel
(List<CorrelationID> correlators, String requestLabel) Cancel outstanding requests or subscriptions represented by the specified list of correlationIdsReturn a new Identity which is valid but has not been authorized.Deprecated.generateAuthorizedIdentity
(AuthOptions authOptions) Generates an authorizedIdentity
with an automatically generatedCorrelationID
.void
generateAuthorizedIdentity
(AuthOptions authOptions, CorrelationID correlationId) Return a generated token to be used for authorization.generateToken
(CorrelationID correlationId) Return a generated token to be used for authorization.generateToken
(CorrelationID correlationId, EventQueue eventQueue) Return a generated token to be used for authorization.generateToken
(String userId, String ipAddress, CorrelationID correlationId, EventQueue eventQueue) Return a generated token to be used for authorization.getAuthorizedIdentity
(CorrelationID correlationId) Returns the authorized identity associated withcorrelationId
.getService
(String serviceIdentifier) Return a handle to aService
object representing the service identified by the specified 'serviceIdentifier'Returns the session identity if it is authorized.Retrieves the next event available for processing on this sessionnextEvent
(long timeoutMillis) Retrieves the next event available for processing on this sessionboolean
openService
(String serviceIdentifier) Open the service having the specifiedserviceIdentifier
openServiceAsync
(String serviceIdentifier) Issue an asynchronous request to open a service.void
openServiceAsync
(String serviceIdentifier, CorrelationID correlationId) Initiate an asynchronous request to open a service.sendAuthorizationRequest
(Request authorizationRequest, Identity identity, CorrelationID correlationId) Send the specified authorizationRequest and update the specified identity with the results.sendAuthorizationRequest
(Request authorizationRequest, Identity identity, CorrelationID correlationId, String requestLabel) Send the specified authorizationRequest and update the specified identity with the results.sendAuthorizationRequest
(Request authorizationRequest, Identity identity, EventQueue eventQueue, CorrelationID correlationId) Send the specified authorizationRequest and update the specified identity with the results.sendAuthorizationRequest
(Request authorizationRequest, Identity identity, EventQueue eventQueue, CorrelationID correlationId, String requestLabel) Send the specified authorizationRequest and update the specified identity with the results.sendAuthorizationRequest
(Request authorizationRequest, UserHandle identity, CorrelationID correlationId) Deprecated.as of 3.3.0, usesendAuthorizationRequest(Request, Identity, CorrelationID)
insteadsendAuthorizationRequest
(Request authorizationRequest, UserHandle identity, CorrelationID correlationId, String requestLabel) Deprecated.as of 3.3.0, usesendAuthorizationRequest(Request, Identity, CorrelationID, String)
insteadsendAuthorizationRequest
(Request authorizationRequest, UserHandle identity, EventQueue eventQueue, CorrelationID correlationId) Deprecated.as of 3.3.0, usesendAuthorizationRequest(Request, Identity, EventQueue, CorrelationID)
insteadsendAuthorizationRequest
(Request authorizationRequest, UserHandle identity, EventQueue eventQueue, CorrelationID correlationId, String requestLabel) Deprecated.as of 3.3.0, usesendAuthorizationRequest(Request, Identity, EventQueue, CorrelationID, String)
insteadboolean
start()
Issue a blocking call to start the session.void
Initiate a non blocking call to start the session.void
stop()
Stops this session.void
stop
(AbstractSession.StopOption stopOption) Stops the operation of this session.Tries to retrieve the next event available for processing on this session
-
Method Details
-
start
Issue a blocking call to start the session.Issue a blocking call to start the session. This call returns true if the Session was started successfully or false otherwise. Also a
Event.EventType.SESSION_STATUS
event may be published containing a message with the result of the request. If the Session was started successfully a "SessionStarted" message will be generated. If the start failed a "SessionStartupFailure" message may be generated.Note: If this is an asynchronous Session then the
Event.EventType.SESSION_STATUS
may be processed by the registeredEventHandler
before this method has returned. If this Session is using an externalEventDispatcher
, it should be already started.A Session may only be started once
- Returns:
- true if session started successfully, false otherwise
- Throws:
IOException
- If an I/O Error occursInterruptedException
- If this thread was interrupted
-
startAsync
Initiate a non blocking call to start the session.Initiate a non blocking call to start the session and return immediately On completion of this request a
Event.EventType.SESSION_STATUS
event is published containing a message with the result of the request. If the Session was started successfully a "SessionStarted" message will be generated. If the start failed a "SessionStartupFailure" message will be generated.Note: If this is an asynchronous Session then the
Event.EventType.SESSION_STATUS
may be processed by the registeredEventHandler
before this method has returned. If this Session is using an externalEventDispatcher
, it should be already started.A Session may only be started once
- Throws:
IllegalStateException
- If the session is in an invalid stateIOException
- If an I/O Error occurs
-
stop
Stops this session.Same as calling
stop(StopOption)
withAbstractSession.StopOption
.SYNC
- Throws:
InterruptedException
- if another thread has interrupted the current thread
-
stop
Stops the operation of this session.If the specified stopOption is
AbstractSession.StopOption.SYNC
then this call blocks until all events relating to this session which are currently being processed have returned from a application suppliedEventHandler
objects. Once this call returns no further callbacks to EventHandlers will occur. If a synchronous stop() is called from within an EventHandler callback, the behavior is undefined and may result in a deadlock.If the specified stopOption is
AbstractSession.StopOption.ASYNC
then the stop call returns immediately and events may still be being processed in user specifiedEventHandler
objects.- Parameters:
stopOption
- determines whether the calling thread will wait for stop to complete.- Throws:
InterruptedException
- if another thread has interrupted the current thread
-
nextEvent
Retrieves the next event available for processing on this sessionThis method is the same as calling
nextEvent(0)
- Returns:
- next event available on this session
- Throws:
InterruptedException
- if another thread has interrupted the current threadIllegalStateException
- if an event handler was specified at construction
-
nextEvent
Retrieves the next event available for processing on this sessionIf no event is available immediately wait for
timeoutMillis
milliseconds for an event to arrive. If no event is received before the timeout expires return aEvent.EventType.TIMEOUT
event. If the timeout specified is 0 then wait for an infinite amount of time for an event to be received. Note that this function cannot be called on a Session that is operating in "asynchronous" mode. That is a Session that was constructed with anEventHandler
.- Parameters:
timeoutMillis
- timeout in milliseconds to wait for an event to be available on the Session- Returns:
- next event available on this session if available before timeout or
Event.EventType.TIMEOUT
event if timeout occurs - Throws:
InterruptedException
- if another thread has interrupted the current threadIllegalStateException
- if an event handler was specified at construction
-
tryNextEvent
Tries to retrieve the next event available for processing on this sessionThis method never blocks. Note that this function cannot be called on a Session that is operating in "asynchronous" mode. That is a Session that was constructed with an
EventHandler
.- Returns:
- next event available on this session if available or null if no event is available immediately
-
openServiceAsync
Issue an asynchronous request to open a service.Same as calling
openServiceAsync(String, CorrelationID)
- Parameters:
serviceIdentifier
- the service that is to be opened- Returns:
- a CorrelationID for this asynchronous openService request.
- Throws:
IllegalStateException
- if the Session is not openedIOException
- if any I/O Error occurs
-
openServiceAsync
public void openServiceAsync(String serviceIdentifier, CorrelationID correlationId) throws IOException Initiate an asynchronous request to open a service.Initiate a request to open the service having the specified
serviceIdentifier
. The specified 'serviceIdentifier' must contain a fully qualified service name. That is it must be of the form"//<namespace>/<service-name>"
Once the request has completed, a
Event.EventType.SERVICE_STATUS
event will be generated indicating the result of the request. ThecorrelationId
will be returned in generated message. It can also be used to cancel this request before it completes by calling thecancel
operation. Note the supplied correlationId MUST BE unique from any "active" correlation supplied to this session via any operation(e.g., "subscribe", "sendRequest"). A correlation id is active if the request for which it was supplied is still pending, or if it refers to a subscription request that has not been terminated either explicitly or by an unsolicited termination.- Parameters:
serviceIdentifier
- the service that is to be openedcorrelationId
- a correlation Id for correlating this request- Throws:
IllegalStateException
- if the Session is not openedIOException
- if any I/O Error occursDuplicateCorrelationIDException
- if correlationId is already "active"- See Also:
-
openService
Open the service having the specifiedserviceIdentifier
The specified 'serviceIdentifier' must must contain a fully qualified service name. That is it must be of the form
"//<namespace>/<service-name"
. Note that this operation is a blocking operation which may require communication to server-side services. Execution may be be blocked for an undetermined amount of time. If blocking is not desired, then useopenServiceAsync
instead.This method returns true if the service was opened successfully false otherwise. Once the request has completed, a
Event.EventType.SERVICE_STATUS
event will be generated indicating the result of the request. If this is an asynchronous Session then thisEvent
may be processed by the registeredEventHandler
before openService() has returned.- Parameters:
serviceIdentifier
- service to open- Returns:
- true if the service was successfully opened false otherwise
- Throws:
InterruptedException
IOException
-
getService
Return a handle to aService
object representing the service identified by the specified 'serviceIdentifier'The serviceIdentifier must contain a fully qualified service name. That is, it must be of the form
"//<namespace>/<service-name>"
. If the specified service is not already open a null handle is returned.- Parameters:
serviceIdentifier
- the serviceIdentifier of the service for which a handle should be returned- Returns:
- a handle to the service if it is already open null otherwise
-
sendAuthorizationRequest
public CorrelationID sendAuthorizationRequest(Request authorizationRequest, Identity identity, CorrelationID correlationId) throws IOException Send the specified authorizationRequest and update the specified identity with the results.Same as calling
sendAuthorizationRequest(authorizationRequest, identity, null, correlationId, null)
- Parameters:
authorizationRequest
- filled in authorization request that needs to be sent to the authorization serviceidentity
- a handle to identify the user that is being authorizedcorrelationId
- the correlator to be used for correlating the response to this request- Returns:
- a internally generated CorrelationID if the specified correlationId is null or return the specified correlationId
- Throws:
IllegalStateException
- If the session is not establishedInvalidRequestException
- If the request is not compliant with the schema for the requestRequestQueueOverflowException
- If this session has too many enqueued requestsIOException
- If any error occurs while sending the requestDuplicateCorrelationIDException
- If the specified correlationId is already active for this SessionIllegalArgumentException
- if the specified Identity was not created through this Session
-
sendAuthorizationRequest
@Deprecated public CorrelationID sendAuthorizationRequest(Request authorizationRequest, UserHandle identity, CorrelationID correlationId) throws IOException Deprecated.as of 3.3.0, usesendAuthorizationRequest(Request, Identity, CorrelationID)
instead- Throws:
IOException
-
sendAuthorizationRequest
public CorrelationID sendAuthorizationRequest(Request authorizationRequest, Identity identity, CorrelationID correlationId, String requestLabel) throws IOException Send the specified authorizationRequest and update the specified identity with the results.Same as calling
sendAuthorizationRequest(authorizationRequest, identity, null, correlationId, requestLabel)
- Parameters:
authorizationRequest
- filled in authorization request that needs to be sent to the authorization serviceidentity
- a handle to identify the user that is being authorizedcorrelationId
- the correlator to be used for correlating the response to this request- Returns:
- a internally generated CorrelationID if the specified correlationId is null or return the specified correlationId
- Throws:
IllegalStateException
- If the session is not establishedInvalidRequestException
- If the request is not compliant with the schema for the requestRequestQueueOverflowException
- If this session has too many enqueued requestsIOException
- If any error occurs while sending the requestDuplicateCorrelationIDException
- If the specified correlationId is already active for this SessionIllegalArgumentException
- if the specified Identity was not created through this Session
-
sendAuthorizationRequest
@Deprecated public CorrelationID sendAuthorizationRequest(Request authorizationRequest, UserHandle identity, CorrelationID correlationId, String requestLabel) throws IOException Deprecated.as of 3.3.0, usesendAuthorizationRequest(Request, Identity, CorrelationID, String)
instead- Throws:
IOException
-
sendAuthorizationRequest
public CorrelationID sendAuthorizationRequest(Request authorizationRequest, Identity identity, EventQueue eventQueue, CorrelationID correlationId) throws IOException Send the specified authorizationRequest and update the specified identity with the results.Same as calling
sendAuthorizationRequest(authorizationRequest, identity, eventQueue, correlationId, null)
- Parameters:
authorizationRequest
- filled in authorization request that needs to be sent to the authorization serviceidentity
- a handle to identify the user that is being authorizedeventQueue
- an optional event queue to receive events for this requestcorrelationId
- the correlator to be used for correlating the response to this request- Returns:
- a internally generated CorrelationID if the specified correlationId is null or return the specified correlationId
- Throws:
IllegalStateException
- If the session is not establishedInvalidRequestException
- If the request is not compliant with the schema for the requestRequestQueueOverflowException
- If this session has too many enqueued requestsIOException
- If any error occurs while sending the requestDuplicateCorrelationIDException
- If the specified correlationId is already active for this SessionIllegalArgumentException
- if the specified Identity was not created through this Session
-
sendAuthorizationRequest
@Deprecated public CorrelationID sendAuthorizationRequest(Request authorizationRequest, UserHandle identity, EventQueue eventQueue, CorrelationID correlationId) throws IOException Deprecated.as of 3.3.0, usesendAuthorizationRequest(Request, Identity, EventQueue, CorrelationID)
instead- Throws:
IOException
-
sendAuthorizationRequest
public CorrelationID sendAuthorizationRequest(Request authorizationRequest, Identity identity, EventQueue eventQueue, CorrelationID correlationId, String requestLabel) throws IOException Send the specified authorizationRequest and update the specified identity with the results.This request can be used by applications to authorize users to receive data from services. If an user is successfully authorized all the entitlements for that user is cached locally. Once authorized the identity can be used to make subscriptions and requests as the user. Also the identity can be checked to ensure that the user has the required entitlements for accessing data that was retrieved using the default credentials.
This method sends the specified authorizationRequest to an authorization service that is available on this session. The specified correlationId is returned on the response and can be used to correlate the response to this request. If a null correlationId is specified then an internal CorrelationID is generated and returned.
If an eventQueue is specified then all response events for this Authorization Request are published to this eventQueue. Users can block on this event queue for response and can use this as a mechanism to convert this asynchronous request into a synchronous request
On completion of this requests an "RESPONSE" event is published containing a message with the result of the authorization request. If the user was successfully authorized an "AuthorizationSuccess" message will be generated. If the user was not authorized an "AuthorizationFailure" message will be generated.
Note that after completion of this request, "AUTHORIZATION_STATUS" update messages may be published through the event dispatcher provided in Session creation or generated in Session's EventQueue if the event dispatcher is not provided.
- Parameters:
authorizationRequest
- filled in authorization request that needs to be sent to the authorization serviceidentity
- a handle to identify the user that is being authorizedeventQueue
- an optional event queue to receive response for this requestcorrelationId
- the correlator to be used for correlating the response to this requestrequestLabel
- defines a string which will be recorded along with any diagnostics for this operation.- Returns:
- an internally generated CorrelationID if the specified correlationId is null or return the specified correlationId
- Throws:
IllegalStateException
- If the session is not establishedInvalidRequestException
- If the request is not compliant with the schema for the requestRequestQueueOverflowException
- If this session has too many enqueued requestsIOException
- If any error occurs while sending the requestDuplicateCorrelationIDException
- If the specified correlationId is already active for this SessionIllegalArgumentException
- if the specified Identity was not created through this Session or it is the session identity
-
sendAuthorizationRequest
@Deprecated public CorrelationID sendAuthorizationRequest(Request authorizationRequest, UserHandle identity, EventQueue eventQueue, CorrelationID correlationId, String requestLabel) throws IOException Deprecated.as of 3.3.0, usesendAuthorizationRequest(Request, Identity, EventQueue, CorrelationID, String)
instead- Throws:
IOException
-
cancel
Cancel an outstanding request or a subscription represented by the specified correlationIdSame as calling
cancel(correlationId, null)
-
cancel
Cancel an outstanding request or a subscription represented by the specified correlationIdThis operation provides a convenience of passing a single CorrelationID See
cancel(List, String)
operation for more information on the handling of cancel requests and other important notes. -
cancel
Cancel outstanding requests or subscriptions represented by the specified list of correlationIdsSame as calling {
cancel(correlators, null)
-
cancel
Cancel outstanding requests or subscriptions represented by the specified list of correlationIdsCancel a previous request or subscription for asynchronous topic updates associated with each correlationId specified in the list of correlators. Upon return, no further message will be generated for the request or subscription associated with the specified correlationIds.
NOTE:
1) For asynchronous sessions, a handler may still be processing an existing message for the associated request or subscription after the call returns. That is while iterating over an event, if any message is encountered for a cancelledCorrelationID
, it will be silently ignored, but if the message was iterated to just prior to the completion of the cancel request it will be delivered, it is up to the application developer to handle this condition.
2) If any of the specified CorrelationIds do not refer to an "active" request or Subscription then, that particularCorrelationID
will be ignored. This behavior is to avoid sporadic failures when unsolicited subscription terminations and request failures are received just prior to an application attempting to explicitly cancel the pending requests or subscriptions.
3) Once this call returns, the specifiedCorrelationID
can be reused for new requests to this session. Also note that application developers should generally be cautions not to reuse a correlation id until all existing references within their applications have been cleared. Depending on the use of the correlation id, this can possibly result in accessing application resources which are no longer available. -
createIdentity
Return a new Identity which is valid but has not been authorized.Create a handle to represent a user of services. For using services with the specific user's credentials the identity should be authorized with the corresponding authorization service
-
createUserHandle
Deprecated.as of 3.3.0, usecreateIdentity()
instead -
generateToken
public CorrelationID generateToken(CorrelationID correlationId, EventQueue eventQueue) throws IOException, InterruptedException Return a generated token to be used for authorization.Generate a token to be used for authorization
- Parameters:
correlationId
- - a correlation Id for correlating this requesteventQueue
- to be used to receive response events for this request- Returns:
- a CorrelationID for this asynchronous token generation request.
- Throws:
IllegalStateException
- if the Session is not openedIOException
- if any I/O Error occursIllegalArgumentException
- if invalid authentication option is specified in session option or there is failure to get authentication information based on authentication optionInterruptedException
-
generateAuthorizedIdentity
Generates an authorizedIdentity
with an automatically generatedCorrelationID
.- Parameters:
authOptions
-AuthOptions
which will be used to generate theIdentity
.- Returns:
- automatically generated
CorrelationID
that will identify the messages associated with the generated identity. - See Also:
-
generateAuthorizedIdentity
Generates an authorizedIdentity
with the specifiedauthOptions
andcorrelationId
.One or more
Event.EventType.AUTHORIZATION_STATUS
events, zero or moreEvent.EventType.TOKEN_STATUS
events and zero or moreEvent.EventType.SERVICE_STATUS
events are generated.If this is an asynchronous session then an
Event
may be delivered to the registeredEventHandler
beforegenerateAuthorizedIdentity
has returned.The behavior is undefined if either
authOptions
orcorrelationId
is null.- Parameters:
authOptions
-AuthOptions
which will be used to generate theIdentity
.correlationId
-CorrelationID
that will identify the messages associated with the generated identity.- See Also:
-
getSessionIdentity
Returns the session identity if it is authorized.- Returns:
- the session identity.
- Throws:
NotFoundException
- if the session identity is not authorized.
-
getAuthorizedIdentity
Returns the authorized identity associated withcorrelationId
.- Parameters:
correlationId
-CorrelationID
associated with anIdentity
.- Returns:
Identity
associated withcorrelationId
.- Throws:
NotFoundException
- if there is no identity associated tocorrelationId
or the associated identity is not authorized.
-
generateToken
public CorrelationID generateToken(String userId, String ipAddress, CorrelationID correlationId, EventQueue eventQueue) throws IOException, InterruptedException Return a generated token to be used for authorization.Generate a token to be used for authorization
- Parameters:
userId
- usernameipAddress
- IPv4 or IPv6 addresscorrelationId
- - optional correlation Id for correlating this request. If null, a correlationId is generated internally.eventQueue
- to be used to receive response events for this request. If null, events for this request are delivered to the Session's event queue.- Returns:
- a CorrelationID for this asynchronous token generation request.
- Throws:
IllegalStateException
- if the Session is not openedIOException
- if any I/O Error occursIllegalArgumentException
- if invalid authentication option is specified in session option or there is failure to get authentication information based on authentication optionInterruptedException
-
generateToken
public CorrelationID generateToken(CorrelationID correlationId) throws IOException, InterruptedException Return a generated token to be used for authorization.Generate a token to be used for authorization
- Parameters:
correlationId
- - a correlation Id for correlating this request- Returns:
- a CorrelationID for this asynchronous token generation request.
- Throws:
IllegalStateException
- if the Session is not openedIOException
- if any I/O Error occursInterruptedException
-
generateToken
Return a generated token to be used for authorization.Generate a token to be used for authorization
-
createIdentity()
instead