LSLightstreamerClient Class Reference
Inherits from | NSObject |
---|---|
Declared in | LSLightstreamerClient.h |
Overview
Façade class for the management of the communication to Lightstreamer Server.
Used to provide configuration settings, event handlers, operations for the control of the connection lifecycle, subscription handling and to send messages.
LIB_NAME
A constant string representing the name of the library.
@property (class, nonatomic, readonly, nonnull) NSString *LIB_NAME
Declared In
LSLightstreamerClient.h
LIB_VERSION
A constant string representing the version of the library.
@property (class, nonatomic, readonly, nonnull) NSString *LIB_VERSION
Declared In
LSLightstreamerClient.h
limitExceptionsUse
Reduces the use of exceptions for error reporting.
When set to YES, the following method calls will return nil, instead of throwing an exception, when called with invalid parameters:
Default: NO
Lifecycle: This property may be changed at any time.
@property (class, nonatomic, assign) BOOL limitExceptionsUse
Declared In
LSLightstreamerClient.h
– initWithServerAddress:adapterSet:
Creates an object to be configured to connect to a Lightstreamer server and to handle all the communications with it.
Each LSLightstreamerClient is the entry point to connect to a Lightstreamer server, subscribe to as many items as needed and to send messages.
- (nonnull instancetype)initWithServerAddress:(nullable NSString *)serverAddress adapterSet:(nullable NSString *)adapterSet
Parameters
serverAddress |
The address of the Lightstreamer Server to which this LightstreamerClient will connect to. It is possible to specify it later by using nil here. See [LSConnectionDetails serverAddress] for details. |
---|---|
adapterSet |
The name of the Adapter Set mounted on Lightstreamer Server to be used to handle all requests in the Session associated with this LightstreamerClient. It is possible not to specify it at all or to specify it later by using nil here. See [LSConnectionDetails adapterSet] for details. |
Exceptions
NSException |
if a not valid address is passed. See [LSConnectionDetails serverAddress] for details. |
---|
Declared In
LSLightstreamerClient.h
connectionOptions
Object that contains options and policies for the connection to the server.
This instance is set up by the LSLightstreamerClient object at its own creation.
Properties of this object can be overwritten by values received from a Lightstreamer Server.
@property (nonatomic, readonly, nonnull) LSConnectionOptions *connectionOptions
Declared In
LSLightstreamerClient.h
connectionDetails
Object that contains the details needed to open a connection to a Lightstreamer Server.
This instance is set up by the LightstreamerClient object at its own creation.
Properties of this object can be overwritten by values received from a Lightstreamer Server.
@property (nonatomic, readonly, nonnull) LSConnectionDetails *connectionDetails
Declared In
LSLightstreamerClient.h
– addDelegate:
Adds a delegate that will receive events from the LSLightstreamerClient instance.
The same delegate can be added to several different LSLightstreamerClient instances.
Lifecycle: a delegate can be added at any time. A call to add a delegate already present will be ignored.
- (void)addDelegate:(nonnull id<LSClientDelegate>)delegate
Parameters
delegate |
An object that will receive the events as documented in the LSClientDelegate interface. Note: delegates are stored with weak references: make sure you keep a strong reference to your delegates or they may be released prematurely. |
---|
See Also
Declared In
LSLightstreamerClient.h
– connect
Operation method that requests to open a Session against the configured Lightstreamer Server.
When connect
is called, unless a single transport was forced through [LSConnectionOptions forcedTransport], the so called “Stream-Sense” mechanism is started:
if the client does not receive any answer for some seconds from the streaming connection, then it will automatically open a polling connection.
A polling connection may also be opened if the environment is not suitable for a streaming connection.
Note that as “polling connection” we mean a loop of polling requests, each of which requires opening a synchronous (i.e. not streaming) connection to Lightstreamer Server.
Lifecycle: note that the request to connect is accomplished by the client in a separate thread; this means that an invocation of status right after connect might not reflect the change yet.
When the request to connect is finally being executed, if the current status of the client is CONNECTING
, CONNECTED:*
or STALLED
, then nothing will be done.
- (void)connect
Exceptions
NSException |
if no server address was configured. |
---|---|
NSException |
if a [LSConnectionOptions maxConcurrentSessionsPerServerExceededPolicy] of |
See Also
Declared In
LSLightstreamerClient.h
– disconnect
Operation method that requests to close the Session opened against the configured Lightstreamer Server (if any).
When disconnect
is called, the “Stream-Sense” mechanism is stopped.
Note that active LSSubscription instances, associated with this LightstreamerClient instance, are preserved to be re-subscribed to on future Sessions.
Lifecycle: note that the request to disconnect is accomplished by the client in a separate thread; this means that an invocation of status right after disconnect might not reflect the change yet.
When the request to disconnect is finally being executed, if the status of the client is DISCONNECTED
, then nothing will be done.
- (void)disconnect
See Also
Declared In
LSLightstreamerClient.h
delegates
List containing the LSClientDelegate instances that were added to this client.
@property (nonatomic, readonly, nonnull) NSArray<id<LSClientDelegate> > *delegates
See Also
Declared In
LSLightstreamerClient.h
status
Current client status and transport (when applicable).
It can be one of the following values:
CONNECTING
the client is waiting for a Server’s response in order to establish a connection;CONNECTED:STREAM-SENSING
the client has received a preliminary response from the server and is currently verifying if a streaming connection is possible;CONNECTED:WS-STREAMING
a streaming connection over WebSocket is active;CONNECTED:HTTP-STREAMING
a streaming connection over HTTP is active;CONNECTED:WS-POLLING
a polling connection over WebSocket is in progress;CONNECTED:HTTP-POLLING
a polling connection over HTTP is in progress;STALLED
the Server has not been sending data on an active streaming connection for longer than a configured time;DISCONNECTED:WILL-RETRY
no connection is currently active but one will be open after a timeout;DISCONNECTED
no connection is currently active.
@property (nonatomic, readonly, nonnull) NSString *status
Declared In
LSLightstreamerClient.h
subscriptions
List containing all the LSSubscription instances that are currently “active” on this LightstreamerClient.
Internal second-level LSSubscription are not included.
The list can be empty.
@property (nonatomic, readonly, nonnull) NSArray<LSSubscription*> *subscriptions
See Also
Declared In
LSLightstreamerClient.h
– removeDelegate:
Removes a delegate from the LSLightstreamerClient instance so that it will not receive events anymore.
Lifecycle: a delegate can be removed at any time.
- (void)removeDelegate:(nonnull id<LSClientDelegate>)delegate
Parameters
delegate |
The delegate to be removed. |
---|
See Also
Declared In
LSLightstreamerClient.h
– sendMessage:
A simplified version of the sendMessage:withSequence:timeout:delegate:enqueueWhileDisconnected:.
The internal implementation will call [self sendMessage:message withSequence:nil timeout:-1.0 delegate:nil enqueWhileDisconnected:NO]
.
Note that this invocation involves no sequence and no listener, hence an optimized fire-and-forget behavior will be applied.
- (void)sendMessage:(nonnull NSString *)message
Parameters
message |
A text message, whose interpretation is entirely demanded to the Metadata Adapter associated to the current connection. |
---|
Declared In
LSLightstreamerClient.h
– sendMessage:withSequence:timeout:delegate:enqueueWhileDisconnected:
Operation method that sends a message to the Server.
The message is interpreted and handled by the Metadata Adapter associated to the current Session. This operation supports in-order guaranteed message delivery with automatic batching. In other words, messages are guaranteed to arrive exactly once and respecting the original order, whatever is the underlying transport (HTTP or WebSockets). Furthermore, high frequency messages are automatically batched, if necessary, to reduce network round trips.
Upon subsequent calls to the method, the sequential management of the involved messages is guaranteed. The ordering is determined by the order in which
the calls to sendMessage
are issued. However, any message that, for any reason, doesn’t reach the Server can be discarded by the Server if this causes the
subsequent message to be kept waiting for longer than a configurable timeout. Note that, because of the asynchronous transport of the requests, if a zero or very
low timeout is set for a message, it is not guaranteed that the previous message can be processed, even if no communication issues occur.
Sequence identifiers can also be associated with the messages. In this case, the sequential management is restricted to all subsets of messages with the same sequence identifier associated.
Notifications of the operation outcome can be received by supplying a suitable delegate. The supplied delegate is guaranteed to be eventually invoked; delegates associated with a sequence are guaranteed to be invoked sequentially.
The UNORDERED_MESSAGES
sequence name has a special meaning. For such a sequence, immediate processing is guaranteed, while strict ordering and even
sequentialization of the processing is not enforced. Likewise, strict ordering of the notifications is not enforced. However, messages that, for any reason,
should fail to reach the Server whereas subsequent messages had succeeded, might still be discarded after a server-side timeout.
Moreover, if UNORDERED_MESSAGES
is used and no listener is supplied, a “fire and forget” scenario is assumed.
In this case, no checks on missing, duplicated or overtaken messages are performed at all, so as to optimize the processing and allow the highest possible throughput.
Lifecycle: since a message is handled by the Metadata Adapter associated to the current connection, a message can be sent only if a connection is currently active.
If the special enqueueWhileDisconnected
flag is specified it is possible to call the method at any time and the client will take care of sending the message
as soon as a connection is available, otherwise, if the current status is DISCONNECTED*
, the message will be abandoned and the
[LSClientMessageDelegate client:didAbortMessage:sentOnNetwork:] event will be fired.
Note that, in any case, as soon as the status switches again to DISCONNECTED*
, any message still pending is aborted, including messages that were queued
with the enqueueWhileDisconnected
flag set to YES.
Also note that forwarding of the message to the server is made in a separate thread, hence, if a message is sent while the connection is active, it could be aborted because of a subsequent disconnection. In the same way a message sent while the connection is not active might be sent because of a subsequent connection.
- (void)sendMessage:(nonnull NSString *)message withSequence:(nullable NSString *)sequence timeout:(NSTimeInterval)delayTimeout delegate:(nullable id<LSClientMessageDelegate>)delegate enqueueWhileDisconnected:(BOOL)enqueueWhileDisconnected
Parameters
message |
A text message, whose interpretation is entirely demanded to the Metadata Adapter associated to the current connection. |
---|---|
sequence |
An alphanumeric identifier, used to identify a subset of messages to be managed in sequence; underscore characters are also allowed.
If the |
delayTimeout |
A timeout, expressed in seconds. If higher than the Server default timeout, the latter will be used instead. The parameter is optional;
if a negative value is supplied, the Server default timeout will be applied. This timeout is ignored for the special |
delegate |
An object suitable for receiving notifications about the processing outcome. The parameter is optional; if not supplied, no notification will be available. Note: delegates are stored with weak references: make sure you keep a strong reference to your delegates or they may be released prematurely. |
enqueueWhileDisconnected |
If this flag is set to YES, and the client is in a disconnected status when the provided message is handled, then the message is not aborted right away but is queued waiting for a new session. Note that the message can still be aborted later when a new session is established. |
Declared In
LSLightstreamerClient.h
+ setLoggerProvider:
Static method that permits to configure the logging system used by the library.
The logging system must respect the LSLoggerProvider interface. A custom class can be used to wrap any third-party logging system.
If no logging system is specified, all the generated log is discarded.
The following categories are available to be consumed:
lightstreamer.stream
: logs socket activity on Lightstreamer Server connections;at INFO level, socket operations are logged;
at DEBUG level, read/write data exchange is logged.
lightstreamer.protocol
: logs requests to Lightstreamer Server and Server answers;at INFO level, requests are logged;
at DEBUG level, request details and events from the Server are logged.
lightstreamer.session
: logs Server Session lifecycle events;at INFO level, lifecycle events are logged;
at DEBUG level, lifecycle event details are logged.
lightstreamer.subscriptions
: logs subscription requests received by the clients and the related updates;at WARN level, alert events from the Server are logged;
at INFO level, subscriptions and unsubscriptions are logged;
at DEBUG level, requests batching and update details are logged.
lightstreamer.actions
: logs settings / API calls.lightstreamer.transport
: logs lower-level transport operations (HTTP and WebSocket).lightstreamer.reachability
: logs network reachability status.
+ (void)setLoggerProvider:(nullable id<LSLoggerProvider>)provider
Parameters
provider |
An LSLoggerProvider instance that will be used to generate log messages by the library classes. |
---|
Declared In
LSLightstreamerClient.h
– subscribe:
Operation method that adds a LSSubscription to the list of “active” subscriptions.
The LSSubscription cannot already be in the “active” state.
Active subscriptions are subscribed to through the server as soon as possible (i.e. as soon as there is a session available). Active LSSubscription
are automatically persisted across different sessions as long as a related unsubscribe:
call is not issued.
Lifecycle: an LSSubscription can be given to the LSLightstreamerClient at any time. Once done the LSSubscription immediately enters the “active” state.
Once “active”, a LSSubscription instance cannot be provided again to a LSLightstreamerClient unless it is first removed from the “active” state through
a call to unsubscribe:
.
Also note that forwarding of the subscription to the server is made in a separate thread.
A successful subscription to the server will be notified through a [LSSubscriptionDelegate subscriptionDidSubscribe:] event.
- (void)subscribe:(nonnull LSSubscription *)subscription
Parameters
subscription |
A LSSubscription object, carrying all the information needed to process its pushed values. |
---|
See Also
Declared In
LSLightstreamerClient.h
– unsubscribe:
Operation method that removes a LSSubscription that is currently in the “active” state.
By bringing back a LSSubscription to the “inactive” state, the unsubscription from all its items is requested to Lightstreamer Server.
Lifecycle: an LSSubscription can be unsubscribed from at any time. Once done the
Note that forwarding of the unsubscription to the server is made in a separate thread.
The unsubscription will be notified through a [LSSubscriptionDelegate subscriptionDidUnsubscribe:] event.
- (void)unsubscribe:(nonnull LSSubscription *)subscription
Parameters
subscription |
An “active” LSSubscription object that was activated by this LSLightstreamerClient instance. |
---|
Declared In
LSLightstreamerClient.h
+ addCookies:forURL:
Static method that can be used to share cookies between connections to the Server (performed by this library) and connections to other sites that are performed by the application.
With this method, cookies received by the application can be added (or replaced if already present) to the cookie set used by the library to access the Server. Obviously, only cookies whose domain is compatible with the Server domain will be used internally.
Specified cookies are actually added to the system’s shared cookie storage, which is used by both HTTP and WebSocket connections.
Lifecycle: this method can be called at any time; it will affect the internal cookie set immediately and the sending of cookies on future requests.
+ (void)addCookies:(nonnull NSArray<NSHTTPCookie*> *)cookies forURL:(nonnull NSURL *)url
Parameters
cookies |
A list of cookies, represented by the system’s standard cookie object NSHTTPCookie. |
---|---|
url |
The URL from which the supplied cookies were received. |
See Also
Declared In
LSLightstreamerClient.h
+ getCookiesForURL:
Static inquiry method that can be used to share cookies between connections to the Server (performed by this library) and connections to other sites that are performed by the application.
With this method, cookies received from the Server can be extracted for sending through other connections, according with the URL to be accessed.
+ (nonnull NSArray<NSHTTPCookie*> *)getCookiesForURL:(nullable NSURL *)url
Parameters
url |
The URL to which the cookies should be sent, or null. |
---|
Return Value
An immutable list with the various cookies that can be sent in a HTTP request for the specified URL. If a null URI was supplied, all available non-expired cookies will be returned. The cookies are represented by the system’s standard cookie object NSHTTPCookie.
Declared In
LSLightstreamerClient.h