OrderedMemoryAwareThreadPoolExecutor with UDP

Cygan cygan80 at hotmail.com
Mon Jul 13 22:42:30 EDT 2009


hi, i'm trying to get OrderedMemoryAwareThreadPoolExecutor to work with UDP,
since UDP don't have channel on it, so i use session id to maintains the
events order instead of channel. Here's the code for my custom
ThreadPoolExecutor. Are my code going to work fine just like the default one
with TCP?


public class MyCustomThreadPoolExecutor extends
        MemoryAwareThreadPoolExecutor {

    private final ConcurrentMap<Integer, Executor> childExecutors =
        new ConcurrentIdentityWeakKeyHashMap<Integer, Executor>();

...
...
...

   private Executor getOrderedExecutor(ChannelEvent e) {
    	int sessionID = -1; 	
    	if(e instanceof UpstreamMessageEvent){
    		UpstreamMessageEvent k = (UpstreamMessageEvent)e;
        	ChannelBuffer msg = (ChannelBuffer)k.getMessage();
                sessionID = msg.readInt();
        	msg.readerIndex(0);
    	}
    	
        //Channel channel = e.getChannel();
        Executor executor = childExecutors.get(sessionID);
        if (executor == null) {

            executor = new ChildExecutor();
            Executor oldExecutor = childExecutors.putIfAbsent(sessionID,
executor);
            if (oldExecutor != null) {
                executor = oldExecutor;
            }
        }

        // Remove the entry when the channel closes.
        /*
        if (e instanceof ChannelStateEvent) {
            ChannelStateEvent se = (ChannelStateEvent) e;
            if (se.getState() == ChannelState.OPEN &&
                !channel.isOpen()) {
                childExecutors.remove(channel);
            }
        }
        */
        return executor;
    }
...
...
...
}
-- 
View this message in context: http://n2.nabble.com/OrderedMemoryAwareThreadPoolExecutor-with-UDP-tp3254023p3254023.html
Sent from the Netty User Group mailing list archive at Nabble.com.



More information about the netty-users mailing list