package connection;
import handlers.AbstractContextualHandler;
import java.io.IOException;
import common.connection.AbstractCommunicationSet;
import common.connection.AbstractConnection;
import common.connection.ConnectionWriterAdapter;
import common.connection.ConnectionWriterInterface;
public abstract class AbstractContextualConnection extends AbstractConnection
{
protected AbstractContextualConnection(AbstractCommunicationSet source)
throws IOException
{
super(source);
}
public abstract AbstractContextualHandler getContextualHandler(int protocolId,
int opcode) throws IOException, ClassNotFoundException;
protected void processMessage(int protocolId, int opcode) throws IOException,
ClassNotFoundException
{
AbstractContextualHandler handler = getContextualHandler(protocolId, opcode);
new Thread(handler, handler.getClass().toString()).start();
}
public final void sendOverlapped(final int protocolId, final int opcode,
final ConnectionWriterInterface writer)
{
Thread thread = new Thread()
{
public void run()
{
send(protocolId, opcode, writer);
}
};
thread.start();
}
public final void sendOverlapped(int protocolId, int opcode)
{
sendOverlapped(protocolId, opcode, new ConnectionWriterAdapter());
}
}