def _register_service(application, service_addr, service_resp_addr, service_passphrase, handle=True): """ Create and store a connection and it's listener and waiting_clients queue. """ logging.debug("service_passphrase: %s" % service_passphrase) assure_resource(application) key = create_resource_key(service_addr, _SERVICE_RESOURCE_TYPE) if not is_resource_registered(key): # create our service connection logging.debug("register_service creating service_conn: %s" % service_addr) service_conn = ServiceClientConnection( service_addr, service_resp_addr, service_passphrase ) # create and start our listener logging.debug("register_service starting listener: %s" % service_addr) coro_spawn( service_response_listener, application, service_addr, service_resp_addr, service_conn, service_passphrase, handle ) # give above process a chance to start coro_sleep(0) # add us to the list resource = {'service_conn': service_conn, 'waiting_clients': {}} register_resource(resource, key) logging.debug("register_service success: %s" % key) else: logging.debug("register_service ignored: %s already registered" % service_addr) return True
def process_message(self, application, message): """Function for coroutine that looks at the message, determines which handler will be used to process it, and then begins processing. The application is responsible for handling misconfigured routes. """ # see if we have initialize _resource attribute on application assure_resource(application) service_request = parse_service_request(message, application.msg_conn.passphrase) handler = application.route_message(service_request) result = handler() msg = {} if result is not None and result is not "": msg = json.dumps(result) service_response = create_service_response(service_request, handler, method='response', arguments={}, msg=msg, headers={}) application.msg_conn.send(service_response)