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

io.zbus.transport.Client Maven / Gradle / Ivy

There is a newer version: 1.0.0-b1
Show newest version
package io.zbus.transport;
 
import java.io.Closeable;
import java.io.IOException;
  
/**
 * A TCP client, capable of 
 * 1) remote invocation of message: messaging pairing, message identification from request to response
 * 2) configuration of IO events(via IoAdaptor), such as connection creation/destroy/message received
 *    more API friendly way is using XXHandler such as ConnectedHandler
 * 3) heartbeat 
 * 
 * @author rushmore (洪磊明)
 *
 * @param  Request message type
 * @param  Response message type
 */
public interface Client extends Invoker, IoAdaptor, Closeable { 

	boolean hasConnected();
	void connectAsync() throws IOException; 
	void connectSync(long timeout) throws IOException, InterruptedException;
	void ensureConnectedAsync(); 
	
	void sendMessage(REQ req) throws IOException, InterruptedException;; 
	void onMessage(MessageHandler messageHandler);
	void onError(ErrorHandler errorHandler);
    void onConnected(ConnectedHandler connectedHandler);
    void onDisconnected(DisconnectedHandler disconnectedHandler);
    
     V attr(String key);
	 void attr(String key, V value);
    
    
	public static interface ConnectedHandler { 
		void onConnected() throws IOException;   
	}
	
	public static interface DisconnectedHandler { 
		void onDisconnected() throws IOException;   
	}
	
	public static interface ErrorHandler { 
		void onError(Throwable e, Session session) throws IOException;   
	}  
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy