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

org.webpieces.webserver.test.http11.DelayedProxy Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package org.webpieces.webserver.test.http11;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.concurrent.CompletableFuture;

import org.webpieces.httpclient11.impl.ChannelProxy;
import org.webpieces.nio.api.handlers.ConnectionListener;
import org.webpieces.nio.api.handlers.DataListener;
import org.webpieces.webserver.test.MockTcpChannel;

public class DelayedProxy implements ChannelProxy {

	private ConnectionListener listener;
	private MockTcpChannel channel;
	private DataListener toServerDataListener;

	public DelayedProxy(ConnectionListener listener, MockTcpChannel channel) {
		this.listener = listener;
		this.channel = channel;
	}

	@Override
	public CompletableFuture connect(InetSocketAddress addr, DataListener dataListener) {
		channel.setDataListener(dataListener);
		return listener.connected(channel, true).thenApply( d -> {
			toServerDataListener = d;
			return null;
		});
	}

	@Override
	public CompletableFuture write(ByteBuffer buffer) {
		return toServerDataListener.incomingData(channel, buffer);
	}

	@Override
	public CompletableFuture close() {
		toServerDataListener.farEndClosed(channel);
		return CompletableFuture.completedFuture(null);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy