Package org.xsocket.connection

Examples of org.xsocket.connection.INonBlockingConnection


   
    public SSLClientToProxyHandler(String forwardHost, int forwardPort, INonBlockingConnection clientToProxyConnection) throws IOException {
      clientToProxyConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      clientToProxyConnection.setAutoflush(true);
     
      INonBlockingConnection proxyToServerConnection = new NonBlockingConnection(InetAddress.getByName(forwardHost), forwardPort, new ProxyHandler(), 60 * 1000, SSLTestContextFactory.getSSLContext(), true, clientToProxyConnection.getWorkerpool());
     
      proxyToServerConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      proxyToServerConnection.setAutoflush(true);
      proxyToServerConnection.setAttachment(clientToProxyConnection);
     
      clientToProxyConnection.setAttachment(proxyToServerConnection);
    }
View Full Code Here


        SimpleDualPortServer dualPortServer = new SimpleDualPortServer(0, 0);
        new Thread(dualPortServer).start();
       
        QAUtil.sleep(1000);
    
        INonBlockingConnection nbc1 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc1.write((int) 55);
       
        INonBlockingConnection nbc2 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc2.write((int) 55);
       
        INonBlockingConnection nbc3 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc3.write((int) 66);
       
        QAUtil.sleep(1000);
       
        HttpClient httpClient = new HttpClient();

        IHttpResponse response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/66", "text/plain", "hello you"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you", response.getBlockingBody().readString());
       

        response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/66", "text/plain", "hello you2"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you2", response.getBlockingBody().readString());


        response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/55", "text/plain", "hello you3"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you3", response.getBlockingBody().readString());

       
        httpClient.close();
        nbc1.close();
        nbc2.close();
        nbc3.close();
        dualPortServer.close();
    }
View Full Code Here

      return true;
    }
   
   
    public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
      INonBlockingConnection forwardConnection = (INonBlockingConnection) connection.getAttachment();

      ByteBuffer[] data = connection.readByteBufferByLength(connection.available());
      forwardConnection.write(data);
      forwardConnection.flush();
     
      return true;
    }
View Full Code Here

   
    public SSLClientToProxyHandler(String forwardHost, int forwardPort, INonBlockingConnection clientToProxyConnection) throws IOException {
      clientToProxyConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      clientToProxyConnection.setAutoflush(true);
     
      INonBlockingConnection proxyToServerConnection = new NonBlockingConnection(InetAddress.getByName(forwardHost), forwardPort, new ProxyHandler(), 60 * 1000, SSLTestContextFactory.getSSLContext(), true, clientToProxyConnection.getWorkerpool());
     
      proxyToServerConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      proxyToServerConnection.setAutoflush(true);
      proxyToServerConnection.setAttachment(clientToProxyConnection);
     
      clientToProxyConnection.setAttachment(proxyToServerConnection);
    }
View Full Code Here

   
    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());
View Full Code Here

          host = target.substring(0, idx);
          port = Integer.parseInt(target.substring(idx + 1, target.length()).trim());
        }
       
       
        INonBlockingConnection tcpConnection = exchange.getConnection().getUnderlyingTcpConnection();
       
        SSLClientToProxyHandler proxyHandler = new SSLClientToProxyHandler(host, port, tcpConnection);
        tcpConnection.setHandler(proxyHandler);
       
        HttpResponse response = new HttpResponse(200);
        exchange.send(response);
      }
    }
View Full Code Here

   
    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());
View Full Code Here

   
    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());
View Full Code Here

  @Execution(Execution.NONTHREADED)
  private static class ProxyHandler implements IDataHandler, IDisconnectHandler {
   
 
    public boolean onDisconnect(INonBlockingConnection connection) throws IOException {
      INonBlockingConnection reverseConnection = (INonBlockingConnection) connection.getAttachment();
      if (reverseConnection != null) {
        connection.setAttachment(null);
        reverseConnection.close();
      }
      return true;
    }
View Full Code Here

        SimpleDualPortServer dualPortServer = new SimpleDualPortServer(0, 0);
        new Thread(dualPortServer).start();
       
        QAUtil.sleep(1000);
    
        INonBlockingConnection nbc1 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc1.write((int) 55);
       
        INonBlockingConnection nbc2 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc2.write((int) 55);
       
        INonBlockingConnection nbc3 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc3.write((int) 66);
       
        QAUtil.sleep(1000);
       
        HttpClient httpClient = new HttpClient();

        IHttpResponse response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/66", "text/plain", "hello you"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you", response.getBlockingBody().readString());
       

        response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/66", "text/plain", "hello you2"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you2", response.getBlockingBody().readString());


        response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/55", "text/plain", "hello you3"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you3", response.getBlockingBody().readString());

       
        httpClient.close();
        nbc1.close();
        nbc2.close();
        nbc3.close();
        dualPortServer.close();
    }
View Full Code Here

TOP

Related Classes of org.xsocket.connection.INonBlockingConnection

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.