Ejemplo n.º 1
0
 def reply(self, msg, operation, content, headers=None):
     """
     @brief Replies to a given message, continuing the ongoing conversation
     @retval Deferred or None
     """
     ionMsg = msg.payload
     recv = ionMsg.get('reply-to', None)
     if not headers:
         headers = {}
     if recv == None:
         logging.error('No reply-to given for message '+str(msg))
     else:
         headers['conv-id'] = ionMsg.get('conv-id','')
         headers['conv-seq'] = int(ionMsg.get('conv-seq',0)) + 1
         return self.send(pu.get_process_id(recv), operation, content, headers)
Ejemplo n.º 2
0
    def __init__(self, receiver=None, spawnArgs=None):
        """
        Initialize process using an optional receiver and optional spawn args
        @param receiver  instance of a Receiver for process control
        @param spawnArgs  standard and additional spawn arguments
        """
        #logging.debug('BaseProcess.__init__()')
        self.procState = "UNINITIALIZED"
        spawnArgs = spawnArgs.copy() if spawnArgs else {}
        self.spawnArgs = spawnArgs
        self.init_time = pu.currenttime_ms()

        # Name (human readable label) of this process.
        self.procName = self.spawnArgs.get('proc-name', __name__)

        # The system unique ID; propagates from root supv to all child procs
        sysname = ioninit.cont_args.get('sysname', Container.id)
        self.sysName = self.spawnArgs.get('sys-name', sysname)

        # The process ID of the supervisor process
        self.procSupId = pu.get_process_id(self.spawnArgs.get('sup-id', None))

        if not receiver:
            receiver = Receiver(self.procName)
        self.receiver = receiver
        receiver.handle(self.receive)

        # Dict of all receivers of this process. Key is the name
        self.receivers = {}
        self.add_receiver(self.receiver)

        # Dict of converations.
        # @todo: make sure this is garbage collected once in a while
        self.conversations = {}
        # Conversations by conv-id for currently outstanding RPCs
        self.rpc_conv = {}

        # List of ProcessDesc instances of defined and spawned child processes
        self.child_procs = []

        logging.info("Process init'd: proc-name=%s, sup-id=%s, sys-name=%s" % (
                self.procName, self.procSupId, self.sysName))