Search in sources :

Example 1 with BufferPool

use of org.webpieces.data.api.BufferPool in project webpieces by deanhiller.

the class IntegSingleRequest method createHttpClient.

public static Http2Socket createHttpClient(String id, boolean isHttp, InetSocketAddress addr) {
    BufferPool pool2 = new BufferCreationPool();
    HpackParser hpackParser = HpackParserFactory.createParser(pool2, false);
    Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
    ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, executor2);
    InjectionConfig injConfig = new InjectionConfig(hpackParser);
    String host = addr.getHostName();
    int port = addr.getPort();
    ForTestSslClientEngineFactory ssl = new ForTestSslClientEngineFactory();
    SSLEngine engine = ssl.createSslEngine(host, port);
    Http2Client client = Http2ClientFactory.createHttpClient(mgr, injConfig);
    Http2Socket socket;
    if (isHttp) {
        socket = client.createHttpSocket(id);
    } else {
        socket = client.createHttpsSocket(id, engine);
    }
    return socket;
}
Also used : HpackParser(com.webpieces.hpack.api.HpackParser) ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) SSLEngine(javax.net.ssl.SSLEngine) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) BufferPool(org.webpieces.data.api.BufferPool) Executor(java.util.concurrent.Executor) Http2Socket(org.webpieces.http2client.api.Http2Socket) Http2Client(org.webpieces.http2client.api.Http2Client)

Example 2 with BufferPool

use of org.webpieces.data.api.BufferPool in project webpieces by deanhiller.

the class IntegTestLocalhostThroughput method testSoTimeoutOnSocket.

public void testSoTimeoutOnSocket() throws InterruptedException {
    Executor executor = Executors.newFixedThreadPool(10, new NamedThreadFactory("serverThread"));
    BufferPool pool = new BufferCreationPool();
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
    ChannelManager mgr = factory.createMultiThreadedChanMgr("server", pool, executor);
    AsyncServerManager serverMgr = AsyncServerMgrFactory.createAsyncServer(mgr);
    AsyncServer server = serverMgr.createTcpServer(new AsyncConfig("tcpServer"), new IntegTestLocalhostServerListener());
    server.start(new InetSocketAddress(8080));
    BufferPool pool2 = new BufferCreationPool();
    DataListener listener = new ClientDataListener(pool2, recorder);
    Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
    TCPChannel channel = createClientChannel(pool2, executor2);
    //TCPChannel channel = createNettyChannel();
    recorder.start();
    CompletableFuture<Channel> connect = channel.connect(new InetSocketAddress(8080), listener);
    connect.thenAccept(p -> runWriting(channel));
    synchronized (this) {
        this.wait();
    }
}
Also used : ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) InetSocketAddress(java.net.InetSocketAddress) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) AsyncServer(org.webpieces.asyncserver.api.AsyncServer) Channel(org.webpieces.nio.api.channels.Channel) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) Executor(java.util.concurrent.Executor) BufferPool(org.webpieces.data.api.BufferPool) DataListener(org.webpieces.nio.api.handlers.DataListener)

Example 3 with BufferPool

use of org.webpieces.data.api.BufferPool in project webpieces by deanhiller.

the class IntegTestClientToEchoServer method testSoTimeoutOnSocket.

public void testSoTimeoutOnSocket() throws InterruptedException {
    runEchoServer();
    BufferPool pool2 = new BufferCreationPool();
    DataListener listener = new ClientDataListener(pool2, recorder);
    Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
    TCPChannel channel = createClientChannel(pool2, executor2);
    //TCPChannel channel = createNettyChannel();
    recorder.start();
    CompletableFuture<Channel> connect = channel.connect(new InetSocketAddress(4444), listener);
    connect.thenAccept(p -> runWriting(channel));
    synchronized (this) {
        this.wait();
    }
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) Executor(java.util.concurrent.Executor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) InetSocketAddress(java.net.InetSocketAddress) Channel(org.webpieces.nio.api.channels.Channel) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) DataListener(org.webpieces.nio.api.handlers.DataListener) BufferCreationPool(org.webpieces.data.api.BufferCreationPool)

Example 4 with BufferPool

use of org.webpieces.data.api.BufferPool in project webpieces by deanhiller.

the class IntegTestEchoClientToOurServer method testSoTimeoutOnSocket.

public void testSoTimeoutOnSocket() throws InterruptedException {
    EchoClient client = new EchoClient();
    Executor executor = Executors.newFixedThreadPool(10, new NamedThreadFactory("serverThread"));
    BufferPool pool = new BufferCreationPool();
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
    ChannelManager mgr = factory.createMultiThreadedChanMgr("server", pool, executor);
    AsyncServerManager serverMgr = AsyncServerMgrFactory.createAsyncServer(mgr);
    AsyncServer server = serverMgr.createTcpServer(new AsyncConfig("tcpServer"), new IntegTestLocalhostServerListener());
    server.start(new InetSocketAddress(8080));
    client.start(8080);
    synchronized (this) {
        this.wait();
    }
}
Also used : Executor(java.util.concurrent.Executor) BufferPool(org.webpieces.data.api.BufferPool) ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) InetSocketAddress(java.net.InetSocketAddress) AsyncServer(org.webpieces.asyncserver.api.AsyncServer) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory)

Example 5 with BufferPool

use of org.webpieces.data.api.BufferPool in project webpieces by deanhiller.

the class TestSSLEngine2 method setup.

@Before
public void setup() throws GeneralSecurityException, IOException {
    MockSSLEngineFactory sslEngineFactory = new MockSSLEngineFactory();
    BufferPool pool = new BufferCreationPool(false, 17000, 1000);
    SSLEngine client = sslEngineFactory.createEngineForSocket();
    SSLEngine svr = sslEngineFactory.createEngineForServerSocket();
    clientEngine = AsyncSSLFactory.create("client", client, pool, clientListener);
    svrEngine = AsyncSSLFactory.create("svr", svr, pool, svrListener);
    Assert.assertEquals(ConnectionState.NOT_STARTED, clientEngine.getConnectionState());
    Assert.assertEquals(ConnectionState.NOT_STARTED, svrEngine.getConnectionState());
    clientEngine.beginHandshake();
    Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
    ByteBuffer buffer = clientListener.getToSendToSocket().get(0);
    svrEngine.feedEncryptedPacket(buffer);
    Assert.assertEquals(ConnectionState.CONNECTING, svrEngine.getConnectionState());
    Runnable r = svrListener.getRunnable();
    r.run();
    Assert.assertEquals(ConnectionState.CONNECTING, svrEngine.getConnectionState());
    ByteBuffer buf = svrListener.getToSendToSocket().get(0);
    clientEngine.feedEncryptedPacket(buf);
    Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
    clientListener.getRunnable().run();
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) SSLEngine(javax.net.ssl.SSLEngine) ByteBuffer(java.nio.ByteBuffer) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) Before(org.junit.Before)

Aggregations

BufferCreationPool (org.webpieces.data.api.BufferCreationPool)7 BufferPool (org.webpieces.data.api.BufferPool)7 Executor (java.util.concurrent.Executor)5 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)5 ChannelManager (org.webpieces.nio.api.ChannelManager)4 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)4 InetSocketAddress (java.net.InetSocketAddress)3 SSLEngine (javax.net.ssl.SSLEngine)3 ByteBuffer (java.nio.ByteBuffer)2 Before (org.junit.Before)2 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)2 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)2 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)2 Channel (org.webpieces.nio.api.channels.Channel)2 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)2 DataListener (org.webpieces.nio.api.handlers.DataListener)2 HpackParser (com.webpieces.hpack.api.HpackParser)1 InjectionConfig (com.webpieces.http2engine.api.client.InjectionConfig)1 Http2Client (org.webpieces.http2client.api.Http2Client)1 Http2Socket (org.webpieces.http2client.api.Http2Socket)1