Coverage for ion/interact/request : 73.10%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#!/usr/bin/env python
@file ion/interact/request.py @author Michael Meisinger @brief Request conversation type, as specified by FIPA spec SC00026H """
""" A FSM factory for FSMs with conversation type state model for request. This is for the initiator and participant roles. """
# FSM definition # Notation STATE ^event --> NEW-STATE /callback-action-function
# INIT ^request --> REQUESTED /request
# REQUESTED ^refuse --> REFUSED /refuse
# REQUESTED ^agree --> AGREED /agree
# AGREED ^failure --> FAILED /failure
# AGREED ^inform_result --> DONE /inform_result
# ANY ^error --> ERROR /error
""" @brief Conversation instance for a request """
""" Request Conversation Type. INITIATOR >>>> role. """
""" @brief OUT msg. Send a request message """
log.debug("In Request.refuse")
""" @brief IN msg. Receive a request message """ log.debug("IN: Request.failure") return self.inform_result(message, *args, **kwargs)
def inform_result(self, message, *args, **kwargs):
log.error("Message received after process %s RPC conv-id=%s timed out=%s: %s" % ( process.proc_name, headers['conv-id'], rpc_deferred, headers)) return
#Cannot do the callback right away, because the message is not yet handled else: log.error("ERROR. Do not support non-blocking RPC yet")
elif status == process.ION_ERROR: code = -1 if isinstance(content, MessageInstance): code = content.MessageResponseCode
if 400 <= code and code < 500: err = failure.Failure(ReceivedApplicationError(headers, content)) elif 500 <= code and code < 600: err = failure.Failure(ReceivedContainerError(headers, content)) else: # Received Error is still the catch all! err = failure.Failure(ReceivedError(headers, content))
if rpc_deferred: # Cannot do the callback right away, because the message is not yet handled reactor.callLater(0, lambda: rpc_deferred.errback(err)) else: log.error("ERROR. Do not support non-blocking RPC yet")
else: log.error('RPC reply is not well formed. Header "status" must be set!') if rpc_deferred: #Cannot do the callback right away, because the message is not yet handled reactor.callLater(0, lambda: rpc_deferred.callback(res)) else: log.error("ERROR. Do not support non-blocking RPC yet")
""" Request Conversation Type. >>>> PARTICIPANT role. """
def request(self, message, *args, **kwargs): """ @brief IN msg. Receive a request message """
# Send an agree if a request message
# Note: We are NOW in a different conversation state: AGREED/REFUSED
# Invoke operation/action # In case of an application error - do not terminate the process! if log.getEffectiveLevel() <= logging.INFO: # only output all this stuff when debugging log.exception("*****Request Application error in message processing*****") log.error('*** Message Payload which cause the error: \n%s' % pu.pprint_to_string(headers)) log.error('*** Message Content: \n%s' % str(headers.get('content', '## No Content! ##'))) log.error("*****End Request Application error in message processing*****")
# @todo Should we send an err or rather reject the msg? # @note We can only send a reply_err to an RPC if msg and msg.payload['reply-to'] and msg.payload.get('performative',None)=='request': yield process.reply_err(msg, exception = ex) # *** PROBLEM. Here the conversation is in ERROR state
log.exception("*****Request Container error in message processing*****") log.error('*** Message payload received:') log.error('*** Message Payload which cause the error: \n%s' % pu.pprint_to_string(headers))
if log.getEffectiveLevel() <= logging.WARN: log.error('*** Message Content: \n%s' % str(headers.get('content', '## No Content! ##')))
log.error("*****End Request Container error in message processing*****")
# @todo Should we send an err or rather reject the msg? # @note We can only send a reply_err to an RPC if msg and msg.payload['reply-to'] and msg.payload.get('performative',None)=='request': yield process.reply_err(msg, exception = ex)
log.debug("IN: Request.refuse")
""" @brief OUT msg. Reply with a failure in request processing """ log.debug("OUT: Request.failure")
""" @brief OUT msg. Reply with a failure in request processing """
""" @brief Defines the conversation type of request with its roles and id. """
role_id="initiator", role_class=RequestInitiator) role_id="participant", role_class=RequestParticipant)
ROLE_PARTICIPANT.role_id:ROLE_PARTICIPANT}
RequestFSMFactory.S_ERROR, RequestFSMFactory.S_TIMEOUT, RequestFSMFactory.S_UNEXPECTED)
|