Search in sources :

Example 1 with ChannelSession

use of org.webpieces.nio.api.channels.ChannelSession in project webpieces by deanhiller.

the class ProxyDataListener method lookupExistingOrCreateNew.

/** 
	 * We have two choices here.
	 * 1. implement equals and hashCode in ProxyTCPChannel to delegate to TCPChannel so as we
	 *    create new ones, they are equal if the Channel they wrap is equal
	 * 2. re-use the same proxy we created for this channel by sticking it in the channel session
	 *    which avoids creating new objects that need to be garbage collected every time data
	 *    comes in
	 *       
	 * @param channel
	 * @return
	 */
private TCPChannel lookupExistingOrCreateNew(Channel channel) {
    ChannelSession session = channel.getSession();
    //This is garbage collected when the TCPChannel and it's ChannelSession are garbage
    //collected...
    ProxyTCPChannel existingProxy = (ProxyTCPChannel) session.get(EXISTING_PROXY_CHANNEL);
    if (existingProxy == null) {
        existingProxy = new ProxyTCPChannel((TCPChannel) channel, connectedChannels);
        session.put(EXISTING_PROXY_CHANNEL, existingProxy);
    }
    return existingProxy;
}
Also used : ChannelSession(org.webpieces.nio.api.channels.ChannelSession) TCPChannel(org.webpieces.nio.api.channels.TCPChannel)

Aggregations

ChannelSession (org.webpieces.nio.api.channels.ChannelSession)1 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)1