public abstract class AbstractSession extends Object
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.
"//<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 /.| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractSession.StopOption
Enumerations for controlled shutdown of the session
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel(CorrelationID correlationId)
Cancel an outstanding request or a subscription represented by the
specified correlationId
|
void |
cancel(CorrelationID correlationId,
String requestLabel)
Cancel an outstanding request or a subscription represented by the
specified correlationId
|
void |
cancel(List<CorrelationID> correlators)
Cancel outstanding requests or subscriptions represented by the
specified list of correlationIds
|
void |
cancel(List<CorrelationID> correlators,
String requestLabel)
Cancel outstanding requests or subscriptions represented by the
specified list of correlationIds
|
Identity |
createIdentity()
Return a new Identity which is valid but has not been authorized.
|
UserHandle |
createUserHandle()
Deprecated.
as of 3.3.0, use
createIdentity() instead |
CorrelationID |
generateToken()
Return a generated token to be used for authorization.
|
CorrelationID |
generateToken(CorrelationID correlationId)
Return a generated token to be used for authorization.
|
CorrelationID |
generateToken(CorrelationID correlationId,
EventQueue eventQueue)
Return a generated token to be used for authorization.
|
CorrelationID |
generateToken(String userId,
String ipAddress,
CorrelationID correlationId,
EventQueue eventQueue)
Return a generated token to be used for authorization.
|
Service |
getService(String serviceIdentifier)
Return a handle to a
Service object representing the service
identified by the specified 'serviceIdentifier' |
Event |
nextEvent()
Retrieves the next event available for processing on this session
|
Event |
nextEvent(long timeoutMillis)
Retrieves the next event available for processing on this session
|
boolean |
openService(String serviceIdentifier)
Open the service having the specified
serviceIdentifier |
CorrelationID |
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.
|
CorrelationID |
sendAuthorizationRequest(Request authorizationRequest,
Identity identity,
CorrelationID correlationId)
Send the specified authorizationRequest and update the specified
identity with the results.
|
CorrelationID |
sendAuthorizationRequest(Request authorizationRequest,
Identity identity,
CorrelationID correlationId,
String requestLabel)
Send the specified authorizationRequest and update the specified
identity with the results.
|
CorrelationID |
sendAuthorizationRequest(Request authorizationRequest,
Identity identity,
EventQueue eventQueue,
CorrelationID correlationId)
Send the specified authorizationRequest and update the specified
identity with the results.
|
CorrelationID |
sendAuthorizationRequest(Request authorizationRequest,
Identity identity,
EventQueue eventQueue,
CorrelationID correlationId,
String requestLabel)
Send the specified authorizationRequest and update the specified
identity with the results.
|
CorrelationID |
sendAuthorizationRequest(Request authorizationRequest,
UserHandle identity,
CorrelationID correlationId)
Deprecated.
as of 3.3.0, use
sendAuthorizationRequest(Request, Identity,
CorrelationID) instead |
CorrelationID |
sendAuthorizationRequest(Request authorizationRequest,
UserHandle identity,
CorrelationID correlationId,
String requestLabel)
Deprecated.
as of 3.3.0, use
sendAuthorizationRequest(Request, Identity,
CorrelationID, String) instead |
CorrelationID |
sendAuthorizationRequest(Request authorizationRequest,
UserHandle identity,
EventQueue eventQueue,
CorrelationID correlationId)
Deprecated.
as of 3.3.0, use
sendAuthorizationRequest(Request, Identity, EventQueue,
CorrelationID) instead |
CorrelationID |
sendAuthorizationRequest(Request authorizationRequest,
UserHandle identity,
EventQueue eventQueue,
CorrelationID correlationId,
String requestLabel)
Deprecated.
as of 3.3.0, use
sendAuthorizationRequest(Request, Identity, EventQueue,
CorrelationID, String) instead |
boolean |
start()
Issue a blocking call to start the session.
|
void |
startAsync()
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.
|
Event |
tryNextEvent()
Tries to retrieve the next event available for processing on this
session
|
public boolean start()
throws IOException,
InterruptedException
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
registered EventHandler before this method has returned. If this
Session is using an external EventDispatcher, it should be
already started.
A Session may only be started once
IOException - If an I/O Error occursInterruptedException - If this thread was interruptedpublic void startAsync()
throws IOException
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
registered EventHandler before this method has returned. If this
Session is using an external EventDispatcher, it should be
already started.
A Session may only be started once
IllegalStateException - If the session is in an invalid stateIOException - If an I/O Error occurspublic void stop()
throws InterruptedException
Same as calling stop(StopOption)
with AbstractSession.StopOption.SYNC
InterruptedException - if another thread has interrupted the current threadpublic void stop(AbstractSession.StopOption stopOption) throws InterruptedException
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 supplied
EventHandler 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
specified EventHandler objects.
stopOption - determines whether the calling thread will wait for
stop to complete.InterruptedException - if another thread has interrupted the current threadpublic Event nextEvent() throws InterruptedException
This method is the same as calling nextEvent(0)
InterruptedException - if another thread has interrupted the current threadIllegalStateException - if an event handler was specified at constructionpublic Event nextEvent(long timeoutMillis) throws InterruptedException
If no event is available immediately wait for timeoutMillis
milliseconds for an event to arrive. If no event is received before the
timeout expires return a Event.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 an EventHandler.
timeoutMillis - timeout in milliseconds to wait for an event to be available
on the SessionEvent.EventType.TIMEOUT event if timeout occursInterruptedException - if another thread has interrupted the current threadIllegalStateException - if an event handler was specified at constructionpublic Event tryNextEvent()
This 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.
public CorrelationID openServiceAsync(String serviceIdentifier) throws IOException
Same as calling openServiceAsync(String, CorrelationID)
serviceIdentifier - the service that is to be openedIllegalStateException - if the Session is not openedIOException - if any I/O Error occurspublic void openServiceAsync(String serviceIdentifier, CorrelationID correlationId) throws IOException
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. The
correlationId will be returned in generated message. It can
also be used to cancel this request before it completes by calling the
cancel 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.
serviceIdentifier - the service that is to be openedcorrelationId - a correlation Id for correlating this requestIllegalStateException - if the Session is not openedIOException - if any I/O Error occursDuplicateCorrelationIDException - if correlationId is already "active"openService(String)public boolean openService(String serviceIdentifier) throws InterruptedException, IOException
serviceIdentifier
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 use
openServiceAsync
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 this Event may be processed by the registered
EventHandler before openService() has returned.
serviceIdentifier - service to openInterruptedExceptionIOExceptionpublic Service getService(String serviceIdentifier)
Service 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.
serviceIdentifier - the serviceIdentifier of the service for which a handle
should be returnedpublic CorrelationID sendAuthorizationRequest(Request authorizationRequest, Identity identity, CorrelationID correlationId) throws IOException
Same as calling
sendAuthorizationRequest(authorizationRequest,
identity, null, correlationId, null)
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 requestIllegalStateException - 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
Sessionpublic CorrelationID sendAuthorizationRequest(Request authorizationRequest, UserHandle identity, CorrelationID correlationId) throws IOException
sendAuthorizationRequest(Request, Identity,
CorrelationID) insteadIOExceptionpublic CorrelationID sendAuthorizationRequest(Request authorizationRequest, Identity identity, CorrelationID correlationId, String requestLabel) throws IOException
Same as calling
sendAuthorizationRequest(authorizationRequest,
identity, null, correlationId, requestLabel)
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 requestIllegalStateException - 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
Sessionpublic CorrelationID sendAuthorizationRequest(Request authorizationRequest, UserHandle identity, CorrelationID correlationId, String requestLabel) throws IOException
sendAuthorizationRequest(Request, Identity,
CorrelationID, String) insteadIOExceptionpublic CorrelationID sendAuthorizationRequest(Request authorizationRequest, Identity identity, EventQueue eventQueue, CorrelationID correlationId) throws IOException
Same as calling
sendAuthorizationRequest(authorizationRequest,
identity, eventQueue, correlationId, null)
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 requestIllegalStateException - 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
Sessionpublic CorrelationID sendAuthorizationRequest(Request authorizationRequest, UserHandle identity, EventQueue eventQueue, CorrelationID correlationId) throws IOException
sendAuthorizationRequest(Request, Identity, EventQueue,
CorrelationID) insteadIOExceptionpublic CorrelationID sendAuthorizationRequest(Request authorizationRequest, Identity identity, EventQueue eventQueue, CorrelationID correlationId, String requestLabel) throws IOException
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.
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.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
Sessionpublic CorrelationID sendAuthorizationRequest(Request authorizationRequest, UserHandle identity, EventQueue eventQueue, CorrelationID correlationId, String requestLabel) throws IOException
sendAuthorizationRequest(Request, Identity, EventQueue,
CorrelationID, String) insteadIOExceptionpublic void cancel(CorrelationID correlationId)
Same as calling cancel(correlationId, null)
public void cancel(CorrelationID correlationId, String requestLabel)
This 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.
public void cancel(List<CorrelationID> correlators)
Same as calling {cancel(correlators, null)
public void cancel(List<CorrelationID> correlators, String requestLabel)
Cancel 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 cancelled CorrelationID, 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 particular CorrelationID 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 specified CorrelationID 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.
public Identity createIdentity()
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
public UserHandle createUserHandle()
createIdentity() insteadpublic CorrelationID generateToken(CorrelationID correlationId, EventQueue eventQueue) throws IOException, InterruptedException
Generate a token to be used for authorization
correlationId - - a correlation Id for correlating this requesteventQueue - to be used to receive response events for this requestIllegalStateException - 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 optionInterruptedExceptionpublic CorrelationID generateToken(String userId, String ipAddress, CorrelationID correlationId, EventQueue eventQueue) throws IOException, InterruptedException
Generate a token to be used for authorization
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.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 optionInterruptedExceptionpublic CorrelationID generateToken(CorrelationID correlationId) throws IOException, InterruptedException
Generate a token to be used for authorization
correlationId - - a correlation Id for correlating this requestIllegalStateException - if the Session is not openedIOException - if any I/O Error occursInterruptedExceptionpublic CorrelationID generateToken() throws IOException, InterruptedException
Generate a token to be used for authorization
Copyright © 2019 Bloomberg L.P.. All rights reserved.