activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1082144 - in /activemq/activemq-apollo/trunk: apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/ apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/ apollo-transport/src/main/java/org/apache/activemq/apollo/tran...
Date Wed, 16 Mar 2011 13:34:16 GMT
Author: chirino
Date: Wed Mar 16 13:34:15 2011
New Revision: 1082144

URL: http://svn.apache.org/viewvc?rev=1082144&view=rev
Log:
Better startup logging of the bound tcp address.

Modified:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
    activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/SslTransportServer.java
    activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/TcpTransportServer.java
    activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/TransportServer.java
    activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/pipe/PipeTransportServer.java

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala?rev=1082144&r1=1082143&r2=1082144&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
Wed Mar 16 13:34:15 2011
@@ -164,7 +164,7 @@ class AcceptingConnector(val broker:Brok
       }
     }
     transport_server.start(^{
-      broker.console_log.info("Accepting connections at: "+config.bind)
+      broker.console_log.info("Accepting connections at: "+transport_server.getBoundAddress)
       on_completed.run
     })
   }

Modified: activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/SslTransportServer.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/SslTransportServer.java?rev=1082144&r1=1082143&r2=1082144&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/SslTransportServer.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/SslTransportServer.java
Wed Mar 16 13:34:15 2011
@@ -22,6 +22,7 @@ import javax.net.ssl.KeyManager;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
 import java.net.URI;
+import java.net.UnknownHostException;
 
 /**
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
@@ -34,7 +35,7 @@ public class SslTransportServer extends 
     protected String protocol = "TLS";
     protected SSLContext sslContext;
 
-    public SslTransportServer(URI location) {
+    public SslTransportServer(URI location) throws UnknownHostException {
         super(location);
     }
 

Modified: activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/TcpTransportServer.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/TcpTransportServer.java?rev=1082144&r1=1082143&r2=1082144&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/TcpTransportServer.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/TcpTransportServer.java
Wed Mar 16 13:34:15 2011
@@ -41,27 +41,31 @@ import java.util.Map;
 
 public class TcpTransportServer implements TransportServer {
 
+    private final String bindScheme;
+    private final InetSocketAddress bindAddress;
+
+    private int backlog = 100;
+    private Map<String, Object> transportOptions;
+
     private ServerSocketChannel channel;
     private TransportAcceptListener listener;
-    private URI bindURI;
-    private URI connectURI;
     private DispatchQueue dispatchQueue;
     private DispatchSource acceptSource;
-    private int backlog = 100;
-    private Map<String, Object> transportOptions;
 
-    public TcpTransportServer(URI location) {
-        this.bindURI = location;
+    public TcpTransportServer(URI location) throws UnknownHostException {
+        bindScheme = location.getScheme();
+        String host = location.getHost();
+        host = (host == null || host.length() == 0) ? "localhost" : host;
+        if (host.equals("localhost")) {
+            host = "0.0.0.0";
+        }
+        bindAddress = new InetSocketAddress(InetAddress.getByName(host), location.getPort());
     }
 
     public void setAcceptListener(TransportAcceptListener listener) {
         this.listener = listener;
     }
 
-    public String getConnectAddress() {
-        return connectURI.toString();
-    }
-
     public InetSocketAddress getSocketAddress() {
         return (InetSocketAddress) channel.socket().getLocalSocketAddress();
     }
@@ -86,36 +90,15 @@ public class TcpTransportServer implemen
         start(null);
     }
     public void start(Runnable onCompleted) throws Exception {
-        URI bind = bindURI;
 
-        String host = bind.getHost();
-        host = (host == null || host.length() == 0) ? "localhost" : host;
-        if (host.equals("localhost")) {
-            host = "0.0.0.0";
-        }
-
-        InetAddress addr = InetAddress.getByName(host);
         try {
             channel = ServerSocketChannel.open();
             channel.configureBlocking(false);
-            channel.socket().bind(new InetSocketAddress(addr, bind.getPort()), backlog);
+            channel.socket().bind(bindAddress, backlog);
         } catch (IOException e) {
-            throw IOExceptionSupport.create("Failed to bind to server socket: " + bind +
" due to: " + e, e);
+            throw IOExceptionSupport.create("Failed to bind to server socket: " + bindAddress
+ " due to: " + e, e);
         }
 
-        try {
-            connectURI = connectURI(resolveHostName(channel.socket(), addr));
-        } catch (URISyntaxException e) {
-            // it could be that the host name contains invalid characters such
-            // as _ on unix platforms
-            // so lets try use the IP address instead
-            try {
-                connectURI = connectURI(addr.getHostAddress());
-            } catch (URISyntaxException e2) {
-                throw IOExceptionSupport.create(e2);
-            }
-        }
-        
         acceptSource = Dispatch.createSource(channel, SelectionKey.OP_ACCEPT, dispatchQueue);
         acceptSource.setEventHandler(new Runnable() {
             public void run() {
@@ -144,21 +127,26 @@ public class TcpTransportServer implemen
         }
     }
 
-    private URI connectURI(String hostname) throws URISyntaxException {
-        return new URI(bindURI.getScheme(), bindURI.getUserInfo(), hostname, channel.socket().getLocalPort(),
bindURI.getPath(), bindURI.getQuery(), bindURI.getFragment());
+    public String getBoundAddress() {
+        return bindScheme+"://"+bindAddress.getAddress()+":"+channel.socket().getLocalPort();
     }
 
-    protected String resolveHostName(ServerSocket socket, InetAddress bindAddress) throws
UnknownHostException {
-        String result = null;
-        if (socket.isBound()) {
-            if (socket.getInetAddress().isAnyLocalAddress()) {
-                // make it more human readable and useful, an alternative to 0.0.0.0
-                result = InetAddress.getLocalHost().getHostName();
-            } else {
-                result = socket.getInetAddress().getCanonicalHostName();
+    public String getConnectAddress() {
+        return bindScheme+"://"+resolveHostName()+":"+channel.socket().getLocalPort();
+    }
+
+
+    protected String resolveHostName() {
+        String result;
+        if (bindAddress.getAddress().isAnyLocalAddress()) {
+            // make it more human readable and useful, an alternative to 0.0.0.0
+            try {
+                result = InetAddress.getLocalHost().getCanonicalHostName();
+            } catch (UnknownHostException e) {
+                result = "localhost";
             }
         } else {
-            result = bindAddress.getCanonicalHostName();
+            result = bindAddress.getAddress().getCanonicalHostName();
         }
         return result;
     }
@@ -183,14 +171,6 @@ public class TcpTransportServer implemen
         }
     }
 
-    public URI getBindURI() {
-        return bindURI;
-    }
-
-    public void setBindURI(URI bindURI) {
-        this.bindURI = bindURI;
-    }
-
     public int getBacklog() {
         return backlog;
     }
@@ -238,7 +218,7 @@ public class TcpTransportServer implemen
      * @return pretty print of this
      */
     public String toString() {
-        return "" + bindURI;
+        return getBoundAddress();
     }
 
 }
\ No newline at end of file

Modified: activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/TransportServer.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/TransportServer.java?rev=1082144&r1=1082143&r2=1082144&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/TransportServer.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/TransportServer.java
Wed Mar 16 13:34:15 2011
@@ -38,6 +38,8 @@ public interface TransportServer extends
      */
     void setAcceptListener(TransportAcceptListener acceptListener);
 
+    String getBoundAddress();
+
     String getConnectAddress();
 
     /**

Modified: activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/pipe/PipeTransportServer.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/pipe/PipeTransportServer.java?rev=1082144&r1=1082143&r2=1082144&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/pipe/PipeTransportServer.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-transport/src/main/java/org/apache/activemq/apollo/transport/pipe/PipeTransportServer.java
Wed Mar 16 13:34:15 2011
@@ -46,6 +46,10 @@ public class PipeTransportServer impleme
     private CustomDispatchSource<PipeTransport,LinkedList<PipeTransport>> acceptSource;
 
 
+    public String getBoundAddress() {
+        return connectURI.toString();
+    }
+
     public String getConnectAddress() {
         return connectURI.toString();
     }



Mime
View raw message