osbrain.address
— osBrain address logic¶
Implementation of address-related features.
-
class
osbrain.address.
AgentAddress
(transport, address, kind, role, serializer)¶ Bases:
object
Agent address information consisting on the transport protocol, address, kind and role.
Parameters: - transport (str, AgentAddressTransport) – Agent transport protocol.
- address (str) – Agent address.
- kind (str, AgentAddressKind) – Agent kind.
- role (str, AgentAddressRole) – Agent role.
- serializer (str) – Agent serializer type.
-
transport
¶ Agent transport protocol.
Type: str, AgentAddressTransport
-
address
¶ Agent address.
Type: str, SocketAddress
-
kind
¶ Agent kind.
Type: AgentAddressKind
-
role
¶ Agent role.
Type: AgentAddressRole
-
serializer
¶ Agent serializer.
Type: AgentAddressSerializer
-
class
osbrain.address.
AgentAddressKind
¶ Bases:
str
Agent’s address kind class.
This kind represents the communication pattern being used by the agent address: REP, PULL, PUB…
-
REQUIRE_HANDLER
= ('REP', 'PULL', 'SUB', 'PULL_SYNC_PUB')¶
-
TWIN
= {'PUB': 'SUB', 'PULL': 'PUSH', 'PULL_SYNC_PUB': 'PUSH_SYNC_SUB', 'PUSH': 'PULL', 'PUSH_SYNC_SUB': 'PULL_SYNC_PUB', 'REP': 'REQ', 'REQ': 'REP', 'SUB': 'PUB'}¶
-
ZMQ_KIND_CONVERSION
= {'PUB': 1, 'PULL': 7, 'PULL_SYNC_PUB': 7, 'PUSH': 8, 'PUSH_SYNC_SUB': 8, 'REP': 4, 'REQ': 3, 'SUB': 2}¶
-
requires_handler
()¶ Whether the Agent’s address kind requires a handler or not. A socket which processes incoming messages would require a handler (i.e. ‘REP’, ‘PULL’, ‘SUB’…).
Returns: Return type: bool
-
twin
()¶ Get the twin kind of the current one.
REQ
would be the twin ofREP
and viceversa,PUB
would be the twin ofSUB
and viceversa, etc.Returns: The twin kind of the current one. Return type: AgentAddressKind
-
zmq
()¶ Get the equivalent ZeroMQ socket kind.
Returns: Return type: int
-
-
class
osbrain.address.
AgentAddressRole
¶ Bases:
str
Agent’s address role class. It can either be
'server'
or'client'
.-
twin
()¶ Get the twin role of the current one.
'server'
would be the twin of'client'
and viceversa.Returns: The twin role. Return type: AgentAddressRole
-
-
class
osbrain.address.
AgentAddressSerializer
(value)¶ Bases:
str
Agent’s address serializer class.
Each communication channel will have a serializer.
Note that for
raw
message passing, everything must be on bytes, and the programmer is the one responsible for converting data to bytes.Parameters: serializer_type (str) – Serializer type (i.e.: ‘raw’, ‘pickle’, ‘cloudpickle’, ‘dill’, ‘json’). -
SERIALIZER_SEPARATOR
= ('pickle', 'cloudpickle', 'dill', 'json')¶
-
SERIALIZER_SIMPLE
= ('raw',)¶
-
-
class
osbrain.address.
AgentAddressTransport
¶ Bases:
str
Agent’s address transport class. It can be ‘tcp’, ‘ipc’ or ‘inproc’.
-
class
osbrain.address.
AgentChannel
(kind, receiver, sender, twin_uuid=None)¶ Bases:
object
Agent channel information.
Channels are communication means with sender and receiver in both sides (i.e.: PULL+PUB - PUSH-SUB or PULL+PUSH - PUSH+PULL).
Parameters: - kind (AgentChannelKind) – Agent kind.
- sender (str) – First AgentAddress.
- receiver (str) – Second AgentAddress.
-
kind
¶ Agent kind.
Type: AgentChannelKind
-
sender
¶ First AgentAddress.
Type: str
-
receiver
¶ Second AgentAddress.
Type: str
-
twin
()¶ Get the twin channel of the current one.
Returns: The twin channel. Return type: AgentChannel
-
class
osbrain.address.
AgentChannelKind
¶ Bases:
str
Agent’s channel kind class.
This kind represents the communication pattern being used by the agent channel: ASYNC_REP, STREAM…
-
TWIN
= {'ASYNC_REP': 'ASYNC_REQ', 'ASYNC_REQ': 'ASYNC_REP', 'SYNC_PUB': 'SYNC_SUB', 'SYNC_SUB': 'SYNC_PUB'}¶
-
twin
()¶ Get the twin kind of the current one.
REQ
would be the twin ofREP
and viceversa,PUB
would be the twin ofSUB
and viceversa, etc.Returns: Return type: AgentChannelKind
-
-
class
osbrain.address.
SocketAddress
(host, port)¶ Bases:
object
Socket address information consisting on the host and port.
Parameters: - host (str, ipaddress.IPv4Address) – IP address.
- port (int) – Port number.
-
host
¶ IP address.
Type: ipaddress.IPv4Address
-
port
¶ Port number.
Type: int
-
osbrain.address.
address_to_host_port
(addr)¶ Try to convert an address to a (host, port) tuple.
Parameters: addr (str, SocketAddress) – Returns: A (host, port) tuple formed with the corresponding data. Return type: tuple
-
osbrain.address.
guess_kind
(kind)¶ Guess if a kind string is an AgentAddressKind or AgentChannelKind.
Parameters: kind (str) – The AgentAddressKind or AgentChannelKind in string format. Returns: The actual kind type. Return type: AgentAddressKind or AgentChannelKind