Search in sources :

Example 36 with TwoPools

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

the class TestHandshakeBackpressure method setup.

@Before
public void setup() throws GeneralSecurityException, IOException, InterruptedException, ExecutionException, TimeoutException {
    System.setProperty("jdk.tls.server.protocols", "TLSv1.2");
    System.setProperty("jdk.tls.client.protocols", "TLSv1.2");
    SSLMetrics metrics = new SSLMetrics("", new SimpleMeterRegistry());
    MockSSLEngineFactory sslEngineFactory = new MockSSLEngineFactory();
    BufferPool pool = new TwoPools("p1", new SimpleMeterRegistry());
    SSLEngine client = sslEngineFactory.createEngineForSocket();
    SSLEngine svr = sslEngineFactory.createEngineForServerSocket();
    clientEngine = AsyncSSLFactory.create("client", client, pool, clientListener, metrics);
    svrEngine = AsyncSSLFactory.create("svr", svr, pool, svrListener, metrics);
    Assert.assertEquals(ConnectionState.NOT_STARTED, clientEngine.getConnectionState());
    Assert.assertEquals(ConnectionState.NOT_STARTED, svrEngine.getConnectionState());
    XFuture<Void> cliFuture = clientEngine.beginHandshake();
    Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
    BufferedFuture toSend = clientListener.getSingleHandshake();
    assertFutureJustResolved(cliFuture, toSend);
    XFuture<Void> svrFuture = svrEngine.feedEncryptedPacket(toSend.engineToSocketData);
    Assert.assertEquals(ConnectionState.CONNECTING, svrEngine.getConnectionState());
    Assert.assertEquals(ConnectionState.CONNECTING, svrEngine.getConnectionState());
    BufferedFuture toSend2 = svrListener.getSingleHandshake();
    assertFutureJustResolved(svrFuture, toSend2);
    XFuture<Void> clientFuture = clientEngine.feedEncryptedPacket(toSend2.engineToSocketData);
    Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
    buffers = clientListener.getHandshake();
    buffers.get(0).future.complete(null);
    buffers.get(1).future.complete(null);
    assertFutureJustResolved(clientFuture, buffers.get(2));
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) TwoPools(org.webpieces.data.api.TwoPools) SSLEngine(javax.net.ssl.SSLEngine) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) BufferedFuture(org.webpieces.ssl.api.MockSslListener.BufferedFuture)

Example 37 with TwoPools

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

the class IntegGoogleHttps method createHttpClient.

public static HttpClient createHttpClient() {
    BufferPool pool2 = new TwoPools("pl", new SimpleMeterRegistry());
    Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(Metrics.globalRegistry);
    ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, new BackpressureConfig(), executor2);
    HttpParser parser = HttpParserFactory.createParser("a", new SimpleMeterRegistry(), pool2);
    HttpClient client = HttpClientFactory.createHttpClient("myClient", mgr, parser);
    return client;
}
Also used : BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) BufferPool(org.webpieces.data.api.BufferPool) Executor(java.util.concurrent.Executor) ChannelManager(org.webpieces.nio.api.ChannelManager) TwoPools(org.webpieces.data.api.TwoPools) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) HttpClient(org.webpieces.httpclient11.api.HttpClient) HttpParser(org.webpieces.httpparser.api.HttpParser) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory)

Example 38 with TwoPools

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

the class HttpClientFactory method createHttpClient.

public static HttpClient createHttpClient(String id, int numThreads, BackpressureConfig backPressureConfig, MeterRegistry metrics) {
    Executor executor = Executors.newFixedThreadPool(numThreads, new NamedThreadFactory("httpclient"));
    MetricsCreator.monitor(metrics, executor, id);
    TwoPools pool = new TwoPools(id + ".bufferpool", metrics);
    HttpParser parser = HttpParserFactory.createParser(id, metrics, pool);
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(metrics);
    ChannelManager mgr = factory.createMultiThreadedChanMgr("httpClientChanMgr", pool, backPressureConfig, executor);
    return createHttpClient(id, mgr, parser);
}
Also used : Executor(java.util.concurrent.Executor) ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) TwoPools(org.webpieces.data.api.TwoPools) HttpParser(org.webpieces.httpparser.api.HttpParser) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory)

Example 39 with TwoPools

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

the class TestSslCloseClient method createSslSvrParser.

public static SSLParser createSslSvrParser() throws GeneralSecurityException, IOException {
    MockSSLEngineFactory sslFactory = new MockSSLEngineFactory();
    BufferPool pool = new TwoPools("pSvr", new SimpleMeterRegistry());
    SSLEngine svrSsl = sslFactory.createEngineForServerSocket();
    SSLMetrics metrics = new SSLMetrics("", new SimpleMeterRegistry());
    return AsyncSSLFactory.create("svr", svrSsl, pool, metrics);
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) TwoPools(org.webpieces.data.api.TwoPools) SSLEngine(javax.net.ssl.SSLEngine) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SSLMetrics(org.webpieces.ssl.api.SSLMetrics)

Example 40 with TwoPools

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

the class TestSslOverLocalhost method createSvrChanMgr.

private ChannelManager createSvrChanMgr(String name) {
    ExecutorService executor = Executors.newFixedThreadPool(10, new NamedThreadFactory(name));
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(Metrics.globalRegistry);
    ChannelManager svrMgr = factory.createMultiThreadedChanMgr(name + "Mgr", new TwoPools("pl", new SimpleMeterRegistry()), new BackpressureConfig(), executor);
    return svrMgr;
}
Also used : NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

TwoPools (org.webpieces.data.api.TwoPools)43 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)39 Before (org.junit.Before)15 BufferPool (org.webpieces.data.api.BufferPool)15 ChannelManager (org.webpieces.nio.api.ChannelManager)12 InetSocketAddress (java.net.InetSocketAddress)11 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)11 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)10 Executor (java.util.concurrent.Executor)8 SSLEngine (javax.net.ssl.SSLEngine)8 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)8 DirectExecutor (org.webpieces.util.threading.DirectExecutor)8 ByteBuffer (java.nio.ByteBuffer)7 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)7 BackpressureConfig (org.webpieces.nio.api.BackpressureConfig)7 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)6 HttpParser (org.webpieces.httpparser.api.HttpParser)6 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)5 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)5 ArrayList (java.util.ArrayList)4