class RequestDispatcher {

  public void dispatch(String endpointId, JsonRpcRequest request) throws JsonRpcException {
    checkNotNull(endpointId, "Endpoint ID must not be null");
    checkArgument(!endpointId.isEmpty(), "Endpoint ID must not be empty");
    checkNotNull(request, "Request must not be null");

    LOGGER.trace("Dispatching request: " + request + ", endpoint: " + endpointId);

    String method = request.getMethod();

    JsonRpcParams params = request.getParams();

    if (request.hasId()) {
      LOGGER.trace("Request has ID");
      String requestId = request.getId();
      checkRequestHandlerRegistration(method, requestId);
      requestHandlerManager.handle(endpointId, requestId, method, params);
    } else {
      LOGGER.trace("Request has no ID -> it is a notification");
      checkNotificationHandlerRegistration(method);
      requestHandlerManager.handle(endpointId, method, params);
    }
  }

  @Inject public  RequestDispatcher(RequestHandlerManager requestHandlerManager);

}