Now, prepareToClose() (formerly unclose()) is exposed to BaseIoSession. It is used to reset the internal 'closed' status to 'not closed'. We exposed this method because we want to reuse the existing session object. As we discussed before, reusing the session instance can reduce the overhead of reconstructing the filter chain. (Do I remember correctly?) But all other attributes and properties should be cleared so they could be set by IoHandler implementation. We don't have any control over the attributes that might contain critical state information that might affect the behavior of an application. Actually we also don't have any control over the insertion and removal of filters in the middle of a connection, so it makes us very hard to reuse a session instance.
So, here's my idea:
1. Create IoConnectorSession interface which extends IoSession and provides 'ConnectFuture reconnect()'
2. Create an implementation of IoConnectorSession which wraps existing IoSession implementations and takes care of all reconnection process (i.e. calling IoConnector.connect() again and switching the wrapped session)
3. IoConnector.connect() wraps the original IoSession implementation (e.g. SocketSession) with the IoConnectorSession implementation.
I think this will minimize changes in our code and enables us to provide reconnection feature more easily for future transport implementations.
There's one problem though; how can we get the original session instance from IoConnectorSession instance if IoConnector.connect() returns a wrapped session? We need to find out a trick.