#include <blpapi_abstractsession.h>
Public Member Functions | |
virtual | ~AbstractSession () |
virtual bool | start ()=0 |
virtual bool | startAsync ()=0 |
virtual void | stop ()=0 |
virtual void | stopAsync ()=0 |
virtual Event | nextEvent (int timeout=0)=0 |
virtual int | tryNextEvent (Event *event)=0 |
bool | openService (const char *serviceIdentifier) |
CorrelationId | openServiceAsync (const char *serviceIdentifier, const CorrelationId &correlationId=CorrelationId()) |
CorrelationId | sendAuthorizationRequest (const Request &authorizationRequest, Identity *identity, const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0) |
void | cancel (const CorrelationId &correlationId) |
void | cancel (const std::vector< CorrelationId > &correlationIds) |
void | cancel (const CorrelationId *correlationIds, size_t numCorrelationIds) |
CorrelationId | generateToken (const CorrelationId &correlationId=CorrelationId(), EventQueue *eventQueue=0) |
Service | getService (const char *serviceIdentifier) const |
UserHandle | createUserHandle () |
Identity | createIdentity () |
blpapi_AbstractSession_t * | abstractSessionHandle () const |
Protected Member Functions | |
AbstractSession () | |
void | initAbstractSessionHandle (blpapi_AbstractSession_t *handle) |
This class provides an abstract session which defines shared interface between publish and consumer requests for Bloomberg
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 when it 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() or unsubscribe(), when a RESPONSE Event (not a PARTIAL_RESPONSE) containing it is received or when a 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 SESSION_STATUS Event generated by a 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().
blpapi::AbstractSession::AbstractSession | ( | ) | [protected] |
Create an abstract session object.
virtual blpapi::AbstractSession::~AbstractSession | ( | ) | [virtual] |
Destructor.
void blpapi::AbstractSession::initAbstractSessionHandle | ( | blpapi_AbstractSession_t * | handle | ) | [protected] |
Initialize the handle of this abstract session.
virtual bool blpapi::AbstractSession::start | ( | ) | [pure virtual] |
Attempt to start this Session and blocks until the Session has started or failed to start. If the Session is started successfully true
is returned, otherwise false
is returned. Before start() returns a SESSION_STATUS Event is generated. If this is an asynchronous Session then the SESSION_STATUS may be processed by the registered EventHandler before start() has returned. A Session may only be started once.
Implemented in blpapi::ProviderSession, and blpapi::Session.
virtual bool blpapi::AbstractSession::startAsync | ( | ) | [pure virtual] |
Attempt to begin the process to start this Session and return true
if successful, otherwise return false
. The application must monitor events for a SESSION_STATUS Event which will be generated once the Session has started or if it fails to start. If this is an asynchronous Session then the SESSION_STATUS Event may be processed by the registered EventHandler before startAsync() has returned. A Session may only be started once.
Implemented in blpapi::ProviderSession, and blpapi::Session.
virtual void blpapi::AbstractSession::stop | ( | ) | [pure virtual] |
Stop operation of this session and block until all callbacks to EventHandler objects relating to this Session which are currently in progress have completed (including the callback to handle the SESSION_STATUS Event with SessionTerminated message this call generates). Once this returns no further callbacks to EventHandlers will occur. If stop() is called from within an EventHandler callback the behavior is undefined and may result in a deadlock. Once a Session has been stopped it can only be destroyed.
Implemented in blpapi::ProviderSession, and blpapi::Session.
virtual void blpapi::AbstractSession::stopAsync | ( | ) | [pure virtual] |
Begin the process to stop this Session and return immediately. The application must monitor events for a SESSION_STATUS Event with SessionTerminated message which will be generated once the Session has been stopped. After this SESSION_STATUS Event no further callbacks to EventHandlers will occur. This method can be called from within an EventHandler callback to stop Sessions using non-default (external) EventDispatcher. Once a Session has been stopped it can only be destroyed.
Implemented in blpapi::ProviderSession, and blpapi::Session.
virtual Event blpapi::AbstractSession::nextEvent | ( | int | timeout = 0 |
) | [pure virtual] |
Return the next available Event for this session. If there is no event available this will block for up to the specified timeoutMillis
milliseconds for an Event to arrive. A value of 0 for timeoutMillis
(the default) indicates nextEvent() should not timeout and will not return until the next Event is available.
If nextEvent() returns due to a timeout it will return an event of type EventType::TIMEOUT
.
If this is invoked on a Session which was created in asynchronous mode an InvalidStateException is thrown.
Implemented in blpapi::ProviderSession, and blpapi::Session.
virtual int blpapi::AbstractSession::tryNextEvent | ( | Event * | event | ) | [pure virtual] |
If there are Events available for the session, load the next Event into event and return 0 indicating success. If there is no event available for the session, return a non-zero value with no effect on event. This method never blocks.
Implemented in blpapi::ProviderSession, and blpapi::Session.
bool blpapi::AbstractSession::openService | ( | const char * | serviceIdentifier | ) |
Attempt to open the service identified by the specified serviceIdentifier
and block until the service is either opened successfully or has failed to be opened. Return true
if the service is opened successfully and false
if the service cannot be successfully opened.
The serviceIdentifier
must contain a fully qualified service name. That is, it must be of the form "//<namespace>/<local-name>".
Before openService() returns a SERVICE_STATUS Event is generated. If this is an asynchronous Session then this Event may be processed by the registered EventHandler before openService() has returned.
CorrelationId blpapi::AbstractSession::openServiceAsync | ( | const char * | serviceIdentifier, | |
const CorrelationId & | correlationId = CorrelationId() | |||
) |
Begin the process to open the service identified by the specified serviceIdentifier
and return immediately. The optional specified correlationId
is used to track Events generated as a result of this call. The actual correlationId which will identify Events generated as a result of this call is returned.
The serviceIdentifier
must contain a fully qualified service name. That is, it must be of the form "//<namespace>/<local-name>".
The application must monitor events for a SERVICE_STATUS Event which will be generated once the service has been successfully opened or the opening has failed.
CorrelationId blpapi::AbstractSession::sendAuthorizationRequest | ( | const Request & | authorizationRequest, | |
Identity * | identity, | |||
const CorrelationId & | correlationId = CorrelationId() , |
|||
EventQueue * | eventQueue = 0 | |||
) |
Send the specified authorizationRequest
and update the specified identity
with the results. If the optionally specified correlationId
is supplied, it is used; otherwise create a CorrelationId. The actual CorrelationId used is returned. If the optionally specified eventQueue
is supplied all Events relating to this Request will arrive on that EventQueue.
The underlying user information must remain valid until the Request has completed successfully or failed.
A successful request will generate zero or more PARTIAL_RESPONSE Messages followed by exactly one RESPONSE Message. Once the final RESPONSE Message has been received the specified identity
will have been updated to contain the users entitlement information and the CorrelationId associated with the request may be re-used. If the request fails at any stage a REQUEST_STATUS will be generated, the specified identity
will not be modified and the CorrelationId may be re-used.
The identity
supplied must have been returned from this Session's createIdentity() method. For example
Identity handle(session.createIdentity()); session.sendAuthorizationRequest(authRequest, &handle, ...)
void blpapi::AbstractSession::cancel | ( | const CorrelationId & | correlationId | ) |
If the specified correlationId
identifies a current request then cancel that request.
Once this call returns the specified correlationId
will not be seen in any subsequent Message obtained from a MessageIterator by calling next(). However, any Message currently pointed to by a MessageIterator when cancel() is called is not affected even if it has the specified correlationId
. Also any Message where a reference has been retained by the application may still contain the correlationId
. For these reasons, although technically an application is free to re-use correlationId
as soon as this method returns it is preferable not to aggressively re-use correlation IDs, particularly with an asynchronous Session.
void blpapi::AbstractSession::cancel | ( | const std::vector< CorrelationId > & | correlationIds | ) |
For each value in the specified correlationIds
which identifies a current request then cancel that request. Any values in the specified correlationIds
which do not identify a current request are ignored.
Once this call returns the specified correlationIds
will not be seen in any subsequent Message obtained from a MessageIterator by calling next(). However, any Message currently pointed to by a MessageIterator when cancel() is called is not affected even if it has one of the specified correlationIds
. Also any Message where a reference has been retained by the application may still contain one of the correlationIds
. For these reasons, although technically an application is free to re-use any of the correlationIds
as soon as this method returns it is preferable not to aggressively re-use correlation IDs, particularly with an asynchronous Session.
void blpapi::AbstractSession::cancel | ( | const CorrelationId * | correlationIds, | |
size_t | numCorrelationIds | |||
) |
For each value specified correlationIds
and numCorrelationIds
which identifies a current request then cancel that request. Any specified CorrelationId's which do not identify a current request are ignored.
Once this call returns the specified correlationIds
will not be seen in any subsequent Message obtained from a MessageIterator by calling next(). However, any Message currently pointed to by a MessageIterator when cancel() is called is not affected even if it has one of the specified correlationIds
. Also any Message where a reference has been retained by the application may still contain one of the correlationIds
. For these reasons, although technically an application is free to re-use any of the correlationIds
as soon as this method returns it is preferable not to aggressively re-use correlation IDs, particularly with an asynchronous Session.
CorrelationId blpapi::AbstractSession::generateToken | ( | const CorrelationId & | correlationId = CorrelationId() , |
|
EventQueue * | eventQueue = 0 | |||
) |
Generate a token to be used for authorization. If invalid authentication option is specified in session option or there is failure to get authentication information based on authentication option, then an InvalidArgumentException is thrown.
Service blpapi::AbstractSession::getService | ( | const char * | serviceIdentifier | ) | const |
Return a 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>/<local-name>".
If the service identified by serviceIdentifier
is not open or registered already then a NotFoundException
is thrown.
UserHandle blpapi::AbstractSession::createUserHandle | ( | ) |
Deprecated: Use createIdentity() instead. TODO: doxy Return a UserHandle which is valid but has not been authorized.
Identity blpapi::AbstractSession::createIdentity | ( | ) |
Return a Identity which is valid but has not been authorized.
blpapi_AbstractSession_t* blpapi::AbstractSession::abstractSessionHandle | ( | ) | const |
Return the handle of this abstract session.