All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.webpieces.frontend2.impl.Http2StreamImpl Maven / Gradle / Ivy

package org.webpieces.frontend2.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;

import org.webpieces.frontend2.api.FrontendSocket;
import org.webpieces.frontend2.api.ResponseStream;

import com.webpieces.http2.api.dto.highlevel.Http2Response;
import com.webpieces.http2.api.dto.lowlevel.CancelReason;
import com.webpieces.http2.api.dto.lowlevel.RstStreamFrame;
import com.webpieces.http2.api.dto.lowlevel.lib.Http2ErrorCode;
import com.webpieces.http2.api.streaming.PushStreamHandle;
import com.webpieces.http2.api.streaming.ResponseStreamHandle;
import com.webpieces.http2.api.streaming.StreamWriter;

public class Http2StreamImpl implements ResponseStream {

	private FrontendSocketImpl socket;
	private AtomicBoolean sentResponseHeaders = new AtomicBoolean(false);
	private ResponseStreamHandle responseHandler;
	private Map session = new HashMap();
	private int streamId;

	public Http2StreamImpl(FrontendSocketImpl socket, ResponseStreamHandle responseHandler, int streamId) {
		this.socket = socket;
		this.responseHandler = responseHandler;
		this.streamId = streamId;
	}

	@Override
	public CompletableFuture process(Http2Response resp) {
		sentResponseHeaders.set(true);
		return responseHandler.process(resp);
	}

	@Override
	public PushStreamHandle openPushStream() {
		PushStreamHandle pushStream = responseHandler.openPushStream();
		return new Http2PushStreamHandle( pushStream, sentResponseHeaders);
	}

	@Override
	public CompletableFuture cancel(CancelReason reason) {
		RstStreamFrame frame = new RstStreamFrame(streamId, Http2ErrorCode.CANCEL);
		return responseHandler.cancel(frame);
	}

	@Override
	public FrontendSocket getSocket() {
		return socket;
	}

	@Override
	public Map getSession() {
		return session;
	}

	@Override
	public String toString() {
		return "Http2Stream["+ socket + ", sId=" + streamId + "]";
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy