예제 #1
0
파일: messenger.py 프로젝트: fredvdd/Swan
 def send(self, actor_id, msg):
    message = copy.deepcopy(msg)
    success = False
    retries = 0
    new_actor_id = None
    actor_location = ids.loc(actor_id)
    while not success and retries < MAX_RETRIES:
      conn = rpc.RPCConnector(actor_location)
      try:
        if actor_location == self.here:
          (success, new_actor_id) = self.message_local(actor_id, message)
          if success:
            return (True, new_actor_id)
        remote_theatre = conn.connect()
        (success, new_actor_id) = remote_theatre.incoming_message(actor_id, message)
        remote_theatre.disconnect()
        if success:
          return (True, new_actor_id)
        time.sleep(0.8)
      except Exception:
        print 'Senderror:'
        log.warn(self, 'sending message to %s failed, retrying, as host (%s) was unreachable (message was: %s)' % (actor_id, actor_location, message))
        log.warn(self, traceback.format_exc())
        new_actor_id = local_theatre().get_migration(actor_id)
        if new_actor_id:
          actor_id = new_actor_id
          actor_location = ids.loc(actor_id)
        retries += 1 
        continue
      if not success:
        log.warn(self, 'sending message to %s failed retrying (message was: %s)' % (actor_id, message))
        new_actor_id = local_theatre().get_migration(actor_id)
        if new_actor_id and not new_actor_id == 'NONE':
          actor_id = new_actor_id
          actor_location = ids.loc(actor_id)
        retries += 1 
    log.error(self, 'sending message to %s aborted after %s retries (message was: %s)' % (actor_id, MAX_RETRIES, message)) 
    return (False, new_actor_id)
예제 #2
0
파일: messenger.py 프로젝트: fredvdd/Swan
 def message_local(self, actor_id, message):
  """Send a message to a local actor. Returns True iff
     the send was sucessful""" 
  local_actor = self.__actor_store.get_ref(actor_id) 
  if local_actor:
    local_actor.add_message(message)
    return (True, None)
  local_port = self.__actor_store.get_port(actor_id) 
  if local_port:
   actor_id = ids.change_port(actor_id, local_port)
   conn = rpc.RPCConnector(ids.loc(actor_id))
   remote_theatre = conn.connect()
   success = remote_theatre.incoming_message(actor_id, message)
   remote_theatre.disconnect()
   return(success, actor_id)
  return (False, None)
예제 #3
0
파일: client.py 프로젝트: fredvdd/Swan
 def shell(self, command):
   opt = command[0:2] 
   param = command[2:len(command)]
   if opt == "l ":
     self.attached = Person(param)
     here = ids.loc(self.actor_id)
     self.attached.attach(param, here)
     self.help()
   if opt == "q":
      if self.attached is not None:
        self.attached.migrate_away()
      die()
   if opt == "w" and self.attached is not None:
     self.attached.print_wall()
   if opt == "y " and self.attached is not None:
     self.attached.yap(param)
   if opt == "f " and self.attached is not None:
       self.attached.follow(param)
   if opt == "h":
     self.help()
예제 #4
0
파일: person.py 프로젝트: fredvdd/Swan
 def migrate_away(self):
   holder = find_type("Holder")
   theatre = ids.loc(holder.actor_id)
   migrate_to(theatre)
예제 #5
0
파일: displayable.py 프로젝트: fredvdd/Swan
 def store_type(self, actor):
   ref = VisActorRef(ids.type(actor), ids.loc(actor))
   self.type_store.append(ref)
예제 #6
0
파일: displayable.py 프로젝트: fredvdd/Swan
 def store_name(self, name, actor):
   ref = VisActorRef("'" + name + "'", ids.loc(actor))
   self.name_store.append(ref)