package com.eactive.eai.adapter.socket2.protocol;

import com.eactive.eai.adapter.EAIException;
import com.eactive.eai.adapter.socket2.EAIConnectException;
import com.eactive.eai.adapter.socket2.common.SimpleFuture;
import com.eactive.eai.adapter.socket2.config.SocketAdapterContext;
import org.apache.mina.common.IoSession;

import java.util.Date;
import java.util.Map;

public interface ISocketAdapter {
	public static enum State {
		STARTING, STARTED, STOPPING, STOPPED;
	}

	public SocketAdapterContext getContext();
	
	/**
	 * basic operation
	 */
	public SimpleFuture start() throws Exception;
	public SimpleFuture stop() throws Exception;
	public SimpleFuture stopForcely() throws Exception;
	public void setTraceLevel(int traceLevel) throws Exception;

	/**
	 * 
s	 */
	public SessionPool getSessionPool();
	public Map getThreadMap();
	
	/**
	 * statistics
	 */
	public long getMessageSend();
	public long getMessageRecv();
	public void incMessageSend();
	public void incMessageRecv();
	
	public State getState();	
	public void setState(State state);
	
	public int getRecentErrorCount();
	public void addRecentError(String message);
	public void addRecentError(String message, Throwable t);
	public void addRecentErrorOnly(String message);
	public void addRecentErrorOnly(String message, Throwable t);
	public String[] getRecentErrors();
	
	public void addRecentLog(String message);
	public void addRecentSend(IoSession session, String message);
	public void addRecentRecv(IoSession session, String message);
	public String[] getRecentSendRecv();
	public void addRecentSendTrace(IoSession session, String message);
	public void addRecentRecvTrace(IoSession session, String message);
	
	public void clearStat() throws Exception;

    public void suspendRead();
    public void suspendWrite();
    public void resumeRead();
    public void resumeWrite();

	public void setAdapterStatus(boolean status);
	public Date getUptime();

	/**
	 * Client Socket Adapter Only
	 */
	public boolean connect() throws Exception;	
	public IoSession connectOne() throws EAIConnectException;
	public Object sendMessage(Object message) throws EAIException;
	public Object sendMessage(Object message,int responseTimeout) throws EAIException;
	public Object sendMessage(IoSession session, Object message) throws EAIException;
}
