dev@grizzly.java.net

About XXXConnectorHandler's isConnected() API

From: Bongjae Chang <carryel_at_korea.com>
Date: Tue, 12 May 2009 11:13:56 +0900

Hi,

All ConnectorHandlers like TCPConnectorHandler, UDPConnectorHandler, SSLConnectorHandler and CacheableConnectorHandler have the same isConnected() method.

I think that it is better that ConnectorHandler interface has the isConnected() API and AbstractConnectorHandler has the isConnected member value and implements default isConnected() method.

What do you think?

I attached the diff and sources.

And here are diffs.

Index: com/sun/grizzly/TCPConnectorHandler.java
===================================================================
--- com/sun/grizzly/TCPConnectorHandler.java (revision 3172)
+++ com/sun/grizzly/TCPConnectorHandler.java (working copy)
@@ -116,12 +116,6 @@
     
     
     /**
- * Is the connection established.
- */
- private volatile boolean isConnected;
-
-
- /**
      * IsConnected Latch related
      */
     private CountDownLatch isConnectedLatch;
@@ -664,15 +658,6 @@
     
     
     /**
- * Is the underlying SocketChannel connected.
- * @return <tt>true</tt> if connected, otherwise <tt>false</tt>
- */
- public boolean isConnected(){
- return isConnected && underlyingChannel.isOpen();
- }
-
-
- /**
      * Return the tcpNoDelay value used by the underlying accepted Sockets.
      *
      * Also see setTcpNoDelay(boolean tcpNoDelay)
Index: com/sun/grizzly/ConnectorHandler.java
===================================================================
--- com/sun/grizzly/ConnectorHandler.java (revision 3172)
+++ com/sun/grizzly/ConnectorHandler.java (working copy)
@@ -231,4 +231,11 @@
      * @param callbackHandler handler
      */
     public void setCallbackHandler(P callbackHandler);
+
+ /**
+ * Is the underlying channel connected.
+ *
+ * @return <tt>true</tt> if connected, otherwise <tt>false</tt>
+ */
+ public boolean isConnected();
 }
Index: com/sun/grizzly/UDPConnectorHandler.java
===================================================================
--- com/sun/grizzly/UDPConnectorHandler.java (revision 3172)
+++ com/sun/grizzly/UDPConnectorHandler.java (working copy)
@@ -80,12 +80,6 @@
         implements AsyncQueueWritable, AsyncQueueReadable {
 
     /**
- * Is the connection established.
- */
- protected volatile boolean isConnected;
-
-
- /**
      * IsConnected Latch related
      */
     protected CountDownLatch isConnectedLatch;
@@ -590,13 +584,4 @@
     public Controller.Protocol protocol(){
         return Controller.Protocol.UDP;
     }
-
-
- /**
- * Is the underlying DatagramChannel connected.
- * @return true if connected, othewise false
- */
- public boolean isConnected(){
- return isConnected && underlyingChannel.isOpen();
- }
 }
Index: com/sun/grizzly/connectioncache/client/CacheableConnectorHandler.java
===================================================================
--- com/sun/grizzly/connectioncache/client/CacheableConnectorHandler.java (revision 3172)
+++ com/sun/grizzly/connectioncache/client/CacheableConnectorHandler.java (working copy)
@@ -186,7 +186,10 @@
         }
     }
 
-
+ public boolean isConnected() {
+ return underlyingConnectorHandler != null && underlyingConnectorHandler.isConnected();
+ }
+
     public ConnectorHandler getUnderlyingConnectorHandler() {
         return underlyingConnectorHandler;
     }
Index: com/sun/grizzly/SSLConnectorHandler.java
===================================================================
--- com/sun/grizzly/SSLConnectorHandler.java (revision 3172)
+++ com/sun/grizzly/SSLConnectorHandler.java (working copy)
@@ -143,11 +143,6 @@
     private ByteBuffer asyncHandshakeBuffer;
     
     /**
- * Is the connection established.
- */
- private volatile boolean isConnected;
-
- /**
      * Is the handshake phase completed
      */
     private volatile boolean isHandshakeDone;
@@ -756,14 +751,6 @@
      * Is the underlying SocketChannel connected.
      * @return <tt>true</tt> if connected, otherwise <tt>false</tt>
      */
- public boolean isConnected() {
- return isConnected && underlyingChannel.isOpen();
- }
-
- /**
- * Is the underlying SocketChannel connected.
- * @return <tt>true</tt> if connected, otherwise <tt>false</tt>
- */
     public boolean isHandshakeDone() {
         return isHandshakeDone && !isProcessingAsyncHandshake;
     }
Index: com/sun/grizzly/AbstractConnectorHandler.java
===================================================================
--- com/sun/grizzly/AbstractConnectorHandler.java (revision 3172)
+++ com/sun/grizzly/AbstractConnectorHandler.java (working copy)
@@ -76,6 +76,11 @@
      * The connection's SelectableChannel.
      */
     protected SelectableChannel underlyingChannel;
+
+ /**
+ * Is the connection established.
+ */
+ protected volatile boolean isConnected;
     
     /**
      * Get the <tt>ConnectorHandler</tt> {_at_link Protocol}.
@@ -157,4 +162,12 @@
     public void setCallbackHandler(K callbackHandler) {
         this.callbackHandler = callbackHandler;
     }
+
+ /**
+ * Is the underlying channel connected.
+ * @return <tt>true</tt> if connected, otherwise <tt>false</tt>
+ */
+ public boolean isConnected(){
+ return isConnected && underlyingChannel != null && underlyingChannel.isOpen();
+ }
 }

Thanks.

--
Bongjae Chang