Search in sources :

Example 1 with Stream

use of com.webpieces.http2engine.impl.shared.data.Stream in project webpieces by deanhiller.

the class Level5AStates method checkForClosedState.

/**
	 * Returns if calling this resulted in closing the stream and cleaning up state
	 */
private boolean checkForClosedState(Stream stream, Http2Msg cause, boolean keepDelayedState) {
    //If a stream ends up in closed state, for request type streams, we must release a permit on
    //max concurrent streams
    boolean isClosed = isInClosedState(stream);
    if (!isClosed)
        //do nothing
        return false;
    log.info(logId + "stream closed=" + stream.getStreamId());
    //		if(!keepDelayedState) {
    Stream removedStream = streamState.remove(stream, cause);
    if (removedStream == null)
        //someone else closed the stream. they beat us to it so just return
        return false;
    return true;
//		} else {
//			//streamState.addDelayedRemove(stream, afterResetExpireSeconds);
//			throw new UnsupportedOperationException("not supported");
//		}
}
Also used : Stream(com.webpieces.http2engine.impl.shared.data.Stream)

Example 2 with Stream

use of com.webpieces.http2engine.impl.shared.data.Stream in project webpieces by deanhiller.

the class Level5BResets method resetAllClientStreams.

private void resetAllClientStreams(ConnectionCancelled reset) {
    ConcurrentMap<Integer, Stream> streams = streamState.closeEngine();
    for (Stream stream : streams.values()) {
        ShutdownStream str = new ShutdownStream(stream.getStreamId(), reset);
        fireRstToClient(stream, str);
    }
}
Also used : ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Stream(com.webpieces.http2engine.impl.shared.data.Stream)

Example 3 with Stream

use of com.webpieces.http2engine.impl.shared.data.Stream in project webpieces by deanhiller.

the class Level5AStates method fireToStateMachine.

private CompletableFuture<Void> fireToStateMachine(Http2SendRecieve type, Stream stream, Http2Msg payload, boolean keepDelayedState) {
    Http2Event event = translate(type, payload);
    CompletableFuture<Void> future = stream.getLock().synchronizeD(() -> {
        fireToStatemachineImpl(stream, event);
        return checkForClosedState(stream, payload, keepDelayedState);
    }).thenApply(isReleased -> {
        release(isReleased, stream, payload);
        return null;
    });
    return future.handle((v, e) -> {
        if (e == null) {
            return CompletableFuture.completedFuture(v);
        } else {
            return translateException(stream, e);
        }
    }).thenCompose(Function.identity());
}
Also used : NoTransitionConnectionError(com.webpieces.http2engine.impl.shared.data.NoTransitionConnectionError) SENT_DATA_EOS(com.webpieces.http2engine.impl.shared.data.Http2Event.SENT_DATA_EOS) RECV_RST(com.webpieces.http2engine.impl.shared.data.Http2Event.RECV_RST) NoTransitionListener(org.webpieces.javasm.api.NoTransitionListener) RECV_DATA_EOS(com.webpieces.http2engine.impl.shared.data.Http2Event.RECV_DATA_EOS) CompletableFuture(java.util.concurrent.CompletableFuture) CancelReasonCode(com.webpieces.http2parser.api.dto.error.CancelReasonCode) NoTransitionStreamError(com.webpieces.http2engine.impl.shared.data.NoTransitionStreamError) Function(java.util.function.Function) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) RECV_HEADERS_EOS(com.webpieces.http2engine.impl.shared.data.Http2Event.RECV_HEADERS_EOS) Http2SendRecieve(com.webpieces.http2engine.impl.shared.data.Http2Event.Http2SendRecieve) StateMachineFactory(org.webpieces.javasm.api.StateMachineFactory) Http2Event(com.webpieces.http2engine.impl.shared.data.Http2Event) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) Http2Push(com.webpieces.hpack.api.dto.Http2Push) State(org.webpieces.javasm.api.State) StateMachine(org.webpieces.javasm.api.StateMachine) Stream(com.webpieces.http2engine.impl.shared.data.Stream) SENT_RST(com.webpieces.http2engine.impl.shared.data.Http2Event.SENT_RST) Memento(org.webpieces.javasm.api.Memento) StreamException(com.webpieces.http2parser.api.dto.error.StreamException) Logger(org.webpieces.util.logging.Logger) AsyncLock(com.webpieces.util.locking.AsyncLock) CancelReason(com.webpieces.http2parser.api.dto.CancelReason) PermitQueue(com.webpieces.util.locking.PermitQueue) SENT_HEADERS_EOS(com.webpieces.http2engine.impl.shared.data.Http2Event.SENT_HEADERS_EOS) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) LoggerFactory(org.webpieces.util.logging.LoggerFactory) Http2PayloadType(com.webpieces.http2engine.impl.shared.data.Http2PayloadType) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Event(com.webpieces.http2engine.impl.shared.data.Http2Event)

Example 4 with Stream

use of com.webpieces.http2engine.impl.shared.data.Stream in project webpieces by deanhiller.

the class Level5ClientStateMachine method sendResponse.

public CompletableFuture<Void> sendResponse(Http2Response frame) {
    Stream stream = streamState.getStream(frame, true);
    CompletableFuture<Void> future = fireToClient(stream, frame);
    return future;
}
Also used : Stream(com.webpieces.http2engine.impl.shared.data.Stream)

Example 5 with Stream

use of com.webpieces.http2engine.impl.shared.data.Stream in project webpieces by deanhiller.

the class Level6RemoteFlowControl method trySendPayload.

private void trySendPayload(DataTry data) {
    long length = data.getDataFrame().getTransmitFrameLength();
    Stream stream = data.getStream();
    boolean send;
    long min = Math.min(remoteWindowSize, stream.getRemoteWindowSize());
    long lengthToSend = Math.min(length, min);
    if (length != lengthToSend) {
        //must split DataFrame into two since WindowUpdateSize is not large enough
        List<DataTry> tuple = splitDataFrame(data, lengthToSend);
        //swap the right size to send
        data = tuple.get(0);
        dataQueue.add(0, tuple.get(1));
    }
    if (lengthToSend > 0) {
        stream.incrementRemoteWindow(-lengthToSend);
        remoteWindowSize -= lengthToSend;
        send = true;
    } else if (data.isWasQueuedBefore()) {
        //insert BACK at beginning of queue
        dataQueue.add(0, data);
        send = false;
    } else {
        //insert at end of queue
        dataQueue.add(data);
        send = false;
    }
    log.info("flow control.  send=" + send + " window=" + remoteWindowSize + " streamWindow=" + stream.getRemoteWindowSize());
    if (send) {
        DataTry finalTry = data;
        layer6NotifyListener.sendFrameToSocket(data.getDataFrame()).handle((v, t) -> processComplete(v, t, finalTry.getFuture()));
    }
}
Also used : Stream(com.webpieces.http2engine.impl.shared.data.Stream) DataTry(com.webpieces.http2engine.impl.DataTry)

Aggregations

Stream (com.webpieces.http2engine.impl.shared.data.Stream)7 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)2 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)1 Http2Push (com.webpieces.hpack.api.dto.Http2Push)1 DataTry (com.webpieces.http2engine.impl.DataTry)1 Http2Event (com.webpieces.http2engine.impl.shared.data.Http2Event)1 Http2SendRecieve (com.webpieces.http2engine.impl.shared.data.Http2Event.Http2SendRecieve)1 RECV_DATA_EOS (com.webpieces.http2engine.impl.shared.data.Http2Event.RECV_DATA_EOS)1 RECV_HEADERS_EOS (com.webpieces.http2engine.impl.shared.data.Http2Event.RECV_HEADERS_EOS)1 RECV_RST (com.webpieces.http2engine.impl.shared.data.Http2Event.RECV_RST)1 SENT_DATA_EOS (com.webpieces.http2engine.impl.shared.data.Http2Event.SENT_DATA_EOS)1 SENT_HEADERS_EOS (com.webpieces.http2engine.impl.shared.data.Http2Event.SENT_HEADERS_EOS)1 SENT_RST (com.webpieces.http2engine.impl.shared.data.Http2Event.SENT_RST)1 Http2PayloadType (com.webpieces.http2engine.impl.shared.data.Http2PayloadType)1 NoTransitionConnectionError (com.webpieces.http2engine.impl.shared.data.NoTransitionConnectionError)1 NoTransitionStreamError (com.webpieces.http2engine.impl.shared.data.NoTransitionStreamError)1 CancelReason (com.webpieces.http2parser.api.dto.CancelReason)1 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)1 RstStreamFrame (com.webpieces.http2parser.api.dto.RstStreamFrame)1 CancelReasonCode (com.webpieces.http2parser.api.dto.error.CancelReasonCode)1