def shutdown(self): log.debug(self, "shutting down") try: self.__valve.shutdown() print "closing port" except socket.error as e: print "ERROR:", e.args
def __init__(self, overlay, name_store, type_store, migration_store, script_store, socket_store): self.__locations = dict() self.__overlay = overlay self.__name_store = name_store self.__type_store = type_store self.__migration_store = migration_store self.__script_store = script_store self.__location_lock = threading.Lock() self.__theatre_lock = threading.Lock() self.__theatres = [] self.__socket_store = socket_store log.debug(self, 'initialised')
def socket_call(self, socket, method, *args, **kwds): log.debug(self,"Call %s on socket %s" % (method, socket)) try: meth = getattr(self.__socket_store.get_socket(socket), method) if meth: res = meth(*args, **kwds) return res else: log.error(self, "No such method %s for socket" % method) except KeyError as e: log.error(self, "Exception %s calling %s on socket %s" % (e, method, socket)) #return "Goodbye"
def begin(self): loc = ManagerExternalInterface( self.overlay, self.name_store, self.type_store, self.migration_store, self.script_store, self.socket_store ) port = self.port while port < self.port + 10: if self.takeport(port, loc): self.port = port break port = port + 1 log.debug(self, "listening on port %s" % port) here = socket.gethostbyname(socket.gethostname()) + ":%d" % self.port ipfinder.create_ip_server(DEFAULT_MANAGER_PORT - 1) self.overlay.here(here) self.overlay.populate(sys.argv) vis.add_manager(here) self.shell()
def isdead(self, actor_id): self.__location_lock.acquire() log.debug(self, 'isdead request - actor with id = %s' % actor_id) if self.__locations.has_key(actor_id): del self.__locations[actor_id] log.debug(self, 'REMOVE - actor removed. id = %s' % actor_id) else: log.debug(self, 'death attempted on non-existant actor. Id = %s' % actor_id) self.__location_lock.release()
def whereis(self, actor_id): log.debug(self, 'whereis actor with id = %s' % actor_id) self.__location_lock.acquire() location = None if self.__locations.has_key(actor_id): location = self.__locations[actor_id] log.debug(self, 'FOUND - actor with id = %s at %s' % (actor_id, location)) else: log.debug(self, 'NOT FOUND - location of actor with id = %s not known' % actor_id) self.__location_lock.release() return location
def globalactoris(self, actor_id, location): self.__location_lock.acquire() log.debug(self, 'globalactoris request, actor with id = %s at location %s' % (actor_id, location)) existing_location = None if self.__locations.has_key(actor_id): existing_location = self.__locations[actor_id] log.debug(self, 'global actor ALREADY registered. Id = %s already at location %s' % (actor_id, existing_location)) else: self.__locations[actor_id] = location log.debug(self, 'global actor registered. Id = %s registered at location %s' % (actor_id, location)) self.__location_lock.release() return existing_location
def close_socket(self, socket_id): log.debug(self, "Closing socket %s" % socket_id) self.__socket_store.get_socket(socket_id).close()
def connect_socket(self, address): log.debug(self, "Connecting to %s:%d" % address) return self.__socket_store.connect_socket(address)
def open_socket(self, port): log.debug(self, "Opening port %d" % port) return self.__socket_store.open_socket(port)
def actoris(self, actor_id, location): self.__location_lock.acquire() log.debug(self, 'actoris request, actor with id = %s at location %s' % (actor_id, location)) location = self.__locations[actor_id] = location log.debug(self, 'actor registered. Id = %s registered at location %s' % (actor_id, location)) self.__location_lock.release()