lightstreamer_adapter package

Submodules

lightstreamer_adapter.server module

class lightstreamer_adapter.server.Server(address, name, keep_alive, thread_pool_size)

Bases: object

An abstract class meant to be extended, which represents a generic Remote Adapter object capable to run Remote Data or Metadata Adapter and connect it to the Proxy Adapter running on Lightstreamer Server.

An instance of a Server’s subclass should be provided with a suitable Adapter instance and with suitable initialization parameters and established connections, then activated through its own start() and finally disposed through its own close(). Further reuse of the same instance is not supported.

name

The name, used for logging purposes, associated to the Server instance.

Type:str
keep_alive

The keepalive interval expressed in seconds (or fractions)

Type:float
thread_pool_size

The thread pool size

Type:int
set_exception_handler(handler)

Sets the handler for error conditions occurring on the Remote Server. By setting the handler, it’s possible to override the default exception handling.

Parameters:handler (lightstreamer_adapter.server.ExceptionHandler) – the handler for error conditions occurring on the Remote Server.
close()

Stops the management of the Remote Adapter and destroys the threads used by this Server. This instance can no longer be used.

Note that this does not stop the supplied Remote Adapter, as no close method is available in the Remote Adapter interface. If the process is not terminating, then the Remote Adapter cleanup should be performed by accessing the supplied Adapter instance directly and calling custom methods.

class lightstreamer_adapter.server.MetadataProviderServer(adapter, address, name=None, keep_alive=1, thread_pool_size=0)

Bases: lightstreamer_adapter.server.Server

A server object which can run a Remote Metadata Adapter and connect it to the Proxy Adapter running on Lightstreamer Server.

The object should be provided with a MetadataProvider instance and with suitable initialization parameters and established connections, then activated through MetadataProviderServer.start() and finally disposed through Server.close(). Further reuse of the same instance is not supported.

The server will take care of sending keepalive packets on the connections when needed. The interval can be configured through the provided keep_alive parameter; by default it is 1 sec; a value of 0, negative or None disables the keepalives.

By default, the invocations to the Metadata Adapter methods will be done in a limited thread pool with a size determined by the number of detected cpu cores. The size can be specified through the provided thread_pool_size parameter. A size of 1 enforces strictly sequential invocations and can be used if parallelization of the calls is not supported by the Metadata Adapter. A value of 0, negative or None also implies the default behaviour as stated above.

Note that requests with an implicit ordering, like lightstreamer_adapter.interfaces.metadata.MetadataProvider.notify_new_session() and lightstreamer_adapter.interfaces.metadata.MetadataProvider.notify_session_close() for the same session, are always guaranteed to be and sequentialized in the right way, although they may not occur in the same thread.

__init__(adapter, address, name=None, keep_alive=1, thread_pool_size=0)

Creates a server with the supplied configuration parameters. The lightstreamer_adapter.interfaces.metadata.MetadataProvider.initialize() method will be invoked only upon a Proxy Adapter request.

Parameters:
  • adapter (lightstreamer_adapter.interfaces.metadata.MetadataProvider) – the Remote Metadata Adapter instance to be run.
  • address (tuple) –

    the address of the Proxy Adapter supplied as a 2-tuple (host, request_reply_port) where:

    • host: a string representing the hostname or the IP address
    • request_reply_port: an int representing the request/reply port
  • name (str) – the name associated to the Server instance.
  • keep_alive (float) – the keepalive interval expressed in seconds (or fractions)
  • thread_pool_size (int) – the thread pool size
Raises:

TypeError – if the supplied Remote Adapter is not an instance of a subclass of lightstreamer_adapter.interfaces.metadata.MetadataProvider.

adapter_config

The pathname of an optional configuration file for the Remote Metadata Adapter, to be passed to the lightstreamer_adapter.interfaces.metadata.MetadataProvider.initialize() method.

Getter:Returns the pathname of the optional configuration file
Setter:Sets the pathname of the optional configuration file
Type:str
adapter_params

A dictionary object to be passed to the lightstreamer_adapter.interfaces.metadata.MetadataProvider.initialize() method, to supply optional parameters.

Getter:Returns the dictionary object of optional parameters
Setter:Sets the dictionary object of optional parameters
Type:dict
start()

Starts the Remote Metadata Adapter. A connection to the Proxy Adapter is performed (as soon as one is available). Then, requests issued by the Proxy Adapter are received and forwarded to the Remote Adapter.

Raises:lightstreamer_adapter.interfaces.metadata.MetadataProviderError – If an error occurred in the initialization phase. The adapter was not started.
class lightstreamer_adapter.server.DataProviderServer(adapter, address, name=None, keep_alive=1, thread_pool_size=0)

Bases: lightstreamer_adapter.server.Server

A server object which can run a Remote Data Adapter and connect it to the Proxy Adapter running on Lightstreamer Server.

The object should be provided with a DataProvider instance and with suitable initialization parameters and established connections, then activated through DataProviderServer.start() and finally disposed through Server.close(). Further reuse of the same instance is not supported.

The server will take care of sending keepalive packets on the connections when needed. The interval can be configured through the provided keep_alive parameter; by default it is 1 sec; a value of 0, negative or None disables the keepalives.

By default, the invocations to the Data Adapter methods will be done in a limited thread pool with a size determined by the number of detected cpu cores. The size can be specified through the provided thread_pool_size parameter. A size of 1 enforces strictly sequential invocations and can be used if parallelization of the calls is not supported by the Metadata Adapter. A value of 0, negative or None also implies the default behaviour as stated above.

Note that :meth;Subscribe and Unsubscribe invocations for the same item are always guaranteed to be sequentialized in the right way, although they may not occur in the same thread.

__init__(adapter, address, name=None, keep_alive=1, thread_pool_size=0)

Creates a server with the supplied configuration parameters. The initialize method of the Remote Adapter will be invoked only upon a Proxy Adapter request.

Parameters:
  • adapter (lightstreamer_adapter.interfaces.data.DataProvider) – The Remote Adapter instance to be run.
  • address (tuple) –

    the address of the Proxy Adapter supplied as a 3-tuple (host, request_reply_port, notify_port) where:

    • host: a string representing the hostname or the IP address
    • request_reply_port: an int representing the request/reply port
    • notify_port: an int representing the notify port
  • name (str) – the name associated to the Server instance.
  • keep_alive (float) – the keepalive interval expressed in seconds (or fractions)
  • thread_pool_size (int) – the thread pool size
Raises:

TypeError – if the supplied Remote Adapter is not an instance of a subclass of lightstreamer_adapter.interfaces.data.DataProvider.

adapter_config

The pathname of an optional configuration file for the Remote Data Adapter, to be passed to the lightstreamer_adapter.interfaces.data.DataProvider.initialize() method.

Getter:Returns the pathname of the optional configuration file
Setter:Sets the pathname of the optional configuration file
Type:str
adapter_params

A dictionary object to be passed to the lightstreamer_adapter.interfaces.data.DataProvider.initialize() method, to supply optional parameters.

Getter:Returns the dictionary object of optional parameters
Setter:Sets the dictionary object of optional parameters
Type:dict
start()

Starts the Remote Data Adapter. A connection to the Proxy Adapter is performed (as soon as one is available). Then, requests issued by the Proxy Adapter are received and forwarded to the Remote Adapter.

Raises:lightstreamer_adapter.interfaces.data.DataProviderError – If an error occurred in the initialization phase. The adapter was not started.
class lightstreamer_adapter.server.ExceptionHandler

Bases: object

Abstract class to to be implemented in order to provide the Server instance with a custom handler for error conditions occurring on the Remote Server.

handle_ioexception(exception)

Called by the Remote Server upon a read or write operation failure. This may mean that the connection to the Server is lost; in any way, after this error, the correct Lightstreamer Server and Remote Server operation is compromised. This can be the signal of a normal Server termination. If this is not the case, then Lightstreamer Server should be restarted and the Remote Server should be reinitialized (i.e. the process should be restarted or a new Server class instance should be used).

The default handling closes the Remote Server. This also ensures that the Proxy Adapter causes the closure of Lightstreamer Server.

Parameters:exception (Exception) – An Exception showing the cause of the problem.
Return bool:True to enable the default handling, false to suppress it.
handle_exception(exception)

Called by the Remote Server upon an unexpected error. After this error, the correct Lightstreamer Server and Remote Server operation might be compromised. If this is the case, then Lightstreamer Server should be restarted and the Remote Server should be reinitialized (i.e. the process should be restarted or a new Server class instance should be used).

The default handling, in case of a Remote Data Adapter, issues an asynchronous failure notification to the Proxy Adapter; this causes the closure of Lightstreamer Server, which, in turn, causes the communication channel to be closed. In case of a Remote Metadata Adapter, the default handling ignores the notification; however, as a consequence of the Remote Protocol being broken, the Proxy Adapter may return exceptions against one or more specific requests by Lightstreamer Kernel.

Parameters:exception (Exception) – An Exception showing the cause of the problem.
Returns:True to enable the default handling, false to suppress it.
Return type:bool