def start(self) -> None: # self.__logger.log_debug('Started EndpointManager') props = Props().from_producer(EndpointSupervisor)\ .with_guardian_supervisor_strategy(Supervision().always_restart_strategy) self._endpoint_supervisor = GlobalRootContext().instance.spawn_named(props, 'EndpointSupervisor') self._endpoint_conn_evn_sub = GlobalEventStream().instance.subscribe(self.__on_endpoint_connected, EndpointConnectedEvent) self._endpoint_term_evn_sub = GlobalEventStream().instance.subscribe(self.__on_endpoint_terminated, EndpointTerminatedEvent)
def test_props_default_init(): props = Props() assert props.producer is None # TODO: change these value with concrete default instances #assert props.mailbox_producer is None #assert props.supervisor_strategy is None assert props.dispatcher is None assert props.middleware == [] assert props.middleware_chain is None
def test_props_with(field, method, value): props = Props() with_method = getattr(props, method) new_props = with_method(value) results = [('producer', None), ('dispatcher', None), ('mailbox_producer', None), ('supervisor_strategy', None)] for r in results: field_name = r[0] prop_value = getattr(new_props, field_name) if field_name == field: assert prop_value == value else: assert prop_value == r[1]
async def start(argv): host = None port = None opts, args = getopt.getopt(argv, "hp", ["host=", "port="]) for opt, arg in opts: if opt == '--host': host = arg elif opt == '--port': port = arg Serialization().register_file_descriptor(DESCRIPTOR) context = RootContext() Remote().start(host, port) props = Props().from_producer(lambda: EchoActor(host, port)) Remote().register_known_kind('EchoActor', props) context.spawn_named(props, "EchoActorInstance") input()
def props(self) -> Props: def spawn_router_process(name: str, props: Props, parent: PID) -> PID: wg = threading.Event() router_state = self.create_router_state() p = props.with_producer(lambda: RouterActor(self, router_state, wg)) ctx = ActorContext(p, parent) mailbox = props.mailbox_producer() dispatcher = props.dispatcher process = RouterProcess(router_state, mailbox, wg) pid, absent = ProcessRegistry().try_add(name, process) if not absent: raise ProcessNameExistException(name, pid) ctx.my_self = pid mailbox.register_handlers(ctx, dispatcher) mailbox.post_system_message(Started()) mailbox.start() wg.wait() return pid return Props().with_spawner(spawn_router_process)
def __spawn_activator(self): props = Props().from_producer(Activator) \ .with_guardian_supervisor_strategy(Supervision().always_restart_strategy) self.__activator_pid = GlobalRootContext().instance.spawn_named(props, 'activator')
def hello_grain_factory(self, factory: AbstractHelloGrain) -> None: self._hello_grain_factory = factory Remote().register_known_kind( 'HelloGrain', Props().from_producer(lambda: HelloGrainActor()))