use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class Level6RemoteFlowControl method sendDataToSocket.
public XFuture<Void> sendDataToSocket(Stream stream, DataFrame dataFrame) {
log.info("sending payload to socket=" + dataFrame);
XFuture<Void> future = new XFuture<>();
DataTry data = new DataTry(stream, dataFrame, future, false);
trySendPayload(data);
return future;
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class MockHttp2Channel method write.
@SuppressWarnings("unchecked")
@Override
public XFuture<Void> write(ByteBuffer b) {
if (!prefaceReceived) {
// copy and store preface
ByteBuffer prefaceBuffer = ByteBuffer.allocate(b.remaining());
prefaceBuffer.put(b);
prefaceReceived = true;
Preface preface = new Preface(prefaceBuffer);
List<Http2Msg> msgs = new ArrayList<>();
msgs.add(preface);
return (XFuture<Void>) super.calledMethod(Method.INCOMING_FRAME, msgs);
}
return processData(b);
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class MockHttp2Channel method processData.
@SuppressWarnings("unchecked")
private XFuture<Void> processData(ByteBuffer b) {
DataWrapper data = dataGen.wrapByteBuffer(b);
parser.unmarshal(unmarshalState, data);
List<Http2Msg> parsedFrames = unmarshalState.getParsedFrames();
return (XFuture<Void>) super.calledMethod(Method.INCOMING_FRAME, parsedFrames);
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class EScopedRouter method invokeRouter.
private RouterStreamRef invokeRouter(AbstractRouter router, RequestContext ctx, ProxyStreamHandle handler, boolean isCorsRequest) {
RouterStreamRef streamRef = invokeWithProtection(router, ctx, handler, isCorsRequest);
XFuture<StreamWriter> writer = streamRef.getWriter().handle((r, t) -> {
if (t == null)
return XFuture.completedFuture(r);
XFuture<StreamWriter> fut = new XFuture<>();
Throwable exc = convert(router.getMatchInfo(), t);
fut.completeExceptionally(exc);
return fut;
}).thenCompose(Function.identity());
return new RouterStreamRef("eScoped2", writer, streamRef);
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class TestHttp1Backpressure method testBasicBackpressureChunked.
@Test
public void testBasicBackpressureChunked() throws InterruptedException, ExecutionException, TimeoutException {
MockResponseListener listener = new MockResponseListener();
RequestStreamHandle handle = socket.openStream();
mockChannel.addWriteResponse(XFuture.completedFuture(null));
Http2Request request = Requests.createRequest();
StreamRef streamRef = handle.process(request, listener);
XFuture<StreamWriter> writer = streamRef.getWriter();
Assert.assertTrue(writer.isDone());
Assert.assertEquals(request, mockChannel.getLastWriteParam());
Http2Response response1 = Requests.createChunkedResponse(1);
HttpChunk response2 = Requests.createHttpChunk(250);
HttpLastChunk lastChunk = new HttpLastChunk();
List<ByteBuffer> buffers = create4BuffersWith3Messags(response1, response2, lastChunk);
DataListener dataListener = mockChannel.getConnectedListener();
XFuture<Void> fut1 = dataListener.incomingData(mockChannel, buffers.get(0));
// resolved since it never made it to the client.
Assert.assertTrue(fut1.isDone());
// this keeps bytes in-memory that is less than bufPool.getSuggestedSize. ie. < 5k
XFuture<StreamWriter> requestFuture = new XFuture<StreamWriter>();
listener.addProcessResponse(requestFuture);
XFuture<Void> fut2 = dataListener.incomingData(mockChannel, buffers.get(1));
// not resolved yet since client only has part of the data
Assert.assertFalse(fut2.isDone());
XFuture<Void> streamWriterFuture = new XFuture<Void>();
MockStreamWriter mockWriter = new MockStreamWriter();
mockWriter.addProcessResponse(streamWriterFuture);
// This releases the response BUT 'some' data was with response so can't ack yet
requestFuture.complete(mockWriter);
// not resolved yet since requestFuture AND streamWriterFutuer BOTH need to be resolved
Assert.assertFalse(fut2.isDone());
// This is BECAUSE 68 bytes resulted in TWO messages and both futures can ack the 68 bytes.
streamWriterFuture.complete(null);
// NOW it's resolved
fut2.get(2, TimeUnit.SECONDS);
// feed the rest of first chunk in and feed part of last chunk
XFuture<Void> firstChunkAck = new XFuture<Void>();
mockWriter.addProcessResponse(firstChunkAck);
XFuture<Void> fut3 = dataListener.incomingData(mockChannel, buffers.get(2));
Assert.assertFalse(fut3.isDone());
// ack the http chunk packet
firstChunkAck.complete(null);
fut3.get(2, TimeUnit.SECONDS);
XFuture<Void> lastChunkAck = new XFuture<Void>();
mockWriter.addProcessResponse(lastChunkAck);
XFuture<Void> fut4 = dataListener.incomingData(mockChannel, buffers.get(3));
Assert.assertFalse(fut4.isDone());
lastChunkAck.complete(null);
fut4.get(2, TimeUnit.SECONDS);
}
Aggregations