use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class TestCMaxConcurrentSetting method sendTwoRequests.
private RequestsSent sendTwoRequests() {
Http2Request request1 = Requests.createRequest();
Http2Request request2 = Requests.createRequest();
MockStreamWriter writer1 = new MockStreamWriter();
MockStreamWriter writer2 = new MockStreamWriter();
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.completedFuture(writer1));
// do not set default incoming response as we want to delay the resolution of the future
MockResponseListener listener2 = new MockResponseListener();
StreamRef streamRef1 = httpSocket.openStream().process(request1, listener1);
XFuture<StreamWriter> future = streamRef1.getWriter();
StreamRef streamRef2 = httpSocket.openStream().process(request2, listener2);
XFuture<StreamWriter> future2 = streamRef2.getWriter();
RequestHolder r1 = new RequestHolder(request1, listener1, writer1, future);
RequestHolder r2 = new RequestHolder(request2, listener2, writer2, future2);
RequestsSent requests = new RequestsSent(r1, r2);
Http2Msg req = mockChannel.getFrameAndClear();
Assert.assertEquals(1, req.getStreamId());
Assert.assertEquals(request1, req);
Assert.assertTrue(future.isDone());
Assert.assertFalse(future2.isDone());
return requests;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class Level2ParsingAndRemoteSettings method parseImpl.
public XFuture<Void> parseImpl(DataWrapper newData) {
parsingState = lowLevelParser.unmarshal(parsingState, newData);
List<Http2Msg> parsedMessages = parsingState.getParsedFrames();
// All the below futures must be chained with previous ones in case previous ones are not
// done which will serialize it all to be in sequence
XFuture<Void> future = parsingState.getProcessFuture();
for (Http2Msg lowLevelFrame : parsedMessages) {
// VERY IMPORTANT: Writing the code like this would slam through calling process N times
// BUT it doesn't give the clients a chance to seet a flag between packets
// Mainly done for exceptions and streaming so you can log exc, set a boolean so you
// don't get 100 exceptions while something is happening like socket disconnect
// In these 2 lines of code, processCorrectly is CALLED N times RIGHT NOW
// The code below this only calls them right now IF AND ONLY IF the client returns
// a completed future each time!!!
// XFuture<Void> messageFuture = process(lowLevelFrame);
// allFutures = allFutures.thenCompose( f -> messageFuture);
future = future.thenCompose(f -> process(lowLevelFrame));
}
parsingState.setProcessFuturee(future);
return future;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class AbstractTest method sendRequestToServer.
protected Http2Request sendRequestToServer(MockResponseListener listener1) {
Http2Request request1 = Requests.createRequest();
httpSocket.openStream().process(request1, listener1);
Http2Msg req = mockChannel.getFrameAndClear();
Assert.assertEquals(request1, req);
return request1;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class Level7MarshalAndPing method sendPing.
// public XFuture<Void> sendControlFrameToClient(Http2Msg msg) {
// return finalLayer.sendControlFrameToClient(msg);
// }
public XFuture<Void> sendPing() {
PingFrame ping = new PingFrame();
ping.setOpaqueData(8L);
XFuture<Void> newFuture = new XFuture<>();
boolean wasSet = pingFutureRef.compareAndSet(null, newFuture);
if (!wasSet) {
throw new IllegalStateException(key + "You must wait until the first ping you sent is complete. 2nd ping=" + ping);
}
return sendFrameToSocket(ping).thenCompose(c -> newFuture);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class Http2ChannelCache method write.
@SuppressWarnings("unchecked")
@Override
public XFuture<Void> write(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);
}
Aggregations