Beispiel #1
0
 def __init__(self, producer: Callable[[], 'Actor'] = None,
              spawner: Callable[[str, 'Props', PID], PID] = default_spawner,
              mailbox_producer: Callable[[], mailbox.AbstractMailbox] =
              MailboxFactory.create_unbounded_mailbox,
              guardian_strategy: AbstractSupervisorStrategy = None,
              supervisor_strategy: AbstractSupervisorStrategy = Supervision.default_strategy,
              dispatcher: AbstractDispatcher = Dispatchers().default_dispatcher,
              receive_middleware: List[Callable[[AbstractContext], Task]] = [],
              sender_middleware: List[Callable[[AbstractContext], Task]] = [],
              receive_middleware_chain: Callable[[AbstractContext], Task] = None,
              sender_middleware_chain: Callable[[AbstractContext], Task] = None,
              context_decorator: List[Callable[[AbstractContext], AbstractContext]] = [],
              context_decorator_chain: Callable[[AbstractContext], AbstractContext] = default_context_decorator) -> \
         None:
     self.__spawner = spawner
     self.__producer = producer
     self.__mailbox_producer = mailbox_producer
     self.__guardian_strategy = guardian_strategy
     self.__supervisor_strategy = supervisor_strategy
     self.__dispatcher = dispatcher
     self.__receive_middleware = receive_middleware
     self.__sender_middleware = sender_middleware
     self.__receive_middleware_chain = receive_middleware_chain
     self.__sender_middleware_chain = sender_middleware_chain
     self.__context_decorator = context_decorator
     self.__context_decorator_chain = context_decorator_chain
async def test_can_subscribe_to_specific_event_types_async():
    async def fun(msg):
        received = msg
        assert received == 'hello'

    event_stream = EventStream()
    event_stream.subscribe(fun, str, Dispatchers().default_dispatcher)
    await event_stream.publish('hello')
Beispiel #3
0
    def start(self, hostname: str, port: int, config: RemoteConfig = RemoteConfig()) -> None:
        self.__remote_config = config
        ProcessRegistry().register_host_resolver(RemoteProcess)
        EndpointManager().start()
        self._endpoint_reader = EndpointReader()

        Dispatchers().default_dispatcher.schedule(self.__run, hostname=hostname, port=port)

        address = "%s:%s" % (hostname, port)
        ProcessRegistry().address = address
        self.__spawn_activator()
    def subscribe(
        self,
        fun: Callable[..., Any],
        msg_type: type = None,
        dispatcher: AbstractDispatcher = Dispatchers().synchronous_dispatcher
    ) -> Subscription:
        async def action(msg):
            if msg_type is None:
                await fun(msg)
            elif isinstance(msg, msg_type):
                await fun(msg)

        sub = Subscription(self, action, dispatcher)
        self._subscriptions[sub.id] = sub
        return sub
Beispiel #5
0
    def start(self,
              hostname: str,
              port: int,
              config: RemoteConfig = RemoteConfig()) -> None:
        self._remote_config = config
        ProcessRegistry().register_host_resolver(RemoteProcess)
        EndpointManager().start()
        self._endpoint_reader = EndpointReader()

        Dispatchers().default_dispatcher.schedule(self.__run,
                                                  hostname=hostname,
                                                  port=port)

        address = f'{hostname}:{port}'
        ProcessRegistry().address = address
        self.__spawn_activator()
        self._logger.debug(f'Starting Proto.Actor server on {address}')
Beispiel #6
0
    def reenter_after(self, target: Callable[[], Awaitable[Any]],
                      action: Callable[[Any], None]) -> None:
        async def run(msg):
            result = await target()
            if len(list(signature(action).parameters)) > 0:

                async def fn1():
                    return await action(result)

                await self.my_self.send_system_message(Continuation(fn1, msg))
            else:

                async def fn2():
                    return await action()

                await self.my_self.send_system_message(Continuation(fn2, msg))

        Dispatchers().default_dispatcher.schedule(
            run, msg=self._message_or_envelope)
    def monitor_member_status_changes(self) -> None:
        async def fn():
            while not self._shutdown:
                await self.__notify_statuses()

        Dispatchers().default_dispatcher.schedule(fn)