Skip to content

[MCCS-1795] Session support

Drew Devereux requested to merge mccs-1795-session-support into main

Currently, ska-ser-devices implements a sessionless application-layer protocol: a fresh connection is established for every request, and closed once a response has been received. There is nothing inherently bad about this, but it would be nice if ska-ser-devices at least provided the option to open a long-lived session, through which many transactions are conducted.

This MR refactors ska-ser-devices to support long-lived sessions.

The server side now holds connections open until it detects that the client has closed the connection.

On the client side, clients are now context managers for sessions. One enters a session using the usual with format, and one can then execute any number of requests within that session:

tcp_client = TcpClient(address)
with tcp_client as session:
    response1 = session.send_receive(request1)
    response2 = session.send_receive(request2)
    response3 = session.send_receive(request3)
    response4 = session.send_receive(request4)

Of course, if you want the old sessionless behaviour where there is a new connection for each transaction, you can easily have it:

with tcp_client as session:
    response1 = session.send_receive(request1)
with tcp_client as session:
    response2 = session.send_receive(request2)
with tcp_client as session:
    response3 = session.send_receive(request3)
with tcp_client as session:
    response4 = session.send_receive(request4)

Finally, in situations where it is not convenient to use the with syntax, one can still access this new functionality: a connect() method returns a session object, and that session object provides a close() method:

tcp_client = TcpClient(address)
session = tcp_client.connect()
response1 = session.send_receive(request1)
response2 = session.send_receive(request2)
response3 = session.send_receive(request3)
response4 = session.send_receive(request4)
session.close()

To prove this functionality

  1. The unit tests have been updated to cover multi-transaction sessions
  2. ska-low-mccs-pasd has been updated to make use of it. A draft MR that depends on this branch can be viewed at ska-telescope/mccs/ska-low-mccs-pasd!55 (merged).
Edited by Drew Devereux

Merge request reports