Package com.google.code.http4j

Examples of com.google.code.http4j.Connection


    connection.connect();
  }
 
  @Test(dependsOnMethods = "connect", expectedExceptions = SocketTimeoutException.class)
  public void setTimeout() throws IOException {
    Connection conn = createConnection();
    conn.setTimeout(1);
    conn.connect();
  }
View Full Code Here


  }

  @Test(dependsOnMethods = "release")
  public void shutdown() throws InterruptedException, IOException {
    manager.shutdown();
    Connection connection = manager.acquire(host);
    Assert.assertNull(connection);
    boolean released = manager.release(connection1);
    Assert.assertFalse(released);
  }
View Full Code Here

  public void setMaxConnectionsPerHost() throws InterruptedException,
      ExecutionException, TimeoutException, IOException {
    final ConnectionManager pool = new ConnectionPool();
    pool.setMaxConnectionsPerHost(1);
    try {
      Connection connection = pool.acquire(host);
      Assert.assertNotNull(connection);
      pool.release(connection);
      connection = pool.acquire(host);
      Assert.assertNotNull(connection);
      ExecutorService service = Executors.newSingleThreadExecutor();
View Full Code Here

    return reuse;
  }
 
  protected Connection getConnection(Host host) throws InterruptedException, IOException {
    Queue<Connection> queue = getFreeQueue(host);
    Connection connection = queue.poll();
    connection = connection == null || connection.isClosed() ? host.newConnection() : connection;
    return connection;
  }
View Full Code Here

  public final Connection acquire(Host host) throws InterruptedException, IOException {
    if(!shutdown.get()) {
      increaseUsed(host);
      Timer blockingTimer = ThreadLocalMetricsRecorder.getInstance().getBlockingTimer();
      blockingTimer.start();
      Connection connection = getConnection(host);
      blockingTimer.stop();
      return connection;
    }
    return null;
  }
View Full Code Here

  }

  @Override
  public Response execute(Request request) throws InterruptedException, IOException {
    ThreadLocalMetricsRecorder.getInstance().reset();
    Connection connection = connectionManager.acquire(request.getHost());
    try {
      send(connection.getOutputStream(), request);
      Response response = receive(connection.getInputStream());
      afterResponse(request, response, connection);
      return response;
    } catch (IOException e) {
      connection.close();
      throw e;
    }
  }
View Full Code Here

    return protocol;
  }

  @Override
  public Connection newConnection() throws IOException {
    Connection connection = protocol.createConnection(this);
    connection.connect();
    return connection;
  }
View Full Code Here

TOP

Related Classes of com.google.code.http4j.Connection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.