Search in sources :

Example 1 with TwoPools

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

the class TestConnecting method setup.

@Before
public void setup() {
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(mockJdk, Metrics.globalRegistry);
    DirectExecutor exec = new DirectExecutor();
    mgr = factory.createMultiThreadedChanMgr("test'n", new TwoPools("pl", new SimpleMeterRegistry()), new BackpressureConfig(), exec);
}
Also used : TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) DirectExecutor(org.webpieces.util.threading.DirectExecutor) Before(org.junit.Before)

Example 2 with TwoPools

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

the class TestSslCloseClient method createClientChannel.

public static TCPChannel createClientChannel(String name, MockJdk mockJdk) throws GeneralSecurityException, IOException {
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(mockJdk, Metrics.globalRegistry);
    BufferPool pool = new TwoPools("pClient", new SimpleMeterRegistry());
    ChannelManager chanMgr = factory.createMultiThreadedChanMgr(name + "Mgr", pool, new BackpressureConfig(), new DirectExecutor());
    MockSSLEngineFactory sslFactory = new MockSSLEngineFactory();
    SSLEngine clientSsl = sslFactory.createEngineForSocket();
    TCPChannel channel1 = chanMgr.createTCPChannel("client", clientSsl);
    return channel1;
}
Also used : BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) BufferPool(org.webpieces.data.api.BufferPool) ChannelManager(org.webpieces.nio.api.ChannelManager) TwoPools(org.webpieces.data.api.TwoPools) SSLEngine(javax.net.ssl.SSLEngine) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) DirectExecutor(org.webpieces.util.threading.DirectExecutor) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory)

Example 3 with TwoPools

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

the class Http2ClientFactory method createHttpClient.

public static Http2Client createHttpClient(Http2ClientConfig config, MeterRegistry metrics) {
    Executor executor = Executors.newFixedThreadPool(config.getNumThreads(), new NamedThreadFactory("httpclient"));
    MetricsCreator.monitor(metrics, executor, config.getId());
    TwoPools pool = new TwoPools(config.getId() + ".bufferpool", metrics);
    HpackParser hpackParser = HpackParserFactory.createParser(pool, false);
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(metrics);
    ChannelManager mgr = factory.createMultiThreadedChanMgr("httpClientChanMgr", pool, config.getBackpressureConfig(), executor);
    InjectionConfig injConfig = new InjectionConfig(hpackParser, new TimeImpl(), config.getHttp2Config());
    return createHttpClient(config.getHttp2Config().getId(), mgr, injConfig);
}
Also used : HpackParser(com.webpieces.hpack.api.HpackParser) Executor(java.util.concurrent.Executor) ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) TwoPools(org.webpieces.data.api.TwoPools) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) TimeImpl(org.webpieces.util.time.TimeImpl)

Example 4 with TwoPools

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

the class ServerFactory method createTestServer.

static int createTestServer(boolean alwaysHttp2, Long maxConcurrentStreams) {
    TwoPools pool = new TwoPools("pl", new SimpleMeterRegistry());
    ScheduledExecutorService timer = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("webpieces-timer"));
    FrontendMgrConfig config = new FrontendMgrConfig();
    HttpFrontendManager frontEndMgr = HttpFrontendFactory.createFrontEnd("frontEnd", timer, pool, config, Metrics.globalRegistry);
    HttpSvrConfig svrConfig = new HttpSvrConfig("id2");
    HttpServer server = frontEndMgr.createHttpServer(svrConfig, new OurListener());
    XFuture<Void> fut = server.start();
    try {
        fut.get(2, TimeUnit.SECONDS);
    } catch (ExecutionException | InterruptedException | TimeoutException e) {
        throw SneakyThrow.sneak(e);
    }
    return server.getUnderlyingChannel().getLocalAddress().getPort();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HttpFrontendManager(org.webpieces.frontend2.api.HttpFrontendManager) TwoPools(org.webpieces.data.api.TwoPools) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) HttpSvrConfig(org.webpieces.frontend2.api.HttpSvrConfig) FrontendMgrConfig(org.webpieces.frontend2.api.FrontendMgrConfig) HttpServer(org.webpieces.frontend2.api.HttpServer) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with TwoPools

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

the class TestHttp11Backpressure method create4SplitPayloads.

private List<ByteBuffer> create4SplitPayloads() {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    req.addHeader(new Header(KnownHeaderName.TRANSFER_ENCODING, "chunked"));
    HttpChunk chunk = new HttpChunk();
    String bodyStr = "hi here and there";
    DataWrapper data = DATA_GEN.wrapByteArray(bodyStr.getBytes(StandardCharsets.UTF_8));
    chunk.setBody(data);
    HttpLastChunk lastChunk = new HttpLastChunk();
    HttpStatefulParser parser = HttpParserFactory.createStatefulParser("a", new SimpleMeterRegistry(), new TwoPools("pl", new SimpleMeterRegistry()));
    ByteBuffer buf1 = parser.marshalToByteBuffer(req);
    ByteBuffer buf2 = parser.marshalToByteBuffer(chunk);
    ByteBuffer buf3 = parser.marshalToByteBuffer(lastChunk);
    byte[] part1 = new byte[10];
    byte[] part2 = new byte[buf1.remaining()];
    buf1.get(part1);
    int toWrite = buf1.remaining();
    buf1.get(part2, 0, toWrite);
    buf2.get(part2, toWrite, part2.length - toWrite);
    byte[] part3 = new byte[buf2.remaining() + 2];
    int toWrite2 = buf2.remaining();
    buf2.get(part3, 0, toWrite2);
    buf3.get(part3, toWrite2, 2);
    byte[] part4 = new byte[buf3.remaining()];
    buf3.get(part4);
    List<ByteBuffer> buffers = new ArrayList<>();
    buffers.add(ByteBuffer.wrap(part1));
    buffers.add(ByteBuffer.wrap(part2));
    buffers.add(ByteBuffer.wrap(part3));
    buffers.add(ByteBuffer.wrap(part4));
    return buffers;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) DataWrapper(org.webpieces.data.api.DataWrapper) HttpLastChunk(org.webpieces.httpparser.api.dto.HttpLastChunk) Header(org.webpieces.httpparser.api.common.Header) HttpStatefulParser(org.webpieces.httpparser.api.HttpStatefulParser) HttpChunk(org.webpieces.httpparser.api.dto.HttpChunk)

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