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

com.github.thorbenkuck.network.client.ClientContainer Maven / Gradle / Ivy

There is a newer version: 0.4.0
Show newest version
package com.github.thorbenkuck.network.client;

import com.github.thorbenkuck.network.RemoteMessage;
import com.github.thorbenkuck.network.connection.ConnectionContext;
import com.github.thorbenkuck.network.encoding.ObjectDecoder;
import com.github.thorbenkuck.network.encoding.ObjectEncoder;
import com.github.thorbenkuck.network.stream.DataStream;
import com.github.thorbenkuck.network.stream.EventStream;

import java.io.Closeable;
import java.io.IOException;
import java.util.function.Consumer;

public interface ClientContainer extends AutoCloseable {

	static ClientContainer open(String address, int port) throws IOException {
		return open(address, port, new BlockingTCPConnectionFactory());
	}

	static ClientContainer open(String address, int port, ClientConnectionFactory clientConnectionFactory) throws IOException {
		return new NativeClientContainer(address, port, clientConnectionFactory);
	}

	static Builder builder() {
		return new ClientBuilder();
	}

	String getTargetAddress();

	int getTargetPort();

	void truncate(ClientContainer clientContainer);

	void append(ClientContainer clientContainer);

	EventStream output();

	DataStream input();

	ObjectEncoder getObjectEncoder();

	void setObjectEncoder(ObjectEncoder objectEncoder);

	ObjectDecoder getObjectDecoder();

	void setObjectDecoder(ObjectDecoder objectDecoder);

	void sendRaw(byte[] data) throws IOException;

	void sendRaw(String message) throws IOException;

	void close() throws IOException;

	void closeSilently();

	void onDisconnect(Consumer connectionConsumer);

	void listen(String id);

	void listen();

	String getIdentifier();

	void setIdentifier(String id);

	ClientContainer createSub() throws IOException;

	ClientContainer createSub(Consumer postCreationConsumer) throws IOException;
}