Ark
Loading...
Searching...
No Matches
comm_handler.service.Service Class Reference
Inheritance diagram for comm_handler.service.Service:
comm_handler.comm_handler.CommHandler

Public Member Functions

 __init__ (self, str name, Type req_type, Type resp_type, Callable[[str, object], object] callback, str registry_host, int registry_port, str host=None, int port=None, is_default=False)
 Initialize the service.
 register_with_registry (self)
 Register the service with the registry server.
 __repr__ (self)
 restart (self)
 Restart the service communication handlers.
 suspend (self)
 Shut down the service and deregister from the registry.
bool deregister_from_registry (self)
 Deregister the service from the registry server and validate the response.
 get_info (self)
 Return a dictionary describing this service instance.
Public Member Functions inherited from comm_handler.comm_handler.CommHandler
 __init__ (self, LCM lcm, str channel_name, type channel_type)
 Initializes the communication handler with an LCM instance, a channel name, and a channel type.
str __repr__ (self)
 Returns a string representation of the communication handler, showing the channel name and the type of message it handles.

Public Attributes

 service_name = name
str comm_type = "Service"
 req_type = req_type
 resp_type = resp_type
 callback = callback
str host = host if host is not None else self._get_local_ip()
int port = port if port is not None else self._find_free_port()
 registry_host = registry_host
 registry_port = registry_port
 thread = threading.Thread(target=self._serve)
 is_default_service = is_default
 registered = self.register_with_registry()
Public Attributes inherited from comm_handler.comm_handler.CommHandler
str channel_name = channel_name
type channel_type = channel_type
bool active = True

Protected Member Functions

str _get_local_ip (self)
 Get the local IP address of the machine.
int _find_free_port (self)
 Find a free port to bind the service.
 _serve (self)
 Serve incoming service requests.
 _recvall (self, conn, n)
 Helper function to receive n bytes from a socket.

Protected Attributes

 _stop_event = threading.Event()
Protected Attributes inherited from comm_handler.comm_handler.CommHandler
LCM _lcm = lcm
 Initializes the communication handler with an LCM instance, a channel name, and a channel type.

Constructor & Destructor Documentation

◆ __init__()

comm_handler.service.Service.__init__ ( self,
str name,
Type req_type,
Type resp_type,
Callable[[str, object], object] callback,
str registry_host,
int registry_port,
str host = None,
int port = None,
is_default = False )

Initialize the service.

Parameters
nameName of the service.
req_typeRequest message class with encode/decode.
resp_typeResponse message class with encode/decode.
callbackCallback handling the request.
registry_hostRegistry server host.
registry_portRegistry server port.
hostOptional host to bind the service.
portOptional port to bind the service.

Member Function Documentation

◆ __repr__()

comm_handler.service.Service.__repr__ ( self)
Returns a string representation of the communication handler, including 
the channel name and the types of messages it handles.

The string is formatted as:
"channel_name[request_type, response_type]".

@return: A string representation of the handler, formatted as 
        "channel_name[request_type,response_type]".

◆ _find_free_port()

int comm_handler.service.Service._find_free_port ( self)
protected

Find a free port to bind the service.

Returns
: Available port number.

◆ _get_local_ip()

str comm_handler.service.Service._get_local_ip ( self)
protected

Get the local IP address of the machine.

Returns
: Detected local IP address.

◆ _recvall()

comm_handler.service.Service._recvall ( self,
conn,
n )
protected

Helper function to receive n bytes from a socket.

Parameters
connSocket connection.
nNumber of bytes to read.
Returns
: Received bytes or None on EOF.

◆ _serve()

comm_handler.service.Service._serve ( self)
protected

Serve incoming service requests.

◆ deregister_from_registry()

bool comm_handler.service.Service.deregister_from_registry ( self)

Deregister the service from the registry server and validate the response.

Returns
: True if deregistration succeeded.

◆ get_info()

comm_handler.service.Service.get_info ( self)

Return a dictionary describing this service instance.

Reimplemented from comm_handler.comm_handler.CommHandler.

◆ register_with_registry()

comm_handler.service.Service.register_with_registry ( self)

Register the service with the registry server.

Returns
: True on success, False otherwise.

◆ restart()

comm_handler.service.Service.restart ( self)

Restart the service communication handlers.

Reimplemented from comm_handler.comm_handler.CommHandler.

◆ suspend()

comm_handler.service.Service.suspend ( self)

Shut down the service and deregister from the registry.

Reimplemented from comm_handler.comm_handler.CommHandler.

Member Data Documentation

◆ _stop_event

comm_handler.service.Service._stop_event = threading.Event()
protected

◆ callback

comm_handler.service.Service.callback = callback

◆ comm_type

str comm_handler.service.Service.comm_type = "Service"

◆ host

comm_handler.service.Service.host = host if host is not None else self._get_local_ip()

◆ is_default_service

comm_handler.service.Service.is_default_service = is_default

◆ port

comm_handler.service.Service.port = port if port is not None else self._find_free_port()

◆ registered

comm_handler.service.Service.registered = self.register_with_registry()

◆ registry_host

comm_handler.service.Service.registry_host = registry_host

◆ registry_port

comm_handler.service.Service.registry_port = registry_port

◆ req_type

comm_handler.service.Service.req_type = req_type

◆ resp_type

comm_handler.service.Service.resp_type = resp_type

◆ service_name

comm_handler.service.Service.service_name = name

◆ thread

comm_handler.service.Service.thread = threading.Thread(target=self._serve)

The documentation for this class was generated from the following file: