rsb.transport.socket

Contains a transport based on point-to-point socket connections.

Code author: jmoringe

Functions

get_bus_client_for(host, port, tcpnodelay, …)

Return a bus client for the given end point and attach a connector to it.

get_bus_server_for(host, port, tcpnodelay, …)

Return a bus server for the given end point and attach a connector to it.

remove_connector(bus, connector)

rsb_initialize()

Classes

Bus()

Instances of this class provide access to a socket-based bus.

BusClient(host, port, tcpnodelay)

Provides access to a bus by means of a client socket.

BusConnection([host, port, socket_, …])

Implements a connection to a socket-based bus.

BusServer(host, port, tcpnodelay[, backlog])

Provides access to a socket-based bus for local and remote bus clients.

Connector(converters[, options])

Base class for connectors that operate on a socket connection based bus.

InConnector(**kwargs)

Receives events from a bus represented by a socket connection.

OutConnector(**kwargs)

Sends events to a bus realized as a socket connection.

TransportFactory

TransportFactory implementation for the socket transport.

class rsb.transport.socket.Bus

Bases: object

Instances of this class provide access to a socket-based bus.

It is transparent for clients (connectors) of this class whether is accessed by running the bus server or by connecting to the bus server as a client.

In-direction connectors add themselves as event sinks using the add_connector method.

Out-direction connectors submit events to the bus using the handle_outgoing method.

Code author: jmoringe

activate()
add_connection(connection)

Add connection to the list of connections of this bus.

This cause notifications send over this bus to be send through connection and notifications received via connection to be dispatched to connectors of this bus.

Parameters

connection – The connection that should be added to this bus.

add_connector(connector)

Add connector to the list of connectors of this bus.

Depending on the direction of connector, this causes connector to either receive or broadcast notifications via this bus.

Parameters

connector – The connector that should be added to this bus.

deactivate()
handle_incoming(connection_and_notification)
handle_outgoing(notification)
remove_connection(connection)

Remove connection from the list of connections of this bus.

Parameters

connection – The connection that should be removed from this bus.

remove_connector(connector)

Remove connector from the list of connectors of this bus.

Parameters

connector – The connector that should be removed from this bus.

property active
property connections

Return the attached connections.

Returns

A list of all connections to the bus.

Rtype

list

property connectors
property lock
class rsb.transport.socket.BusClient(host, port, tcpnodelay)

Bases: rsb.transport.socket.Bus

Provides access to a bus by means of a client socket.

Code author: jmoringe

Create a new client connection on the specified host and port.

Parameters
  • host – A hostname or address of the node on which the bus server listens.

  • port – The port on which the new bus server listens.

  • tcpnodelay – If True, the socket will be set to TCP_NODELAY.

Type host

str

Type port

int

Type tcpnodelay

bool

activate()
add_connection(connection)

Add connection to the list of connections of this bus.

This cause notifications send over this bus to be send through connection and notifications received via connection to be dispatched to connectors of this bus.

Parameters

connection – The connection that should be added to this bus.

add_connector(connector)

Add connector to the list of connectors of this bus.

Depending on the direction of connector, this causes connector to either receive or broadcast notifications via this bus.

Parameters

connector – The connector that should be added to this bus.

deactivate()
handle_incoming(connection_and_notification)
handle_outgoing(notification)
remove_connection(connection)

Remove connection from the list of connections of this bus.

Parameters

connection – The connection that should be removed from this bus.

remove_connector(connector)

Remove connector from the list of connectors of this bus.

Parameters

connector – The connector that should be removed from this bus.

property active
property connections

Return the attached connections.

Returns

A list of all connections to the bus.

Rtype

list

property connectors
property lock
class rsb.transport.socket.BusConnection(host=None, port=None, socket_=None, is_server=False, tcpnodelay=True)

Bases: rsb.eventprocessing.BroadcastProcessor

Implements a connection to a socket-based bus.

The basic operations provided by this class are receiving an event by calling receive_notification and submitting an event to the bus by calling send_notification.

In a process which act as a client for a particular bus, a single instance of this class is connected to the bus server and provides access to the bus for the process.

A process which acts as the server for a particular bus, manages (via the BusServer class) one BusConnection object for each client (remote process) connected to the bus.

Code author: jmoringe

Args:

Returns:

Create a new instance.

Parameters
  • host – Hostname or address of the bus server.

  • port – Port of the bus server.

  • socket – A socket object through which the new connection should access the bus.

  • is_server – if True, the created object will perform the server part of the handshake protocol.

  • tcpnodelay – If True, the socket will be set to TCP_NODELAY.

Type host

str or None

Type port

int or None

Type is_server

bool

Type tcpnodelay

bool

activate()
add_handler(handler)
static buffer_to_notification(serialized)
deactivate()
dispatch(event)
do_one_notification()
handle(notification)
static notification_to_buffer(notification)
receive_notification()
receive_notifications()
remove_handler(handler)
send_notification(notification)
shutdown()
wait_for_deactivation()
property disconnect_hook
property handlers
class rsb.transport.socket.BusServer(host, port, tcpnodelay, backlog=5)

Bases: rsb.transport.socket.Bus

Provides access to a socket-based bus for local and remote bus clients.

Remote clients can connect to a server socket in order to send and receive events through the resulting socket connection.

Local clients (connectors) use the usual Bus interface to receive events submitted by remote clients and submit events which will be distributed to remote clients by the BusServer.

Code author: jmoringe

Create a new instance on the given host and port.

Parameters
  • host – A hostname or address identifying the interface to which the listen socket of the new bus server should be bound.

  • port – The port to which the listen socket of the new bus server should be bound.

  • tcpnodelay – If True, the socket will be set to TCP_NODELAY.

  • backlog – The maximum number of queued connection attempts.

Type host

str

Type port

int

Type tcpnodelay

bool

Type backlog

int

accept_clients()
activate()
add_connection(connection)

Add connection to the list of connections of this bus.

This cause notifications send over this bus to be send through connection and notifications received via connection to be dispatched to connectors of this bus.

Parameters

connection – The connection that should be added to this bus.

add_connector(connector)

Add connector to the list of connectors of this bus.

Depending on the direction of connector, this causes connector to either receive or broadcast notifications via this bus.

Parameters

connector – The connector that should be added to this bus.

deactivate()
handle_incoming(connection_and_notification)
handle_outgoing(notification)
remove_connection(connection)

Remove connection from the list of connections of this bus.

Parameters

connection – The connection that should be removed from this bus.

remove_connector(connector)

Remove connector from the list of connectors of this bus.

Parameters

connector – The connector that should be removed from this bus.

property active
property connections

Return the attached connections.

Returns

A list of all connections to the bus.

Rtype

list

property connectors
property lock
class rsb.transport.socket.Connector(converters, options=None, **kwargs)

Bases: rsb.transport.Connector, rsb.transport.ConverterSelectingConnector

Base class for connectors that operate on a socket connection based bus.

Instances of subclasses of this class receive events from a bus (represented by a Bus object) that is accessed via a socket connection.

Code author: jmoringe

activate()
deactivate()
get_converter_for_data_type(data_type)

Return a converter that converts the supplied data to the wire-type.

Parameters

data_type – the type of the object for which a suitable converter should returned.

Returns

converter

Raises KeyError

no converter is available for the supplied data.

get_converter_for_wire_schema(wire_schema)

Return a suitable converter for the wire_schema.

Parameters

wire_schema – the wire-schema to or from which the returned converter should convert

Type wire_schema

str

Returns

converter

Raises KeyError

no converter is available for the specified wire-schema.

get_transport_url()
set_quality_of_service_spec(qos)
property bus
property converter_map
property scope
property wire_type

Return the serialization type used for this connector.

Returns

python serialization type

class rsb.transport.socket.InConnector(**kwargs)

Bases: rsb.transport.socket.Connector, rsb.transport.InConnector

Receives events from a bus represented by a socket connection.

Instances of this class receive events from a bus (represented by a Bus object) that is accessed via a socket connection.

The receiving and dispatching of events is done in push mode: each instance has a Bus which pushes appropriate events into the instance. The connector deserializes event payloads and pushes the events into handlers (usually objects which implement some event processing strategy).

Code author: jmoringe

activate()
deactivate()
filter_notify(the_filter, action)
get_converter_for_data_type(data_type)

Return a converter that converts the supplied data to the wire-type.

Parameters

data_type – the type of the object for which a suitable converter should returned.

Returns

converter

Raises KeyError

no converter is available for the supplied data.

get_converter_for_wire_schema(wire_schema)

Return a suitable converter for the wire_schema.

Parameters

wire_schema – the wire-schema to or from which the returned converter should convert

Type wire_schema

str

Returns

converter

Raises KeyError

no converter is available for the specified wire-schema.

get_transport_url()
handle(notification)
set_observer_action(action)

Set the action used by the connector to notify about incoming events.

The call to this method must be thread-safe.

Parameters

action – action called if a new message is received from the connector. Must accept an Event as parameter.

set_quality_of_service_spec(qos)
property bus
property converter_map
property scope
property wire_type

Return the serialization type used for this connector.

Returns

python serialization type

class rsb.transport.socket.OutConnector(**kwargs)

Bases: rsb.transport.socket.Connector, rsb.transport.OutConnector

Sends events to a bus realized as a socket connection.

Instance of this class send events to a bus (represented by a Bus object) that is accessed via a socket connection.

Code author: jmoringe

activate()
deactivate()
get_converter_for_data_type(data_type)

Return a converter that converts the supplied data to the wire-type.

Parameters

data_type – the type of the object for which a suitable converter should returned.

Returns

converter

Raises KeyError

no converter is available for the supplied data.

get_converter_for_wire_schema(wire_schema)

Return a suitable converter for the wire_schema.

Parameters

wire_schema – the wire-schema to or from which the returned converter should convert

Type wire_schema

str

Returns

converter

Raises KeyError

no converter is available for the specified wire-schema.

get_transport_url()
handle(event)

Send event and adapts its meta data with the actual send time.

Parameters

event – event to send

set_quality_of_service_spec(qos)
property bus
property converter_map
property scope
property wire_type

Return the serialization type used for this connector.

Returns

python serialization type

class rsb.transport.socket.TransportFactory

Bases: rsb.transport.TransportFactory

TransportFactory implementation for the socket transport.

Code author: jwienke

create_in_connector(converters, options)

Create a new InConnector for the represented transport.

Parameters

converters – the converters to use for this type options(dict of str): options for the new connector

Type converters

ConverterSelectionStrategy

Returns

the new connector instance

Rtype

rsb.transport.InConnector

create_out_connector(converters, options)

Create a new OutConnector for the represented transport.

Parameters

converters – the converters to use for this type options(dict of str): options for the new connector

Type converters

ConverterSelectionStrategy

Returns

the new connector instance

Rtype

rsb.transport.OutConnector

property name

Return the name representing this transport.

Returns

name of the transport, non-empty

Rtype

str

property remote

Return true if the transport performs remote communication.

Returns

does the transport perform remote communication?

Rtype

bool

rsb.transport.socket.get_bus_client_for(host, port, tcpnodelay, connector)

Return a bus client for the given end point and attach a connector to it.

Return (creating it if necessary), a BusClient for the endpoint designated by host and port and attach connector to it. Attaching connector marks the bus client as being in use and protects it from being destroyed in a race condition situation.

Parameters
  • host – A hostname or address of the node on which the bus server listens.

  • port – The port on which the bus server listens.

  • tcpnodelay – If True, the socket will be set to TCP_NODELAY.

  • connector – A connector that should be attached to the bus client.

Type host

str

Type port

int

Type tcpnodelay

bool

rsb.transport.socket.get_bus_server_for(host, port, tcpnodelay, connector)

Return a bus server for the given end point and attach a connector to it.

Return (creating it if necessary), a BusServer for the endpoint designated by host and port and attach connector to it. Attaching connector marks the bus server as being in use and protects it from being destroyed in a race condition situation.

Parameters
  • host – A hostname or address identifying the interface to which the listen socket of the new bus server should be bound.

  • port – The port to which the listen socket of the new bus server should be bound.

  • tcpnodelay – If True, the socket will be set to TCP_NODELAY.

  • connector – A connector that should be attached to the bus server.

Type host

str

Type port

int

Type tcpnodelay

bool

rsb.transport.socket.remove_connector(bus, connector)
rsb.transport.socket.rsb_initialize()