lightstreamer_adapter package¶
Subpackages¶
Submodules¶
lightstreamer_adapter.server module¶
-
class
lightstreamer_adapter.server.
Server
(address, name, keep_alive, thread_pool_size, ssl_context)¶ Bases:
object
An abstract class meant to be extended, which represents a generic Remote Server object, which can run a Remote Data or Metadata Adapter and connect it to the Proxy Adapter running on Lightstreamer Server.
The object should be provided with a suitable Adapter instance and with suitable initialization parameters, then activated through its own
start()
and finally disposed through its ownclose()
. Further reuse of the same instance is not supported.The Remote Server will take care of sending keepalive packets on the connections when needed. The interval can be configured through the provider
keep_alive
parameter, where a value of 0 or negative means no keepalives. By default, it is set to 10 sec.However, if a stricter interval is requested by the Proxy Adapter on startup, it will be obeyed (with a safety minimum of 1 second). This should ensure that the Proxy Adapter activity checks will always succeed, but for some old versions of the Proxy Adapter.
-
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
-
remote_user
¶ The username credential to be sent to the Proxy Adapter upon connection. The credentials are needed only if the Proxy Adapter is configured to require Remote Adapter authentication.
Type: str
-
remote_password
¶ The password credential to be sent to the Proxy Adapter upon connection. The credentials are needed only if the Proxy Adapter is configured to require Remote Adapter authentication.
Type: str
-
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=None, thread_pool_size=0, ssl_context=None)¶ Bases:
lightstreamer_adapter.server.Server
A Remote Server object which can run a Remote Metadata Adapter and connect it to the Proxy Adapter running on Lightstreamer Server. Note that since Server version 7.4 the Proxy Adapter also supports connection inversion, that is, it can be configured to listen for a connection issued by the Remote Server. This option is currently not supported by this library.
The object should be provided with a MetadataProvider instance and with suitable initialization parameters, then activated through
MetadataProviderServer.start()
and finally disposed throughServer.close()
. Further reuse of the same instance is not supported.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 orNone
also implies the default behaviour as stated above.Note that requests with an implicit ordering, like
lightstreamer_adapter.interfaces.metadata.MetadataProvider.notify_new_session()
andlightstreamer_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=None, thread_pool_size=0, ssl_context=None)¶ 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
- ssl_context (SSLContext) – the SSL context to be used in the case of encrypted communications with the Proxy Adapter
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.
The requests are handled through a ThreadPoolExecutor. Since Python 3.9, this requires that the main thread is kept active until close is invoked.
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=None, thread_pool_size=0, ssl_context=None)¶ Bases:
lightstreamer_adapter.server.Server
A Remote Server object which can run a Remote Data Adapter and connect it to the Proxy Adapter running on Lightstreamer Server. Note that since Server version 7.4 the Proxy Adapter also supports connection inversion, that is, it can be configured to listen for a connection issued by the Remote Server. This option is currently not supported by this library.
The object should be provided with a DataProvider instance and with suitable initialization parameters, then activated through
DataProviderServer.start()
and finally disposed throughServer.close()
. Further reuse of the same instance is not supported.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 Data Adapter. A value of 0, negative orNone
also implies the default behaviour as stated above.Note that
subscribe()
andunsubscribe()
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=None, thread_pool_size=0, ssl_context=None)¶ 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 Data 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
- ssl_context (SSLContext) – the SSL context to be used in the case of encrypted communications with the Proxy Adapter
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.
The requests are handled through a ThreadPoolExecutor. Since Python 3.9, this requires that the main thread is kept active until close is invoked.
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
An abstract class meant to to be implemented in order to provide a Remote Server instance with a custom handler for error conditions occurring on the Remote Server.
Note that multiple redundant invocations on the same Remote Server instance are possible.
-
handle_ioexception
(exception)¶ Called by the Remote Server upon a read or write operation failure. This may mean that the connection to Lightstreamer Server is lost; in any way, after this error, the correct operation of this Remote Server operation is compromised. This can be the signal of a normal termination of Lightstreamer Server. If this is not the case, then this Remote Server should be closed and a new one should be created and initialized. This may mean closing and restarting the process or just creating a new instance, depending on the implementation choice. This will be detected by the Proxy Adapter, which will react accordingly.
The default handling just terminates the process.
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 operation of this Remote Server instance is compromised. If this is the case, then this Remote Server instance should be closed and a new one should be created and initialized. This may mean closing and restarting the process or just creating a new instance, depending on the implementation choice. This will be detected by the Proxy Adapter, which will react accordingly.
The default handling, in case of a Remote Data Adapter, issues an asynchronous failure notification to the Proxy Adapter. 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
-