Example #1
0
 def _supplier_connector_state_changed(self, idurl, newstate):
     lg.out(
         14, 'fire_hire._supplier_connector_state_changed %s %s, state=%s' %
         (idurl, newstate, self.state))
     supplier_connector.by_idurl(idurl).remove_callback('fire_hire')
     if self.state == 'SUPPLIERS?':
         self.connect_list.remove(idurl)
     elif self.state == 'FIRE_MANY':
         self.dismiss_results.append(idurl)
     else:
         return
     self.automat('supplier-state-changed', (idurl, newstate))
Example #2
0
 def doDecideToDismiss(self, arg):
     """
     Action method.
     """
     global _SuppliersToFire
     result = set(_SuppliersToFire)
     _SuppliersToFire = []
     # if you have some empty suppliers need to get rid of them,
     # but no need to dismiss anyone at the moment.
     if '' in contactsdb.suppliers():
         lg.out(10, 'fire_hire.doDecideToDismiss found empty supplier, SKIP')
         self.automat('made-decision', [])
         return
     for supplier_idurl in contactsdb.suppliers():
         if not supplier_idurl:
             continue
         sc = supplier_connector.by_idurl(supplier_idurl)
         if not sc:
             continue
         if sc.state == 'NO_SERVICE':
             result.add(supplier_idurl)
     if contactsdb.num_suppliers() > settings.getSuppliersNumberDesired():
         for supplier_index in range(
                 settings.getSuppliersNumberDesired(),
                 contactsdb.num_suppliers()):
             idurl = contactsdb.supplier(supplier_index)
             if idurl:
                 result.add(idurl)
     result = list(result)
     lg.out(10, 'fire_hire.doDecideToDismiss %s' % result)
     self.automat('made-decision', result)
Example #3
0
 def doCleanPrevUser(self, arg):
     """
     Action method.
     """
     sc = supplier_connector.by_idurl(self.target_idurl)
     if sc:
         sc.remove_callback('supplier_finder')
     self.target_idurl = None
 def doCleanPrevUser(self, arg):
     """
     Action method.
     """
     sc = supplier_connector.by_idurl(self.target_idurl)
     if sc:
         sc.remove_callback('supplier_finder')
     self.target_idurl = None
Example #5
0
 def doSupplierConnect(self, arg):
     """
     Action method.
     """
     sc = supplier_connector.by_idurl(self.target_idurl)
     if not sc:
         sc = supplier_connector.create(self.target_idurl)
     sc.automat('connect')
     sc.set_callback('supplier_finder', self._supplier_connector_state)
 def doSupplierConnect(self, arg):
     """
     Action method.
     """
     sc = supplier_connector.by_idurl(self.target_idurl)
     if not sc:
         sc = supplier_connector.create(self.target_idurl)
     sc.automat('connect')
     sc.set_callback('supplier_finder', self._supplier_connector_state)
Example #7
0
 def doCloseConnectors(self, arg):
     """
     Action method.
     """
     for supplier_idurl in self.dismiss_list:
         sc = supplier_connector.by_idurl(supplier_idurl)
         if supplier_idurl in self.dismiss_list:
             self.dismiss_list.remove(supplier_idurl)
         if sc:
             sc.automat('shutdown')
Example #8
0
 def doCloseConnector(self, arg):
     """
     Action method.
     """
     supplier_idurl, supplier_state = arg
     sc = supplier_connector.by_idurl(supplier_idurl)
     if supplier_idurl in self.dismiss_list:
         self.dismiss_list.remove(supplier_idurl)
     if sc:
         sc.automat('shutdown')
     else:
         raise Exception('supplier_connector must exist')
Example #9
0
 def doDestroyMe(self, arg):
     """
     Remove all references to the state machine object to destroy it.
     """
     global _SupplierFinder
     del _SupplierFinder
     _SupplierFinder = None
     callback.remove_inbox_callback(self._inbox_packet_received)
     if self.target_idurl:
         sc = supplier_connector.by_idurl(self.target_idurl)
         if sc:
             sc.remove_callback('supplier_finder')
         self.target_idurl = None
     self.destroy()
     lg.out(14, 'supplier_finder.doDestroyMy index=%s' % self.index)
Example #10
0
 def doDestroyMe(self, arg):
     """
     Remove all references to the state machine object to destroy it.
     """
     global _SupplierFinder
     del _SupplierFinder
     _SupplierFinder = None
     callback.remove_inbox_callback(self._inbox_packet_received)
     if self.target_idurl:
         sc = supplier_connector.by_idurl(self.target_idurl)
         if sc:
             sc.remove_callback('supplier_finder')
         self.target_idurl = None
     self.destroy()
     lg.out(14, 'supplier_finder.doDestroyMy index=%s' % self.index)
Example #11
0
 def doDisconnectSuppliers(self, arg):
     """
     Action method.
     """
     lg.out(10, 'fire_hire.doDisconnectSuppliers %r' % self.dismiss_list)
     self.dismiss_results = []
     for supplier_idurl in self.dismiss_list:
         sc = supplier_connector.by_idurl(supplier_idurl)
         if sc:
             sc.set_callback('fire_hire',
                             self._supplier_connector_state_changed)
             sc.automat('disconnect')
         else:
             lg.warn(
                 'supplier_connector must exist, but not found %s' %
                 supplier_idurl)
Example #12
0
 def doConnectSuppliers(self, arg):
     """
     Action method.
     """
     self.connect_list = []
     for supplier_idurl in contactsdb.suppliers():
         if supplier_idurl == '':
             continue
         sc = supplier_connector.by_idurl(supplier_idurl)
         if sc is None:
             sc = supplier_connector.create(supplier_idurl)
         sc.set_callback(
             'fire_hire',
             self._supplier_connector_state_changed)
         self.connect_list.append(supplier_idurl)
         sc.automat('connect')
Example #13
0
 def FileSendAck(self, newpacket, info):
     if self.shutdown:
         lg.out(
             10,
             "io_throttle.FileSendAck finishing to %s, shutdown is True" %
             self.remoteName)
         return
     self.ackedCount += 1
     packetID = global_id.CanonicalID(newpacket.PacketID)
     if packetID not in self.fileSendQueue:
         lg.warn("packet %s not in sending queue for %s" %
                 (newpacket.PacketID, self.remoteName))
         return
     if packetID not in self.fileSendDict.keys():
         lg.warn("packet %s not in sending dict for %s" %
                 (newpacket.PacketID, self.remoteName))
         return
     self.fileSendDict[packetID].ackTime = time.time()
     if newpacket.Command == commands.Ack():
         self.fileSendDict[packetID].result = 'acked'
         if self.fileSendDict[packetID].callOnAck:
             reactor.callLater(0, self.fileSendDict[packetID].callOnAck,
                               newpacket, newpacket.OwnerID, packetID)
     elif newpacket.Command == commands.Fail():
         self.fileSendDict[packetID].result = 'failed'
         if self.fileSendDict[packetID].callOnFail:
             reactor.callLater(0, self.fileSendDict[packetID].callOnFail,
                               newpacket.CreatorID, packetID, 'failed')
     import supplier_connector
     sc = supplier_connector.by_idurl(newpacket.OwnerID)
     if sc:
         if newpacket.Command == commands.Ack():
             sc.automat('ack', newpacket)
         elif newpacket.Command == commands.Fail():
             sc.automat('fail', newpacket)
         elif newpacket.Command == commands.Data():
             sc.automat('data', newpacket)
         else:
             raise Exception('incorrect packet type received')
     self.DoSend()
     # self.RunSend()
     lg.out(
         14, "io_throttle.FileSendAck %s from %s, queue=%d" %
         (str(newpacket), self.remoteName, len(self.fileSendQueue)))