private final Set<Stoppable> executors = new HashSet<Stoppable>();
public AsyncConnectionAdapter(Connection<T> connection, DispatchFailureHandler<? super T> dispatchFailureHandler, ExecutorFactory executor, Protocol<T>... protocols) {
this.connection = connection;
StoppableExecutor outgoingExecutor = executor.create(String.format("%s send", connection));
executors.add(outgoingExecutor);
outgoing = new AsyncDispatch<T>(outgoingExecutor);
outgoing.dispatchTo(new FailureHandlingDispatch<T>(connection, dispatchFailureHandler));
StoppableExecutor dispatchExecutor = executor.create(String.format("%s dispatch", connection));
executors.add(dispatchExecutor);
stack = new ProtocolStack<T>(dispatchExecutor, dispatchFailureHandler, dispatchFailureHandler, protocols);
stack.getBottom().dispatchTo(outgoing);
StoppableExecutor incomingExecutor = executor.create(String.format("%s receive", connection));
executors.add(incomingExecutor);
incoming = new AsyncReceive<T>(incomingExecutor);
incoming.dispatchTo(stack.getBottom());
incoming.receiveFrom(new ConnectionReceive<T>(connection));
}