Index: com/sun/grizzly/ComplexSelectorHandler.java =================================================================== --- com/sun/grizzly/ComplexSelectorHandler.java (revision 3400) +++ com/sun/grizzly/ComplexSelectorHandler.java (working copy) @@ -54,5 +54,12 @@ * @param protocol Network protocol name * @return true if protocol is supported, false otherwise */ - public boolean supportsProtocol(Protocol protocol); + public boolean supportsProtocol(Protocol protocol); + + /** + * Return next aux. ReadController to process an accepted connection + * + * @return next aux. {@link ReadController} + */ + public ReadController nextController(); } Index: com/sun/grizzly/RoundRobinSelectorHandler.java =================================================================== --- com/sun/grizzly/RoundRobinSelectorHandler.java (revision 3400) +++ com/sun/grizzly/RoundRobinSelectorHandler.java (working copy) @@ -43,6 +43,7 @@ import java.io.IOException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.Set; /** @@ -61,8 +62,8 @@ implements ComplexSelectorHandler { private ReadController[] rrControllers; private int roundRobinCounter; - private Set customProtocols; - + private Set customProtocols = new CopyOnWriteArraySet(); + public RoundRobinSelectorHandler() {} public RoundRobinSelectorHandler(ReadController[] rrControllers) { @@ -82,27 +83,27 @@ ReadController auxController = nextController(); SelectorHandler protocolSelectorHandler = context.getSelectorHandler(); SelectableChannel channel = protocolSelectorHandler.acceptWithoutRegistration(key); - + if (channel != null) { protocolSelectorHandler.configureChannel(channel); - SelectorHandler relativeSelectorHandler = + SelectorHandler relativeSelectorHandler = auxController.getSelectorHandlerClone(protocolSelectorHandler); - + if (relativeSelectorHandler == null) { // Clone was not found - take correspondent protocol SelectorHandler - relativeSelectorHandler = + relativeSelectorHandler = auxController.getSelectorHandler(protocolSelectorHandler.protocol()); if (relativeSelectorHandler == null) { throw new IOException("Can not get correct SelectorHandler"); } } - + auxController.addChannel(channel, relativeSelectorHandler); } return false; } - + /** * Add custom protocol support * @param customProtocol custom {@link Controller.Protocol} @@ -110,7 +111,7 @@ public void addProtocolSupport(Protocol customProtocol) { customProtocols.add(customProtocol); } - + /** * {@inheritDoc} */ @@ -118,12 +119,17 @@ return protocol == Protocol.TCP || protocol == Protocol.TLS || customProtocols.contains(protocol); } - + /** - * Return next aux. ReadController to process an accepted connection - * @return{@link ReadController} + * {@inheritDoc} */ - private ReadController nextController() { + public ReadController nextController() { return rrControllers[((roundRobinCounter++) & 0x7fffffff) % rrControllers.length]; } + + @Override + public void shutdown() { + super.shutdown(); + customProtocols.clear(); + } } Index: com/sun/grizzly/UDPConnectorHandler.java =================================================================== --- com/sun/grizzly/UDPConnectorHandler.java (revision 3400) +++ com/sun/grizzly/UDPConnectorHandler.java (working copy) @@ -118,12 +118,24 @@ if (controller == null){ throw new IllegalStateException("Controller cannot be null"); } - - connect(remoteAddress,localAddress,callbackHandler, - (UDPSelectorHandler)controller.getSelectorHandler(protocol())); + + SelectorHandler selectorHandler = controller.getSelectorHandler( protocol() ); + if( controller.getReadThreadsCount() > 0 ) { + ReadController auxController = controller.multiReadThreadSelectorHandler.nextController(); + SelectorHandler relativeSelectorHandler = auxController.getSelectorHandlerClone( selectorHandler ); + if( relativeSelectorHandler == null ) { + // Clone was not found - take correspondent protocol SelectorHandler + relativeSelectorHandler = auxController.getSelectorHandler( selectorHandler.protocol() ); + if( relativeSelectorHandler == null ) + throw new IOException( "Can not get correct SelectorHandler" ); + } + selectorHandler = relativeSelectorHandler; + } + + connect(remoteAddress, localAddress, callbackHandler, (UDPSelectorHandler)selectorHandler); } - - + + /** * Connect to hostname:port. When an aysnchronous event happens (e.g * OP_READ or OP_WRITE), the {@link Controller} will invoke @@ -142,7 +154,8 @@ connect(remoteAddress,null,callbackHandler,selectorHandler); } - + + /** * Connect to hostname:port. When an aysnchronous event happens (e.g * OP_READ or OP_WRITE), the {@link Controller} will invoke