def interaction_factory(self, context) -> ExecuteResult: si = self.super_interaction if si is not None and not si.can_run_subinteraction(self, context): return ExecuteResult(False, None, 'SuperInteraction cannot run SubInteraction.') try: interaction = self.affordance(self, context, liabilities=self._liabilities, **self._kwargs) except Exception as exc: from interactions.base.interaction import logger logger.exception('{}: Error instantiating affordance:', self) return ExecuteResult(False, None, 'Error instantiating affordance: {}'.format(exc)) if si is not None: interaction.super_interaction = si if context.continuation_id is not None: services.get_master_controller().reset_timestamp_for_sim(context.sim) return ExecuteResult(True, interaction, None)
def on_remove(self): self.remove_callbacks() self.owner.routing_component.on_sim_removed() master_controller = services.get_master_controller() master_controller.remove_sim(self.owner) if self.privacy_rules: privacy_service = services.privacy_service() privacy_service.remove_vehicle_to_monitor(self.owner)
def _setup(self): master_controller = services.get_master_controller() master_controller.add_sim(self.owner) if self.privacy_rules: privacy_service = services.privacy_service() privacy_service.add_vehicle_to_monitor(self.owner) self.owner.routing_component.on_sim_added() self.add_callbacks()
def interaction_factory(self, context) -> ExecuteResult: si = self.super_interaction if si is not None and not si.can_run_subinteraction(self, context): return ExecuteResult( False, None, 'SuperInteraction cannot run SubInteraction.') try: interaction = self.affordance(self, context, liabilities=self._liabilities, **self._kwargs) except Exception as exc: from interactions.base.interaction import logger logger.exception('{}: Error instantiating affordance:', self) return ExecuteResult( False, None, 'Error instantiating affordance: {}'.format(exc)) if si is not None: interaction.super_interaction = si if context.continuation_id is not None: services.get_master_controller().reset_timestamp_for_sim( context.sim) return ExecuteResult(True, interaction, None)
def _process(self): logger.debug('Start Processing') if gsi_handlers.reset_handlers.reset_log_archiver.enabled: gsi_handlers.reset_handlers.archive_reset_log_message( 'Start Processing') self._is_processing = True hard_stop_error = False master_controller = services.get_master_controller() try: if master_controller is not None: master_controller.on_reset_begin() while self._all_reset_records: for stage in range(_Stage.PROCESSING_COUNT): if self._staged_records[stage]: self._process_one_record(stage) break except HardStopError: hard_stop_error = True logger.debug('Hard Stop out of Processing') if gsi_handlers.reset_handlers.reset_log_archiver.enabled: gsi_handlers.reset_handlers.archive_reset_log_message( 'Hard Stop out of Processing') raise except BaseException: logger.exception( 'Unexpected exception while processing ResetAndDeleteService.') finally: self._is_processing = False if not hard_stop_error: logger.debug('Stop Processing') if gsi_handlers.reset_handlers.reset_log_archiver.enabled: gsi_handlers.reset_handlers.archive_reset_log_message( 'Stop Processing') logger.debug('Poke MasterController:{}', self._master_controller_sims) if gsi_handlers.reset_handlers.reset_log_archiver.enabled: gsi_handlers.reset_handlers.archive_reset_log_message( 'Poke MasterController:{}'.format( self._master_controller_sims)) try: sims = self._master_controller_sims self._master_controller_sims = set() if master_controller is not None: master_controller.on_reset_end(*sims) except BaseException: logger.exception( 'Unexpected exception in master_controller.on_reset_end.')
def _do_spawn_gen(timeline): nonlocal middle_bassinet, new_bassinet self.interaction.add_exit_function(_on_interaction_exit) self.interaction.remove_liability('ReservationLiability') if is_external: middle_bassinet = self.interaction.target target_sim = bassinet else: for handler in bassinet.get_reservation_handlers(): if handler.sim is self.interaction.sim: bassinet.remove_reservation_handler(handler) middle_bassinet = bassinet.replace_for_age_up( interaction=self.interaction) yield timeline.run_child( SleepElement(interval_in_real_seconds(1))) target_sim = self.spawn_for_age_up( sim_info, bassinet.position, sim_location=bassinet.location) self.interaction.context.create_target_override = target_sim yield from target_sim._startup_sim_gen(timeline) master_controller = services.get_master_controller() master_controller.add_global_lock(target_sim) self.interaction.add_exit_function( lambda *_, **__: master_controller.remove_global_lock( target_sim)) self.interaction.add_liability( WorkLockLiability.LIABILITY_TOKEN, WorkLockLiability(sim=target_sim)) def _add_bassinet(obj): obj.location = middle_bassinet.location obj.opacity = 0 new_bassinet = create_object( BabyTuning.get_corresponding_definition( middle_bassinet.definition), init=_add_bassinet) def _on_age_up_event(*_, **__): new_bassinet.opacity = 1 middle_bassinet.remove_from_client() self._action = AgeUpBaby(sim_info, callback=_on_age_up_event)
def _process(self): logger.debug('Start Processing') if gsi_handlers.reset_handlers.reset_log_archiver.enabled: gsi_handlers.reset_handlers.archive_reset_log_message('Start Processing') self._is_processing = True hard_stop_error = False master_controller = services.get_master_controller() master_controller.on_reset_begin() try: while self._all_reset_records: for stage in range(_Stage.PROCESSING_COUNT): while self._staged_records[stage]: self._process_one_record(stage) break except HardStopError: hard_stop_error = True logger.debug('Hard Stop out of Processing') if gsi_handlers.reset_handlers.reset_log_archiver.enabled: gsi_handlers.reset_handlers.archive_reset_log_message('Hard Stop out of Processing') raise except BaseException: logger.exception('Unexpected exception while processing ResetAndDeleteService.') finally: self._is_processing = False if not hard_stop_error: logger.debug('Stop Processing') if gsi_handlers.reset_handlers.reset_log_archiver.enabled: gsi_handlers.reset_handlers.archive_reset_log_message('Stop Processing') logger.debug('Poke MasterController:{}', self._master_controller_sims) if gsi_handlers.reset_handlers.reset_log_archiver.enabled: gsi_handlers.reset_handlers.archive_reset_log_message('Poke MasterController:{}'.format(self._master_controller_sims)) try: sims = self._master_controller_sims self._master_controller_sims = set() master_controller.on_reset_end(*sims) except BaseException: logger.exception('Unexpected exception in master_controller.on_reset_end.')
def component_reset(self, reset_reason): if self._running_behavior is not None: self._pending_running_behavior = type(self._running_behavior) self._running_behavior.trigger_hard_stop() self._set_running_behavior(None) services.get_master_controller().on_reset_sim(self.owner, reset_reason)