use of org.webpieces.data.api.TwoPools in project webpieces by deanhiller.
the class AsyncSSLEngine3Impl method firePlainPacketToListener.
private void firePlainPacketToListener(ByteBuffer cachedOutBuffer, int totalBytesToAck) {
cachedOutBuffer.flip();
metrics.recordPlainBytesToClient(cachedOutBuffer.remaining());
if (pool instanceof TwoPools) {
// (we don't want too many large buffers as that eats up memory very fast)
if (cachedOutBuffer.remaining() <= pool.getSuggestedBufferSize()) {
ByteBuffer largeSslBuffer = cachedOutBuffer;
cachedOutBuffer = pool.nextBuffer(largeSslBuffer.remaining());
cachedOutBuffer.put(largeSslBuffer);
cachedOutBuffer.flip();
pool.releaseBuffer(largeSslBuffer);
}
}
listener.packetUnencrypted(cachedOutBuffer).handle((v, t) -> {
if (t != null)
log.error("Exception in ssl listener", t);
// after the client consumes the packet(completes the future), ack the number of bytes corresponding
// to the packet we sent to the consumer. NOTE: We do NOT care about how many bytes we sent the
// consumer BUT only how many encrypted bytes there were to ack those bytes and release our nio library to
// keep processing. (in this way, the lower layer shuts off the peer from writing to us if your app gets slow)
decryptionTracker.ackBytes(totalBytesToAck);
return null;
});
}
use of org.webpieces.data.api.TwoPools in project webpieces by deanhiller.
the class TestSplitBackpressure 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> clientFuture = clientEngine.beginHandshake();
Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
BufferedFuture toSend = clientListener.getSingleHandshake();
assertFutureJustResolved(clientFuture, toSend);
List<ByteBuffer> split = split(toSend.engineToSocketData);
// TODO: feed in this packet as two and resolving 'both' resolves the future returned
XFuture<Void> svrFuture = svrEngine.feedEncryptedPacket(split.get(0));
Assert.assertEquals(ConnectionState.CONNECTING, svrEngine.getConnectionState());
XFuture<Void> svrFuture2 = svrEngine.feedEncryptedPacket(split.get(1));
Assert.assertEquals(ConnectionState.CONNECTING, svrEngine.getConnectionState());
BufferedFuture toSend2 = svrListener.getSingleHandshake();
Assert.assertFalse(svrFuture.isDone());
Assert.assertFalse(svrFuture2.isDone());
toSend2.future.complete(null);
svrFuture.get(2, TimeUnit.SECONDS);
svrFuture2.get(2, TimeUnit.SECONDS);
// TODO: feed 2 halves of this packet in and test resolution of future
List<ByteBuffer> split2 = split(toSend2.engineToSocketData);
XFuture<Void> clientFuture1 = clientEngine.feedEncryptedPacket(split2.get(0));
Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
XFuture<Void> clientFuture2 = clientEngine.feedEncryptedPacket(split2.get(1));
List<BufferedFuture> buffers = clientListener.getHandshake();
buffers.get(0).future.complete(null);
buffers.get(1).future.complete(null);
Assert.assertFalse(clientFuture1.isDone());
Assert.assertFalse(clientFuture2.isDone());
buffers.get(2).future.complete(null);
clientFuture1.get(2, TimeUnit.SECONDS);
clientFuture2.get(2, TimeUnit.SECONDS);
XFuture<Void> fut1 = svrEngine.feedEncryptedPacket(buffers.get(0).engineToSocketData);
fut1.get(2, TimeUnit.SECONDS);
XFuture<Void> fut2 = svrEngine.feedEncryptedPacket(buffers.get(1).engineToSocketData);
Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
fut2.get(2, TimeUnit.SECONDS);
XFuture<Void> fut3 = svrEngine.feedEncryptedPacket(buffers.get(2).engineToSocketData);
Assert.assertEquals(ConnectionState.CONNECTED, svrEngine.getConnectionState());
Assert.assertTrue(svrListener.connected);
List<BufferedFuture> toClientBuffers = svrListener.getHandshake();
toClientBuffers.get(0).future.complete(null);
assertFutureJustResolved(fut3, toClientBuffers.get(1));
XFuture<Void> cliFut = clientEngine.feedEncryptedPacket(toClientBuffers.get(0).engineToSocketData);
Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
cliFut.get(2, TimeUnit.SECONDS);
XFuture<Void> cliFut2 = clientEngine.feedEncryptedPacket(toClientBuffers.get(1).engineToSocketData);
Assert.assertEquals(ConnectionState.CONNECTED, clientEngine.getConnectionState());
Assert.assertTrue(clientListener.connected);
cliFut2.get(2, TimeUnit.SECONDS);
}
use of org.webpieces.data.api.TwoPools in project webpieces by deanhiller.
the class IntegSingleRequest method createHttpClient.
public static Http2Socket createHttpClient(String id, boolean isHttp, InetSocketAddress addr) {
BufferPool pool2 = new TwoPools("pl", new SimpleMeterRegistry());
HpackParser hpackParser = HpackParserFactory.createParser(pool2, false);
Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
ChannelManagerFactory factory = ChannelManagerFactory.createFactory(Metrics.globalRegistry);
ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, new BackpressureConfig(), 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(id, mgr, injConfig);
Http2Socket socket;
if (isHttp) {
socket = client.createHttpSocket(new SocketListener());
} else {
socket = client.createHttpsSocket(engine, new SocketListener());
}
return socket;
}
use of org.webpieces.data.api.TwoPools in project webpieces by deanhiller.
the class TestHttp1Backpressure method create3BuffersWithTwoMessags.
private List<ByteBuffer> create3BuffersWithTwoMessags(Http2Response response1, HttpData response2) {
HttpStatefulParser parser = HttpParserFactory.createStatefulParser("a", new SimpleMeterRegistry(), new TwoPools("pl", new SimpleMeterRegistry()));
HttpResponse resp1 = Http2ToHttp11.translateResponse(response1);
ByteBuffer buf1 = parser.marshalToByteBuffer(resp1);
ByteBuffer buf2 = parser.marshalToByteBuffer(response2);
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()];
buf2.get(part3);
List<ByteBuffer> buffers = new ArrayList<>();
buffers.add(ByteBuffer.wrap(part1));
buffers.add(ByteBuffer.wrap(part2));
buffers.add(ByteBuffer.wrap(part3));
return buffers;
}
use of org.webpieces.data.api.TwoPools in project webpieces by deanhiller.
the class TestHttp1Backpressure method setup.
@Before
public void setup() throws InterruptedException, ExecutionException, TimeoutException {
BufferPool pool = new TwoPools("pl", new SimpleMeterRegistry());
httpClient = Http2to11ClientFactory.createHttpClient("myClient3", mockChannelMgr, new SimpleMeterRegistry(), pool);
mockChannelMgr.addTCPChannelToReturn(mockChannel);
socket = httpClient.createHttpSocket(new Http2CloseListener());
mockChannel.setConnectFuture(XFuture.completedFuture(null));
XFuture<Void> future = socket.connect(new InetSocketAddress(8080));
future.get(2, TimeUnit.SECONDS);
}
Aggregations