Click or drag to resize
Session Class
This class provides a session for making requests and subscriptions to services.
Inheritance Hierarchy

Namespace:  Bloomberglp.Blpapi
Assembly:  Bloomberglp.Blpapi (in Bloomberglp.Blpapi.dll) Version: 3.15.0.1
Syntax
public class Session : AbstractSession

The Session type exposes the following members.

Constructors
  NameDescription
Public methodSession
Public methodSession(SessionOptions)
Creates a session with the specified sessionOptions.
Remarks
Values in sessionOptions are used for configuring this session.
Public methodSession(SessionOptions, EventHandler)
Creates a session with the specified sessionOptions and dispatch events on this session to the specified handler
Remarks
Values in sessionOptions are used for configuring this session. The event handler to which all events are delivered.
Public methodSession(SessionOptions, EventHandler, EventDispatcher)
Creates a session with the specified sessionOptions and dispatch events on this session using the provided dispatcher to the specified handler
Remarks
See SessionOptions for information on what options can be specified.

If the specified eventHandler is not null then this Session will operate in asynchronous mode, otherwise the Session will operate in Synchronous mode.

If eventDispatcher is null then the Session will create a default EventDispatcher for this Session which will use a single thread for dispatching events. For more control over event dispatching a specific instance of EventDispatcher can be supplied. This can be used to share a single EventDispatcher among multiple Session objects.

If an eventDispatcher is supplied which uses more than one thread the Session will ensure that events which should be ordered are passed to callbacks in a correct order. For example, updates to a single subscription.

Each EventDispatcher uses its own thread or pool of threads so if you want to ensure that a session which receives very large messages and takes a long time to process them does not delay a session that receives small messages and processes each one very quickly then give each one a separate EventDispatcher.

Values in sessionOptions are used for configuring this session. The event handler to which all events are delivered. The dispatcher to be used for dispatching events.
Top
Methods
  NameDescription
Public methodCancel(CorrelationID)
Cancels an outstanding request or a subscription represented by the specified correlationId.
(Inherited from AbstractSession.)
Public methodCancel(IListCorrelationID)
Cancels outstanding requests or subscriptions represented by the specified list of correlationIds.
(Inherited from AbstractSession.)
Public methodCancel(CorrelationID, String)
Cancels an outstanding request or a subscription represented by the specified correlationId.
(Inherited from AbstractSession.)
Public methodCancel(IListCorrelationID, String)
Cancels outstanding requests or subscriptions represented by the specified list of correlationIds.
(Inherited from AbstractSession.)
Public methodCreateIdentity
Returns a new Identity which is valid but has not been authorized.
(Inherited from AbstractSession.)
Public methodcreateSnapshotRequestTemplate(String, CorrelationID)
Same as calling createSnapshotRequestTemplate( subscriptionString, statusCid, null)

The session identity will be used if it's been authorized.

Public methodcreateSnapshotRequestTemplate(String, CorrelationID, Identity)
Create a snapshot service request template for getting subscription data specified by the 'subscriptionString' using the optionally specified 'identity' if all the following conditions are met: the session is established, 'subscriptionString' is a valid subscription string and 'statusCid' is not used in this session. If one or more conditions are not met, an exception is thrown. The provided 'statusCid' will be used for an implied subscription associated with the create request template. The created request template status updates will be delivered using ADMIN events.

The benefit of the snapshot service request templates is that these requests may be serviced from a cache and the user may expect to see significantly lower response time.

There are 3 possible states for a created request template: 'Pending', 'Available', and 'Terminated'. A 'RequestTemplate' is initially in the 'Pending' state.

The user may send a request using a template that is in 'Pending' state. If this succeeds, the state of that template changes to 'Available'. Note that response times to receive data may be longer than a response time for a request in the 'Available' state since request caches may not yet have been established. A template may transition back into 'Pending' state from the 'Available' state, in which case a 'RequestTemplatePending' message will be generated.

If state is 'Available', all requests will be serviced from a cache and the user may expect to see significantly reduced latency. Note, that a snapshot request template can transition out of the 'Available' state concurrently with requests being sent, so no guarantee of service from the cache can be provided. Request template may transition into 'Available' state only from the 'Pending' state. In this case the 'RequestTemplateAvailable' message is generated. This message will also contain information about currently used connection in the 'boundTo' field. Note that it is possible to get the 'RequestTemplateAvailable' message with a new connection information, even if a request template is already in the 'Available' state.

If state is 'Terminated', sending request will always result in a failure response. Request template may transition into this state from any other state. This is a final state and it is guaranteed that the last message associated with the provided 'statusCid' will be the 'RequestTemplateTerminated' message which is generated when a request template transitions into this state. If a request template transitions into this state, all outstanding requests will be failed and appropriate messages will be generated for each request. After receiving the 'RequestTemplateTerminated' message, 'statusCid' may be reused.

Note that resources used by a snapshot service request template are released only when request template transitions into the 'Terminated' state or when session is destroyed. In order to release resources when request template is not needed anymore, user should call Cancel(CorrelationID) or close unless the 'RequestTemplateTerminated' message was already received due to some problems. If the 'Session.cancel' method is used, all outstanding requests are canceled and the underlying subscription is closed immediately. If the handle is closed with the 'RequestTemplate.close' method, the underlying subscription is closed only when all outstanding requests are served. Note that it is possible to have a situation when response contain data that were sent by a backend before user actually sends a request template. For example it is possible if user requested data were already in an incoming TCP queue.

Public methodCreateUserHandle Obsolete. (Inherited from AbstractSession.)
Protected methodDispatchEvent
Dispatch event with event handler if it has been set otherwise do nothing. Event handlers are set by a library client in case of async session. SetEventHandler(SessionEventHandler), SetEventHandler(SessionEventHandler, EventEventType), EventEventType
(Inherited from AbstractSession.)
Public methodGenerateAuthorizedIdentity
Generates an authorized Identity with the specified authOptions and cid.

One or more AUTHORIZATION_STATUS events, zero or more TOKEN_STATUS events and zero or more SERVICE_STATUS events are generated. If this is an asynchronous AbstractSession then an Event may be processed by the registered EventHandler before GenerateAuthorizedIdentity(AuthOptions, CorrelationID) has returned.

The behavior is undefined when authOptions is null.

(Inherited from AbstractSession.)
Public methodGenerateToken
Return a generated token to be used for authorization.
(Inherited from AbstractSession.)
Public methodGenerateToken(CorrelationID)
Return a generated token to be used for authorization.
(Inherited from AbstractSession.)
Public methodGenerateToken(CorrelationID, EventQueue)
Return a generated token to be used for authorization.
(Inherited from AbstractSession.)
Public methodGenerateToken(String, String, CorrelationID, EventQueue)
Return a generated token to be used for authorization.
(Inherited from AbstractSession.)
Public methodGetAuthorizedIdentity
Gets the authorized Identity associated with the specified cid.

If cid is omitted and the session identity is authorized, the function will return the session identity.

(Inherited from AbstractSession.)
Public methodGetService
Returns a handle to a Service object representing the service identified by the specified uri.
(Inherited from AbstractSession.)
Public methodGetSubscriptions
Returns an enumerable collection for iterating over the subscriptions.
Public methodGetSubscriptionStatus
Returns the subscription status for the specified correlationId.
Public methodGetSubscriptionString
Returns the subscription string for the specified correlationId.
Protected methodInit
Initialize AbstractSession. Must be called from the constructor(s) of the derived class.
(Inherited from AbstractSession.)
Public methodNextEvent
Returns the next event available for processing on this session.
(Inherited from AbstractSession.)
Public methodNextEvent(Int64)
Returns the next event available for processing on this session.
(Inherited from AbstractSession.)
Public methodOpenService
Opens the service having the specified uri.
(Inherited from AbstractSession.)
Public methodOpenServiceAsync(String)
Issues an asynchronous request to open a service.
(Inherited from AbstractSession.)
Public methodOpenServiceAsync(String, CorrelationID)
Initiates an asynchronous request to open a service.
(Inherited from AbstractSession.)
Public methodResubscribe(IListSubscription)
Modifies each subscription in the specified subscriptionList to reflect the modified options specified for it.
Public methodResubscribe(IListSubscription, Int32)
Modifies each subscription in the specified subscriptionList to reflect the modified options specified for it.
Public methodResubscribe(IListSubscription, String)
Modifies each subscription in the specified subscriptionList to reflect the modified options specified for it.
Public methodResubscribe(IListSubscription, Int32, String)
Modifies each subscription in the specified subscriptionList to reflect the modified options specified for it.
Public methodSendAuthorizationRequest(Request, Identity, CorrelationID)
Sends the specified authorizationRequest and update the specified identity with the results.
(Inherited from AbstractSession.)
Public methodSendAuthorizationRequest(Request, UserHandle, CorrelationID) Obsolete.
Deprecated since 3.3.0.0. Use SendAuthorizationRequest(Request, Identity, CorrelationID)instead.
(Inherited from AbstractSession.)
Public methodSendAuthorizationRequest(Request, Identity, CorrelationID, String)
Sends the specified authorizationRequest and update the specified identity with the results.
(Inherited from AbstractSession.)
Public methodSendAuthorizationRequest(Request, Identity, EventQueue, CorrelationID)
Sends the specified authorizationRequest and update the specified identity with the results.
(Inherited from AbstractSession.)
Public methodSendAuthorizationRequest(Request, UserHandle, CorrelationID, String) Obsolete. (Inherited from AbstractSession.)
Public methodSendAuthorizationRequest(Request, UserHandle, EventQueue, CorrelationID) Obsolete. (Inherited from AbstractSession.)
Public methodSendAuthorizationRequest(Request, Identity, EventQueue, CorrelationID, String)
Sends the specified authorizationRequest and update the specified identity with the results.
(Inherited from AbstractSession.)
Public methodSendAuthorizationRequest(Request, UserHandle, EventQueue, CorrelationID, String) Obsolete. (Inherited from AbstractSession.)
Public methodSendRequest(RequestTemplate)
Same as calling 'SendRequest(requestTemplate, null)'
Public methodSendRequest(Request, CorrelationID)
Sends the specified request to a service using this session.

The session identity will be used if it's been authorized.

Public methodSendRequest(RequestTemplate, CorrelationID)
Send a request defined by the specified 'requestTemplate'. If the optionally specified 'correlationId' is supplied, use it otherwise create a new 'CorrelationId'. The actual 'CorrelationId' used is returned. A successful request will generate zero or more 'PARTIAL_RESPONSE' events followed by exactly one 'RESPONSE' event. Once the final 'RESPONSE' event has been received the 'CorrelationId' associated with this request may be re-used. If the request fails at any stage a 'REQUEST_STATUS' will be generated after which the 'CorrelationId' associated with the request may be re-used.
Public methodSendRequest(Request, CorrelationID, String)
Sends the specified request to a service using this session.

The session identity will be used if it's been authorized.

Public methodSendRequest(Request, EventQueue, CorrelationID)
Sends the specified request to a service using this session.

The session identity will be used if it's been authorized.

Public methodSendRequest(Request, Identity, CorrelationID)
Sends the specified request to a service using this session.
Public methodSendRequest(Request, UserHandle, CorrelationID) Obsolete.
Deprecated since 3.3.0.0. Use SendRequest(Request, Identity, CorrelationID) instead.
Public methodSendRequest(Request, EventQueue, CorrelationID, String)
Sends the specified request to a service using this session.
Public methodSendRequest(Request, Identity, CorrelationID, String)
Sends the specified request to a service using this session.
Public methodSendRequest(Request, Identity, EventQueue, CorrelationID)
Sends the specified request to a service using this session.
Public methodSendRequest(Request, UserHandle, CorrelationID, String) Obsolete.
Deprecated since 3.3.0.0. Use SendRequest(Request, Identity, CorrelationID, String) instead.
Public methodSendRequest(Request, UserHandle, EventQueue, CorrelationID) Obsolete.
Deprecated since 3.3.0.0. Use SendRequest(Request, Identity, EventQueue, CorrelationID) instead.
Public methodSendRequest(Request, Identity, EventQueue, CorrelationID, String)
Sends the specified request to a service using this session.
Public methodSendRequest(Request, UserHandle, EventQueue, CorrelationID, String) Obsolete.
Public methodSetEventHandler
Set event specific event handlers
Public methodStart
Issues a blocking call to start the session.
(Inherited from AbstractSession.)
Public methodStartAsync
Initiates a non blocking call to start the session.
(Inherited from AbstractSession.)
Public methodStop
Stops this session.
(Inherited from AbstractSession.)
Public methodStop(AbstractSessionStopOption)
Stops the operation of this session.
(Inherited from AbstractSession.)
Public methodSubscribe(IListSubscription)
Initiates a request to receive asynchronous updates to the specified topics.

The session identity will be used if it's been authorized.

Public methodSubscribe(IListSubscription, Identity)
Initiates a request to receive asynchronous updates to the specified topics.
Public methodSubscribe(IListSubscription, UserHandle) Obsolete.
Public methodSubscribe(IListSubscription, String)
Initiates a request to receive asynchronous updates to the specified topics.

The session identity will be used if it's been authorized.

Public methodSubscribe(IListSubscription, Identity, String)
Initiates a request to receive asynchronous updates to the specified topics in the subscriptionList.
Public methodSubscribe(IListSubscription, UserHandle, String) Obsolete.
Public methodTryNextEvent
Tries to retrieve the next event available for processing on this session
(Inherited from AbstractSession.)
Public methodUnsubscribe(CorrelationID) Obsolete.
Cancels a previous request for asynchronous topic updates associated with the specified correlationId.
Public methodUnsubscribe(IListSubscription)
Cancels previous requests for asynchronous topic updates associated with the correlation ids listed in the specified subscriptionList.
Public methodUnsubscribe(IListSubscription, String)
Cancels previous requests for asynchronous topic updates associated with the correlation ids listed in the specified subscriptionList.
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implementationPrivate methodIDisposableDispose
Dispose this Session object. It calls AbstractSession.Stop() to close the opened socket.
(Inherited from AbstractSession.)
Top
Remarks

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.

A Session is asynchronous if an EventHandler object is supplied whenit is constructed. The SetEventHandler() method may be called to adjust the way events are handled subsequently and the NextEvent() method may not be called. All incoming events are delivered to the EventHandler(s) supplied on construction or subsequently using SetEventHandler().

A Session is synchronous if an EventHandler object is not supplied when it is constructed. The NextEvent() method must be called to read incoming events and the SetEventHandler() method may not be called. Several methods in Session take a CorrelationID parameter. The application may choose to supply its own CorrelationID values or allow the Session to create values. If the application supplies its own CorrelationID values it must manage their lifetime such that the same value is not reused for more than one operation at a time. The lifetime of a CorrelationID begins when it is supplied in a method invoked on a Session and ends either when it is explicitly cancelled using Cancel(CorrelationID), when a Event.EventType.RESPONSE Event (not a PARTIAL_RESPONSE) containing it is received or when a Event.EventType.SUBSCRIPTION_STATUS Event which indicates that the subscription it refers to has been terminated is received.

When using an asynchronous Session the application must be aware that because the callbacks are generated from another thread they may be processed before the call which generates them has returned. For example, the Event.EventType.SESSION_STATUS Event generated by the StartAsync may be processed before StartAsync() has returned (even though StartAsync() itself will not block).

This becomes more significant when Session generated CorrelationIds are in use. For example, if a call to Subscribe() which returns a Session generated CorrelationID has not completed before the first Events which contain that CorrelationID arrive the application may not be able to interpret those events correctly. For this reason, it is preferable to use user generated CorrelationIDs when using asynchronous Sessions. This issue does not arise when using a synchronous Session as long as the calls to Subscribe() etc are made on the same thread as the calls to NextEvent().

Thread Safety
Static members of this type are safe for multi-threaded operations. Instance members of this type are safe for multi-threaded operations.
Thread Safety
Static members of this type are safe for multi-threaded operations. Instance members of this type are safe for multi-threaded operations.
See Also