dev@grizzly.java.net

Re: refactring SelectionKeyHandler related code

From: Harsha Godugu <Harsha.Godugu_at_Sun.COM>
Date: Tue, 28 Aug 2007 08:01:00 -0700

Aha... Alexey. Your proposal looks good to me too. It makes more sense more now.
SelectionKeyHandler is more close to SelectorHandler than the controller in right abstraction.
Isn't it?

thanks..

----- Original Message -----
From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Tuesday, August 28, 2007 5:58 am
Subject: refactring SelectionKeyHandler related code
To: dev_at_grizzly.dev.java.net


> Hello.
>
> Here is update I propose in order to move SelectionKeyHandler from
> Controller and associate it with SelectorHandler.
> For a while old methods are marked deprecated, but once we will have a
>
> chance - we need to remove them.
>
> If you have any comments - welcome :)
>
> WBR,
> Alexey.
>
> Index:
> UDPSelectorHandler.java===================================================================---
> UDPSelectorHandler.java (revision 432)+++
> UDPSelectorHandler.java (working copy)@@ -31,6 +31,7 @@ import
> java.net.SocketAddress; import java.net.SocketException; import
> java.nio.channels.DatagramChannel;+import
> java.nio.channels.SelectableChannel; import
> java.nio.channels.SelectionKey; import java.nio.channels.Selector;
> import java.util.Iterator;@@ -249,6 +250,14 @@ throw new
> IllegalStateException(NOT_SUPPORTED); } + public void
> closeChannel(SelectableChannel channel) {+ try{+
> channel.close();+ } catch (IOException ex){+ ; //
> LOG ME+ }+ }+ //---------------
> ConnectorInstanceHandler -----------------------------
> @Override protected Callable<ConnectorHandler>
> getConnectorInstanceHandlerDelegate() {Index:
> DefaultSelectionKeyHandler.java===================================================================---
> DefaultSelectionKeyHandler.java (revision 434)+++
> DefaultSelectionKeyHandler.java (working copy)@@ -66,11 +66,26 @@
> */ protected long timeout = 30 * 1000L; + /**+ *
> Associated <code>SelectorHandler</code>+ */+ private
> SelectorHandler selectorHandler; public
> DefaultSelectionKeyHandler() { } + public
> DefaultSelectionKeyHandler(SelectorHandler selectorHandler) {+
> this.selectorHandler = selectorHandler;+ }+ /**+ * Set
> associated <code>SelectorHandler</code>+ */+ public void
> setSelectorHandler(SelectorHandler selectorHandler) {+
> this.selectorHandler = selectorHandler;+ } + + /** *
> {_at_inheritDoc} */ public void process(SelectionKey key) {@@
> -206,7 +221,11 @@ return; } -
> closeChannel(key.channel());+ if (selectorHandler != null)
> {+ selectorHandler.closeChannel(key.channel());+ }
> else {+ closeChannel(key.channel());+ }
> key.attach(null); key.cancel();@@ -238,7 +257,6
> @@ this.timeout = timeout; } - protected void
> closeChannel(SelectableChannel channel) { if (channel
> instanceof SocketChannel) { Socket socket =
> ((SocketChannel) channel).socket();@@ -267,5 +285,5 @@ } catch
> (IOException ex){ ; // LOG ME }- }+ }
> }Index:
> SelectorHandler.java===================================================================---
> SelectorHandler.java (revision 432)+++ SelectorHandler.java (working
> copy)@@ -228,4 +228,9 @@ * Return the
> <code>ProtocolChainInstanceHandler</code> */ public
> ProtocolChainInstanceHandler getProtocolChainInstanceHandler();+
> + /**+ * Closes <code>SelectableChannel</code>+ */+
> public void closeChannel(SelectableChannel channel); }Index:
> TCPSelectorHandler.java===================================================================---
> TCPSelectorHandler.java (revision 443)+++
> TCPSelectorHandler.java (working copy)@@ -804,7 +804,37 @@
> return instanceHandler; } - + /**+ *
> {_at_inheritDoc}+ */+ public void closeChannel(SelectableChannel
> channel) {+ Socket socket = ((SocketChannel)
> channel).socket();+ + try {+ if
> (!socket.isInputShutdown()) socket.shutdownInput();+ } catch
> (IOException ex){+ ;+ }+ + try
> {+ if (!socket.isOutputShutdown())
> socket.shutdownOutput();+ } catch (IOException ex){+
> ;+ }+ + try{+
> socket.close();+ } catch (IOException ex){+
> ;+ }+ + try{+ channel.close();+
> } catch (IOException ex){+ ; // LOG ME+ }+ }+
> //--------------- ConnectorInstanceHandler
> ----------------------------- /** * Return
> <Callable>factory<Callable> object, which knows how
>
> Index:
> main/java/com/sun/grizzly/http/SelectorThread.java===================================================================---
> main/java/com/sun/grizzly/http/SelectorThread.java (revision 432)+++
> main/java/com/sun/grizzly/http/SelectorThread.java (working copy)@@
> -47,7 +47,6 @@ import java.net.Socket; import
> java.net.SocketException; import java.util.Iterator;-import
> java.util.Set; import java.util.logging.Logger; import
> java.util.logging.Level; import
> java.util.concurrent.ConcurrentLinkedQueue;@@ -617,7 +616,7 @@
> controller.setSelectorHandler(selectorHandler);
> DefaultSelectionKeyHandler keyHandler = - new
> DefaultSelectionKeyHandler(){+ new
> DefaultSelectionKeyHandler(selectorHandler){ public void
> expire(Iterator<SelectionKey> keys){
> super.expire(keys); if (isMonitoringEnabled()) {@@
> -634,7 +633,7 @@ };
> keyHandler.setLogger(logger);
> keyHandler.setTimeout(keepAliveTimeoutInSeconds * 1000);-
> controller.setSelectionKeyHandler(keyHandler);+
> selectorHandler.setSelectionKeyHandler(keyHandler); final
> DefaultProtocolChain protocolChain = new
> DefaultProtocolChain(){ public void execute(Context ctx)
> throws Exception {
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net