Package org.xsocket.connection

Examples of org.xsocket.connection.NonBlockingConnectionPool


    };
    IServer server = new Server(dh);
    server.start();
   
   
    NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
   
    for (int i = 0; i < 5; i++) {
     
      INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
      HttpClientConnection httpCon = new HttpClientConnection(con);
     
      IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("12", response.getBlockingBody().readString());
    }
   
    QAUtil.sleep(1000);
    Assert.assertEquals(5, pool.getNumActive());
    Assert.assertEquals(0, pool.getNumIdle());
    Assert.assertEquals(0, pool.getNumDestroyed());
   
   
    INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    HttpClientConnection httpCon = new HttpClientConnection(con);
    IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();
   
    QAUtil.sleep(1000);
    con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    httpCon = new HttpClientConnection(con);
    response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();

    QAUtil.sleep(1000);
    Assert.assertEquals(5, pool.getNumActive());
    Assert.assertEquals(1, pool.getNumIdle());
    Assert.assertEquals(0, pool.getNumDestroyed());
   
   
    pool.destroy();
    server.close();
  }
View Full Code Here


    };
    IServer server = new Server(dh);
    server.start();
   
   
    NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
   
    for (int i = 0; i < 5; i++) {
     
      INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
      HttpClientConnection httpCon = new HttpClientConnection(con);
     
      IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("12", response.getBlockingBody().readString());
    }
   
    QAUtil.sleep(1000);
    Assert.assertEquals(0, pool.getNumActive());
    Assert.assertEquals(5, pool.getNumDestroyed());
   
   
    INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    HttpClientConnection httpCon = new HttpClientConnection(con);
    IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();
   
    QAUtil.sleep(1000);
    con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    httpCon = new HttpClientConnection(con);
    response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();

    QAUtil.sleep(1000);
    Assert.assertEquals(0, pool.getNumActive());
    Assert.assertEquals(7, pool.getNumDestroyed());
   
    pool.destroy();
    server.close();
 
View Full Code Here

    };
    IServer server = new Server(dh);
    server.start();
   
   
    NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
   
    for (int i = 0; i < 5; i++) {
     
      INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
      HttpClientConnection httpCon = new HttpClientConnection(con);
     
      IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("12", response.getBlockingBody().readString());
    }
   
    QAUtil.sleep(1000);
    Assert.assertEquals(0, pool.getNumActive());
    Assert.assertEquals(5, pool.getNumDestroyed());
   
   
    INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    HttpClientConnection httpCon = new HttpClientConnection(con);
    IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();
   
    QAUtil.sleep(1000);
    con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    httpCon = new HttpClientConnection(con);
    response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();

    QAUtil.sleep(1000);
    Assert.assertEquals(0, pool.getNumActive());
    Assert.assertEquals(7, pool.getNumDestroyed());
   
    pool.destroy();
    server.close();
  }
View Full Code Here

 
  @Test
  public void testLive() throws Exception {
   
    NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
   
    for (int i = 0; i < 10; i++) {
      ConnectHandler ch = new ConnectHandler();
     
      long start = System.nanoTime();
     
      INonBlockingConnection nbc = pool.getNonBlockingConnection("www.gmx.com", 80, ch);
      // perform ch.isConnected() later. It will be called multithreaded
     
      HttpClientConnection con = new HttpClientConnection(nbc);
     
      IHttpRequest request = new GetRequest("http://www.gmx.com/doesNotExist.html");
View Full Code Here

      };
     
      IServer server = new Server(dh);
      server.start();
     
      NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
             
        for (int i = 0; i < 1000; i++) {
            HttpClientConnection httpCon = new HttpClientConnection(pool.getNonBlockingConnection("localhost", server.getLocalPort()));
            IHttpResponse resp = httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
       
            InputStream in = Channels.newInputStream(resp.getBlockingBody());
            in.close();
               
            httpCon.close();
        }
       
        pool.close();
  }
View Full Code Here

    };
    IServer server = new Server(dh);
    server.start();
   
   
    NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
   
    for (int i = 0; i < 5; i++) {
     
      INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
      HttpClientConnection httpCon = new HttpClientConnection(con);
     
      IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("12", response.getBlockingBody().readString());
    }
   
    QAUtil.sleep(1000);
    Assert.assertEquals(5, pool.getNumActive());
    Assert.assertEquals(0, pool.getNumIdle());
    Assert.assertEquals(0, pool.getNumDestroyed());
   
   
    INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    HttpClientConnection httpCon = new HttpClientConnection(con);
    IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();
   
    QAUtil.sleep(1000);
    con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    httpCon = new HttpClientConnection(con);
    response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();

    QAUtil.sleep(1000);
    Assert.assertEquals(5, pool.getNumActive());
    Assert.assertEquals(1, pool.getNumIdle());
    Assert.assertEquals(0, pool.getNumDestroyed());
   
   
    pool.destroy();
    server.close();
  }
View Full Code Here

    };
    IServer server = new Server(dh);
    server.start();
   
   
    NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
   
    for (int i = 0; i < 5; i++) {
     
      INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
      HttpClientConnection httpCon = new HttpClientConnection(con);
     
      IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("12", response.getBlockingBody().readString());
    }
   
    QAUtil.sleep(1000);
    Assert.assertEquals(0, pool.getNumActive());
    Assert.assertEquals(5, pool.getNumDestroyed());
   
   
    INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    HttpClientConnection httpCon = new HttpClientConnection(con);
    IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();
   
    QAUtil.sleep(1000);
    con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    httpCon = new HttpClientConnection(con);
    response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();

    QAUtil.sleep(1000);
    Assert.assertEquals(0, pool.getNumActive());
    Assert.assertEquals(7, pool.getNumDestroyed());
   
    pool.destroy();
    server.close();
 
View Full Code Here

    };
    IServer server = new Server(dh);
    server.start();
   
   
    NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
   
    for (int i = 0; i < 5; i++) {
     
      INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
      HttpClientConnection httpCon = new HttpClientConnection(con);
     
      IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("12", response.getBlockingBody().readString());
    }
   
    QAUtil.sleep(1000);
    Assert.assertEquals(0, pool.getNumActive());
    Assert.assertEquals(5, pool.getNumDestroyed());
   
   
    INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    HttpClientConnection httpCon = new HttpClientConnection(con);
    IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();
   
    QAUtil.sleep(1000);
    con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    httpCon = new HttpClientConnection(con);
    response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBlockingBody().readString());
    httpCon.close();

    QAUtil.sleep(1000);
    Assert.assertEquals(0, pool.getNumActive());
    Assert.assertEquals(7, pool.getNumDestroyed());
   
    pool.destroy();
    server.close();
  }
View Full Code Here

   * @param interceptors  the interceptors
   */
  public HttpClient(SSLContext sslCtx, IHttpRequestHandler... interceptors) {
     
     
      pool = new NonBlockingConnectionPool(sslCtx);
      pool.setPooledMaxIdleTimeMillis(DEFAULT_PERSISTENT_CONNECTION_TIMEOUT);
     
    setPooledMaxIdleTimeMillis(DEFAULT_POOLED_IDLE_TIMEOUT_MILLIS);
    setPooledMaxLifeTimeMillis(DEFAULT_POOLED_LIFE_TIMEOUT_MILLIS);
   
View Full Code Here

                  LOG.fine("default SSLContext -> SSLContext.getDefault() is loaded automatically");
              }
          } catch (Exception ignore) { }
      }
     
    pool = new NonBlockingConnectionPool(sslContext);
    pool.setPooledMaxIdleTimeMillis(DEFAULT_PERSISTENT_CONNECTION_TIMEOUT);
  }
View Full Code Here

TOP

Related Classes of org.xsocket.connection.NonBlockingConnectionPool

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.