Example #1
0
    def on_message(self, msg):
        '''
        When a message with an already knwon traversal_id is received,
        we try to build a duplication message and send it in to a protocol
        dependent recipient. This is used in contracts traversing
        the graph, when the contract has rereached the same shard.
        This message is necessary, as silently ignoring the incoming bids
        adds a lot of latency to the nested contracts (it is waitng to receive
        message from all the recipients).
        '''
        self.log('Received message: %r', msg)

        # Check if it isn't expired message
        time_left = time.left(msg.expiration_time)
        if time_left < 0:
            self.log('Throwing away expired message. Time left: %s, '
                     'msg_class: %r', time_left, msg.get_msg_class())
            return False

        # Check for known traversal ids:
        if IFirstMessage.providedBy(msg):
            t_id = msg.traversal_id
            if t_id is None:
                self.warning(
                    "Received corrupted message. The traversal_id is None ! "
                    "Message: %r", msg)
                return False
            if t_id in self._traversal_ids:
                self.log('Throwing away already known traversal id %r, '
                         'msg_class: %r', msg.get_msg_class(), t_id)
                recp = msg.duplication_recipient()
                if recp:
                    resp = msg.duplication_message()
                    self.send_msg(recp, resp)
                return False
            else:
                self._traversal_ids.set(t_id, True, msg.expiration_time)

        # Handle registered dialog
        if IDialogMessage.providedBy(msg):
            recv_id = msg.receiver_id
            if recv_id is not None and recv_id in self._protocols:
                protocol = self._protocols[recv_id]
                protocol.on_message(msg)
                return True

        # Handle new conversation coming in (interest)
        p_type = msg.protocol_type
        if p_type in self._interests:
            p_id = msg.protocol_id
            interest = self._interests[p_type].get(p_id)
            if interest and interest.schedule_message(msg):
                return True

        self.warning("Couldn't find appropriate protocol for message: "
                     "%s", msg.get_msg_class())
        return False
Example #2
0
 def _on_died_response_handler(self, state, response):
     if state.so_took_reponsability:
         self.log('Someone already took responsability, ignoring.')
         return
     if isinstance(response, partners.ResponsabilityAccepted):
         state.so_took_reponsability = True
         time_left = time.left(response.expiration_time)
         state.timeout_call_id = state.agent.call_later(
             time_left, self._timeout_waiting_for_restart)
Example #3
0
    def testFutureTime(self):
        cur_time = python_time.time()
        fut_time = time.future(1)
        self.assertApproximates(cur_time + 1, fut_time, 0.01)

        time.scale(0.1)
        cur_time = python_time.time()
        fut_time = time.future(1)
        self.assertApproximates(cur_time / time._get_scale() + 1,
                                fut_time, 0.01)
        time_left = time.left(fut_time)
        self.assertApproximates(1, time_left, 0.01)
Example #4
0
    def _setup_expiration_call(self, expire_time, state,
                               method, *args, **kwargs):
        self.log('Setting expiration call of method: %r.%r',
                 self.__class__.__name__, method.__name__)

        time_left = time.left(expire_time)
        if time_left < 0:
            raise RuntimeError('Tried to call method in the past! ETA: %r' %
                               (time_left, ))

        def to_call(callback):
            if state:
                self._set_state(state)
            self.log('Calling method: %r with args: %r', method, args)
            d = self._call(method, *args, **kwargs)
            d.chainDeferred(callback)

        result = defer.Deferred()
        self._expiration_call = time.callLater(
            time_left, to_call, result)
        return result
Example #5
0
File: common.py Project: f3at/feat
 def set_timeout(self, expiration_time, state, callback, *args, **kwargs):
     self.cancel_timeout()
     eta = max([0, time.left(expiration_time)])
     self._timeout_call = time.call_later(
         eta, self._timeout_target, state, callback, args, kwargs)
Example #6
0
 def get_eta_to_reconnect(self):
     if self._callID:
         return time.left(self._callID.getTime())
Example #7
0
 def show_status(self):
     eta = self.reconnector and self.reconnector.active() and \
           time.left(self.reconnector.getTime())
     return "Database", self.is_connected(), self.host, self.port, eta
Example #8
0
 def _time_left(self, moment):
     return time.left(moment)
Example #9
0
 def show_connection_status(self):
     eta = self.reconnector and self.reconnector.active() and time.left(self.reconnector.getTime())
     return "CouchDB", self.is_connected(), self.host, self.port, eta