activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r383831 - /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
Date Tue, 07 Mar 2006 09:47:28 GMT
Author: jstrachan
Date: Tue Mar  7 01:47:25 2006
New Revision: 383831

URL: http://svn.apache.org/viewcvs?rev=383831&view=rev
Log:
allow a connectionTimeout to be specified on a socket for AMQ-607

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java?rev=383831&r1=383830&r2=383831&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
Tue Mar  7 01:47:25 2006
@@ -46,6 +46,7 @@
 public class TcpTransport extends TransportThreadSupport implements Transport, Service, Runnable
{
     private static final Log log = LogFactory.getLog(TcpTransport.class);
 
+    private int connectionTimeout = -1;
     private int soTimeout = 10000;
     private int socketBufferSize = 64 * 1024;
     private Socket socket;
@@ -57,6 +58,7 @@
     private int minmumWireFormatVersion;
     private long maxInactivityDuration = 0; //30000;
     private InetSocketAddress socketAddress;
+
     
     /**
      * Construct basic helpers
@@ -215,17 +217,20 @@
         this.maxInactivityDuration = maxInactivityDuration;
     }
 
+    public int getConnectionTimeout() {
+        return connectionTimeout;
+    }
+
+    /**
+     * Sets the timeout used to connect to the socket
+     */
+    public void setConnectionTimeout(int connectionTimeout) {
+        this.connectionTimeout = connectionTimeout;
+    }
+    
 
     // Implementation methods
     // -------------------------------------------------------------------------
-    protected void doStart() throws Exception {
-        initialiseSocket(socket);
-        if (socketAddress != null) {
-            socket.connect(socketAddress);
-        }
-        initializeStreams();
-        super.doStart();
-    }
 
     /**
      * Factory method to create a new socket
@@ -291,11 +296,18 @@
         sock.setSoTimeout(soTimeout);
     }
 
-    protected void initializeStreams() throws IOException {
-        TcpBufferedInputStream buffIn = new TcpBufferedInputStream(socket.getInputStream(),
4096);
-        this.dataIn = new DataInputStream(buffIn);
-        TcpBufferedOutputStream buffOut = new TcpBufferedOutputStream(socket.getOutputStream(),
8192);
-        this.dataOut = new DataOutputStream(buffOut);
+    protected void doStart() throws Exception {
+        initialiseSocket(socket);
+        if (socketAddress != null) {
+            if (connectionTimeout >= 0) {
+                socket.connect(socketAddress, connectionTimeout);
+            }
+            else {
+                socket.connect(socketAddress);
+            }
+        }
+        initializeStreams();
+        super.doStart();
     }
 
     protected void doStop(ServiceStopper stopper) throws Exception {
@@ -303,6 +315,13 @@
         if (socket != null) {
             socket.close();
         }
+    }
+
+    protected void initializeStreams() throws IOException {
+        TcpBufferedInputStream buffIn = new TcpBufferedInputStream(socket.getInputStream(),
4096);
+        this.dataIn = new DataInputStream(buffIn);
+        TcpBufferedOutputStream buffOut = new TcpBufferedOutputStream(socket.getOutputStream(),
8192);
+        this.dataOut = new DataOutputStream(buffOut);
     }
 
     protected void closeStreams() throws IOException {



Mime
View raw message