public void send(Request request, List<Response.ResponseListener> listeners) {
    if (!scheme.equals(request.getScheme()))
      throw new IllegalArgumentException(
          "Invalid request scheme " + request.getScheme() + " for destination " + this);
    if (!getHost().equals(request.getHost()))
      throw new IllegalArgumentException(
          "Invalid request host " + request.getHost() + " for destination " + this);
    int port = request.getPort();
    if (port >= 0 && getPort() != port)
      throw new IllegalArgumentException(
          "Invalid request port " + port + " for destination " + this);

    HttpConversation conversation = client.getConversation(request.getConversationID(), true);
    HttpExchange exchange = new HttpExchange(conversation, this, request, listeners);

    if (client.isRunning()) {
      if (exchanges.offer(exchange)) {
        if (!client.isRunning() && exchanges.remove(exchange)) {
          throw new RejectedExecutionException(client + " is stopping");
        } else {
          LOG.debug("Queued {}", request);
          requestNotifier.notifyQueued(request);
          Connection connection = acquire();
          if (connection != null) process(connection, false);
        }
      } else {
        throw new RejectedExecutionException(
            "Max requests per destination "
                + client.getMaxRequestsQueuedPerDestination()
                + " exceeded");
      }
    } else {
      throw new RejectedExecutionException(client + " is stopped");
    }
  }
Esempio n. 2
0
  protected void send(HttpRequest request, List<Response.ResponseListener> listeners) {
    if (!getScheme().equals(request.getScheme()))
      throw new IllegalArgumentException(
          "Invalid request scheme " + request.getScheme() + " for destination " + this);
    if (!getHost().equals(request.getHost()))
      throw new IllegalArgumentException(
          "Invalid request host " + request.getHost() + " for destination " + this);
    int port = request.getPort();
    if (port >= 0 && getPort() != port)
      throw new IllegalArgumentException(
          "Invalid request port " + port + " for destination " + this);

    HttpExchange exchange = new HttpExchange(this, request, listeners);

    if (client.isRunning()) {
      if (enqueue(exchanges, exchange)) {
        if (!client.isRunning() && exchanges.remove(exchange)) {
          request.abort(new RejectedExecutionException(client + " is stopping"));
        } else {
          if (LOG.isDebugEnabled()) LOG.debug("Queued {} for {}", request, this);
          requestNotifier.notifyQueued(request);
          send();
        }
      } else {
        if (LOG.isDebugEnabled())
          LOG.debug(
              "Max queue size {} exceeded by {} for {}",
              client.getMaxRequestsQueuedPerDestination(),
              request,
              this);
        request.abort(
            new RejectedExecutionException(
                "Max requests per destination "
                    + client.getMaxRequestsQueuedPerDestination()
                    + " exceeded for "
                    + this));
      }
    } else {
      request.abort(new RejectedExecutionException(client + " is stopped"));
    }
  }