tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r385662 - /tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/tcp/bio/BioSender.java
Date Mon, 13 Mar 2006 21:40:57 GMT
Author: fhanik
Date: Mon Mar 13 13:40:56 2006
New Revision: 385662

URL: http://svn.apache.org/viewcvs?rev=385662&view=rev
Log:
Fixed socket connection logic, too many methods doing the same thing, also, no timeout was
set for connection timeout

Modified:
    tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/tcp/bio/BioSender.java

Modified: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/tcp/bio/BioSender.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/tcp/bio/BioSender.java?rev=385662&r1=385661&r2=385662&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/tcp/bio/BioSender.java
(original)
+++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/tcp/bio/BioSender.java
Mon Mar 13 13:40:56 2006
@@ -28,6 +28,7 @@
 import org.apache.catalina.tribes.tcp.DataSender;
 import org.apache.catalina.tribes.tcp.SenderState;
 import org.apache.catalina.util.StringManager;
+import java.net.InetSocketAddress;
 
 /**
  * Send cluster messages with only one socket. Ack and keep Alive Handling is
@@ -73,7 +74,7 @@
     /**
      * is Socket really connected
      */
-    private boolean isSocketConnected = false;
+    private boolean connected = false;
 
     /**
      * sender is in suspect state (last transfer failed)
@@ -187,7 +188,7 @@
     }
 
     public boolean isConnected() {
-        return isSocketConnected;
+        return connected;
     }
 
     public boolean isSuspect() {
@@ -312,12 +313,12 @@
      * @see IDataSender#disconnect()
      */
     public synchronized void disconnect() {
-            boolean connect = isConnected() ;
-            closeSocket();
-            if(connect) {
-                if (log.isDebugEnabled())
-                    log.debug(sm.getString("IDataSender.disconnect", address.getHostAddress(),new
Integer(port),new Long(0)));
-            }
+        boolean connect = isConnected();
+        closeSocket();
+        if (connect) {
+            if (log.isDebugEnabled())
+                log.debug(sm.getString("IDataSender.disconnect", address.getHostAddress(),
new Integer(port), new Long(0)));
+        }
         
     }
 
@@ -370,16 +371,19 @@
      * is socket open return directly
      */
     protected synchronized void openSocket() throws IOException {
-       if(isConnected())
-           return ;
+       if(isConnected()) return ;
        try {
-            createSocket();
-            if (getWaitForAck()) socket.setSoTimeout((int) timeout);
-            isSocketConnected = true;
-            this.keepAliveCount = 0;
-            this.keepAliveConnectTime = System.currentTimeMillis();
-            if (log.isDebugEnabled())
-                log.debug(sm.getString("IDataSender.openSocket", address.getHostAddress(),
new Integer(port),new Long(0)));
+           socket = new Socket();
+           InetSocketAddress sockaddr = new InetSocketAddress(getAddress(), getPort());
+           socket.connect(sockaddr,(int)timeout);
+           socket.setSendBufferSize(getTxBufSize());
+           socket.setReceiveBufferSize(getRxBufSize());
+           socket.setSoTimeout( (int) timeout);
+           connected = true;
+           this.keepAliveCount = 0;
+           this.keepAliveConnectTime = System.currentTimeMillis();
+           if (log.isDebugEnabled())
+               log.debug(sm.getString("IDataSender.openSocket", address.getHostAddress(),
new Integer(port), new Long(0)));
       } catch (IOException ex1) {
           getSenderState().setSuspect();
           if (log.isDebugEnabled())
@@ -390,17 +394,6 @@
      }
 
     /**
-     * @throws IOException
-     * @throws SocketException
-     */
-    protected synchronized void createSocket() throws IOException, SocketException {
-        socket = new Socket(getAddress(), getPort());
-        socket.setSendBufferSize(getTxBufSize());
-        socket.setReceiveBufferSize(getRxBufSize());
-        socket.setSoTimeout((int)timeout);
-    }
-
-    /**
      * close socket
      * 
      * @see DataSender#disconnect()
@@ -417,7 +410,7 @@
                 }
             }
             this.keepAliveCount = 0;
-            isSocketConnected = false;
+            connected = false;
             if (log.isDebugEnabled())
                 log.debug(sm.getString("IDataSender.closeSocket",address.getHostAddress(),
new Integer(port),new Long(0)));
        }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message