RestService¶
-
class
services.
RestService
(_server, _params, _type=<SocketKind.SOCK_DGRAM: 2>, _family=<AddressFamily.AF_UNSPEC: 0>)¶ Bases:
services.SocketService
RestService - baseclass for getting particular rest commands for communication over REST API
Parameters: {obj} -- Service base class (Service) – Methods Summary
add_accept_handler
(sock, callback)Accept Handler for UDP Socket add_sockets
(sockets)Adds speficic sockets to the server bind
(port[, address, family])Bind a specific socket (here UDP) to the server bind_unix_socket
(file, mode)Special binding for UnixSockets - the way unix-sockets are reused depends extremly on OS Platform can_send
()Basic info wether service can send back or not close
()Basic close service get_service
(_params[, _server])Gets a service from service params EXAMPLE: _params[‘active_service’].append({ # tcp service “id”: 2, “antano_server_id”: 1, # needs to be the same as id above “service_type_id”: 2, “port”: 18002, “host”: “0.0.0.0”, “endpoint”: “”, # in case of rest or websocket /my_endpoint put “my_endpoint” “message_format_in_id”: 1, # message_format “message_format_out_id”: 1, # message_format }) make
(endpoint)make app - creates a tornado endpoint with a given class on_received_message
(message, address, …)On received message will process the message and if there is a repsonse it will send back to the same stream the client has send run_processes
(_services, _num_of_process)Finally runs all processes for given sockets this is mandatory for creating port bindings after creating sub-processes send_message
(message, address, stream[, …])Basic send message from service start
(_params[, _internal])basic start function start_internal_service
(server)Starts an internal service for unix socket stop
()Stops a service immediately Methods Documentation
-
add_accept_handler
(sock, callback)¶ Accept Handler for UDP Socket
Parameters: - {socket} -- Socket object (sock) –
- {function} -- callBackFunction (callback) –
Keyword Arguments: {IOLoop Obj} -- Current IOLoop (default (io_loop) – {None})
-
add_sockets
(sockets)¶ Adds speficic sockets to the server
Parameters: {[Dict]} -- Dict of Sockets (sockets) –
-
bind
(port, address=None, family=<AddressFamily.AF_UNSPEC: 0>)¶ Bind a specific socket (here UDP) to the server
Parameters: {int} -- [port number] (port) –
Keyword Arguments: - {string} -- [Address string] (default (address) – {None})
- {Socket.Family} -- [Socket.Family] (default (family) – {socket.AF_UNSPEC})
- {int} -- [description] (default (backlog) – {25})
-
bind_unix_socket
(file, mode)¶ Special binding for UnixSockets - the way unix-sockets are reused depends extremly on OS Platform
Parameters: - {string} -- file name (file) –
- {int} -- chmod mode (mode) –
Keyword Arguments: {int} -- current backlog (default (backlog) – {128})
Returns: Socket obj – the current socket
-
static
can_send
()¶ Basic info wether service can send back or not
Returns: bool – can send back?
-
close
()¶ Basic close service
-
static
get_service
(_params, _server=None)¶ Gets a service from service params EXAMPLE: _params[‘active_service’].append({
# tcp service “id”: 2, “antano_server_id”: 1, # needs to be the same as id above “service_type_id”: 2, “port”: 18002, “host”: “0.0.0.0”, “endpoint”: “”, # in case of rest or websocket /my_endpoint put “my_endpoint” “message_format_in_id”: 1, # message_format “message_format_out_id”: 1, # message_format})
Parameters: {Dict<String, Obj>} -- service param (_params) – Returns: Service obj – a service
-
make
(endpoint)¶ make app - creates a tornado endpoint with a given class
Parameters: {string} -- defined endpoints (endpoint) – Returns: obj – web endpoint application
-
on_received_message
(message, address, sock_stream)¶ On received message will process the message and if there is a repsonse it will send back to the same stream the client has send
Parameters: - {bytes[]} -- message data (message) –
- {Tuple (address) –
- {mixed} -- Socket or SOCK_STREAM (sock) –
Returns: [bytes[]] – response
-
static
run_processes
(_services, _num_of_process)¶ Finally runs all processes for given sockets this is mandatory for creating port bindings after creating sub-processes
Parameters: - {array} -- array of services (_services) –
- {int} -- number of processes to start (_num_of_process) –
-
send_message
(message, address, stream, is_binary=False)¶ Basic send message from service
Parameters: - {bytes[]} -- message data (message) –
- {Tuple (address) –
- {mixed} -- Socket or SOCK_STREAM (sock) –
-
start
(_params, _internal=False)¶ basic start function
Parameters: - {string} -- ip or host (_ip) –
- {int} -- defined port (_port) –
-
static
start_internal_service
(server)¶ Starts an internal service for unix socket
Parameters: {Server} -- AntanoServer obj (server) – Returns: Dict<string, obj> – a Service Params dict
-
stop
()¶ Stops a service immediately
-