def _set_state(self, state): # Managed state handling # Update since if previously a shadow actor the init has been called first # which potentially have altered the managed attributes set compared # with the recorded state self._managed.update(set(state['_managed'])) for key in state['_managed']: if key not in self.__dict__: self.__dict__[key] = state.pop(key) else: obj = self.__dict__[key] if _implements_state(obj): obj.set_state(state.pop(key)) else: self.__dict__[key] = state.pop(key) # Manual state handling for port in state['inports']: # Uses setdefault to support shadow actor self.inports.setdefault(port, actorport.InPort( port, self))._set_state(state['inports'][port]) for port in state['outports']: # Uses setdefault to support shadow actor self.outports.setdefault(port, actorport.OutPort( port, self))._set_state(state['outports'][port]) self._component_members = set(state['_component_members'])
def _set_private_state(self, state): """Deserialize and apply state common to all actors""" get_calvinsys().deserialize(actor=self, csobjects=state["_calvinsys"]) for port in state['inports']: # Uses setdefault to support shadow actor self.inports.setdefault(port, actorport.InPort( port, self))._set_state(state['inports'][port]) for port in state['outports']: # Uses setdefault to support shadow actor self.outports.setdefault(port, actorport.OutPort( port, self))._set_state(state['outports'][port]) self._component_members = set(state['_component_members']) # FIXME: The objects in _private_state_keys are well known, they are private after all, # and we shouldn't need this generic handler. for key in self._private_state_keys: if key not in self.__dict__: self.__dict__[key] = state.pop(key, None) else: obj = self.__dict__[key] if _implements_state(obj): obj.set_state(state.pop(key)) else: self.__dict__[key] = state.pop(key, None)
def __init__(self, actor_type, name='', allow_invalid_transitions=True, disable_transition_checks=False, disable_state_checks=False, actor_id=None, security=None): """Should _not_ be overridden in subclasses.""" super(Actor, self).__init__() self._type = actor_type self._name = name # optional: human_readable_name self._id = actor_id or calvinuuid.uuid("ACTOR") _log.debug("New actor id: %s, supplied actor id %s" % (self._id, actor_id)) self._deployment_requirements = [] self._port_property_capabilities = None self._signature = None self._component_members = set( [self._id]) # We are only part of component if this is extended self._managed = set( ('_id', '_name', '_has_started', '_deployment_requirements', '_signature', '_subject_attributes', '_migration_info', "_port_property_capabilities", "_replication_data")) self._has_started = False self._calvinsys = None self._using = {} # self.control = calvincontrol.get_calvincontrol() # self.metering = metering.get_metering() self._migration_info = None self._migrating_to = None # During migration while on the previous node set to the next node id self._last_time_warning = 0.0 self.sec = security self._subject_attributes = self.sec.get_subject_attributes( ) if self.sec is not None else None self.authorization_checks = None self._replication_data = ReplicationData(initialize=False) self._exhaust_cb = None self.inports = { p: actorport.InPort(p, self, pp) for p, pp in self.inport_properties.items() } self.outports = { p: actorport.OutPort(p, self, pp) for p, pp in self.outport_properties.items() } hooks = { (Actor.STATUS.PENDING, Actor.STATUS.ENABLED): self._will_start, (Actor.STATUS.ENABLED, Actor.STATUS.PENDING): self.will_stop, } self.fsm = Actor.FSM( Actor.STATUS, Actor.STATUS.LOADED, Actor.VALID_TRANSITIONS, hooks, allow_invalid_transitions=allow_invalid_transitions, disable_transition_checks=disable_transition_checks, disable_state_checks=disable_state_checks)
def create_shadow_port(self, port_name, port_dir, port_id=None): # TODO check if we should create port against meta info if port_dir == "in": self.inport_properties[port_name] = {} port = actorport.InPort(port_name, self) self.inports[port_name] = port else: self.outport_properties[port_name] = {} port = actorport.OutPort(port_name, self) self.outports[port_name] = port return port
def __init__(self, actor_type, name='', allow_invalid_transitions=True, disable_transition_checks=False, disable_state_checks=False, actor_id=None): """Should _not_ be overridden in subclasses.""" super(Actor, self).__init__() self._type = actor_type self.name = name # optional: human_readable_name self.id = actor_id or calvinuuid.uuid("ACTOR") self._deployment_requirements = [] self._managed = set(('id', 'name', '_deployment_requirements')) self._calvinsys = None self._using = {} self.control = calvincontrol.get_calvincontrol() self._migrating_to = None # During migration while on the previous node set to the next node id self.inports = { p: actorport.InPort(p, self) for p in self.inport_names } self.outports = { p: actorport.OutPort(p, self) for p in self.outport_names } hooks = { (Actor.STATUS.PENDING, Actor.STATUS.ENABLED): self.will_start, (Actor.STATUS.ENABLED, Actor.STATUS.PENDING): self.will_stop, } self.fsm = Actor.FSM( Actor.STATUS, Actor.STATUS.LOADED, Actor.VALID_TRANSITIONS, hooks, allow_invalid_transitions=allow_invalid_transitions, disable_transition_checks=disable_transition_checks, disable_state_checks=disable_state_checks)
def __init__(self, actor_type, name='', allow_invalid_transitions=True, disable_transition_checks=False, disable_state_checks=False, actor_id=None): """Should normally _not_ be overridden in subclasses.""" super(Actor, self).__init__() self._type = actor_type self.name = name # optional: human_readable_name self.id = actor_id or calvinuuid.uuid("ACTOR") self._managed = set(('id', 'name')) self.calvinsys = None # CalvinSys(node) self.control = calvincontrol.get_calvincontrol() self.inports = { p: actorport.InPort(p, self) for p in self.inport_names } self.outports = { p: actorport.OutPort(p, self) for p in self.outport_names } hooks = { (Actor.STATUS.PENDING, Actor.STATUS.ENABLED): self.will_start, (Actor.STATUS.ENABLED, Actor.STATUS.PENDING): self.will_stop, } self.fsm = Actor.FSM( Actor.STATUS, Actor.STATUS.LOADED, Actor.VALID_TRANSITIONS, hooks, allow_invalid_transitions=allow_invalid_transitions, disable_transition_checks=disable_transition_checks, disable_state_checks=disable_state_checks)