Пример #1
0
    def lookup(self, request: Request) -> List[Callable[[], Handler]]:
        """
        Looks up the handler associated with a request - matches the key on the request to a registered handler
        :param request: The request we want to find a handler for
        :return:
        """
        key = request.__class__.__name__
        if key not in self._registry:
            if request.is_command():
                raise ConfigurationException("There is no handler registered for this request")
            elif request.is_event():
                return []  # type: Callable[[] Handler]

        return self._registry[key]
Пример #2
0
    def lookup(self, request: Request) -> List[Callable[[], Handler]]:
        """
        Looks up the handler associated with a request - matches the key on the request to a registered handler
        :param request: The request we want to find a handler for
        :return:
        """
        key = request.__class__.__name__
        if key not in self._registry:
            if request.is_command():
                raise ConfigurationException(
                    "There is no handler registered for this request")
            elif request.is_event():
                return []  # type: Callable[[] Handler]

        return self._registry[key]
Пример #3
0
 def register(self, request_class: Request, handler_factory: Callable[[], Handler]) -> None:
     """
     Register the handler for the command
     :param request_class: The command or event to dispatch. It must implement getKey()
     :param handler_factory: A factory method to create the handler to dispatch to
     :return:
     """
     key = request_class.__name__
     is_command = request_class.is_command()
     is_event = request_class.is_event()
     is_present = key in self._registry
     if is_command and is_present:
         raise ConfigurationException("A handler for this request has already been registered")
     elif is_event and is_present:
         self._registry[key].append(handler_factory)
     elif is_command or is_event:
         self._registry[key] = [handler_factory]
Пример #4
0
 def register(self, request_class: Request,
              handler_factory: Callable[[], Handler]) -> None:
     """
     Register the handler for the command
     :param request_class: The command or event to dispatch. It must implement getKey()
     :param handler_factory: A factory method to create the handler to dispatch to
     :return:
     """
     key = request_class.__name__
     is_command = request_class.is_command()
     is_event = request_class.is_event()
     is_present = key in self._registry
     if is_command and is_present:
         raise ConfigurationException(
             "A handler for this request has already been registered")
     elif is_event and is_present:
         self._registry[key].append(handler_factory)
     elif is_command or is_event:
         self._registry[key] = [handler_factory]