activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1359194 - in /activemq/trunk: activemq-core/src/main/java/org/apache/activemq/broker/ activemq-core/src/main/java/org/apache/activemq/broker/jmx/ activemq-core/src/main/java/org/apache/activemq/transport/ activemq-core/src/test/java/org/ap...
Date Mon, 09 Jul 2012 14:43:31 GMT
Author: dejanb
Date: Mon Jul  9 14:43:30 2012
New Revision: 1359194

URL: http://svn.apache.org/viewvc?rev=1359194&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3918 - transport connector urls exposed using JMX

Added:
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/WebTransportServerSupport.java
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerViewMBean.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportServerSupport.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportServer.java
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=1359194&r1=1359193&r2=1359194&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Mon Jul  9 14:43:30 2012
@@ -2328,11 +2328,11 @@ public class BrokerService implements Se
         if (policy != null) {
             connector.setMessageAuthorizationPolicy(policy);
         }
+        connector.getStatistics().setEnabled(enableStatistics);
+        connector.start();
         if (isUseJmx()) {
             connector = registerConnectorMBean(connector);
         }
-        connector.getStatistics().setEnabled(enableStatistics);
-        connector.start();
         return connector;
     }
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java?rev=1359194&r1=1359193&r2=1359194&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
Mon Jul  9 14:43:30 2012
@@ -23,6 +23,8 @@ import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.concurrent.atomic.AtomicInteger;
 import javax.management.ObjectName;
@@ -364,21 +366,54 @@ public class BrokerView implements Broke
         }
     }
 
+    public  Map<String, String> getTransportConnectors() {
+        Map<String, String> answer = new HashMap<String, String>();
+        try {
+            for (TransportConnector connector : brokerService.getTransportConnectors()) {
+                answer.put(connector.getName(), connector.getConnectUri().toString());
+            }
+        } catch (Exception e) {
+            LOG.debug("Failed to read URI to build transport connectors map", e);
+        }
+        return answer;
+    }
+
+    @Override
+    public String getTransportConnectorByType(String type) {
+        return brokerService.getTransportConnectorURIsAsMap().get(type);
+    }
+
+    @Deprecated
+    /**
+     * @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
+     */
     public String getOpenWireURL() {
         String answer = brokerService.getTransportConnectorURIsAsMap().get("tcp");
         return answer != null ? answer : "";
     }
 
+    @Deprecated
+    /**
+     * @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
+     */
     public String getStompURL() {
         String answer = brokerService.getTransportConnectorURIsAsMap().get("stomp");
         return answer != null ? answer : "";
     }
 
+    @Deprecated
+    /**
+     * @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
+     */
     public String getSslURL() {
         String answer = brokerService.getTransportConnectorURIsAsMap().get("ssl");
         return answer != null ? answer : "";
     }
 
+    @Deprecated
+    /**
+     * @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
+     */
     public String getStompSslURL() {
         String answer = brokerService.getTransportConnectorURIsAsMap().get("stomp+ssl");
         return answer != null ? answer : "";

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerViewMBean.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerViewMBean.java?rev=1359194&r1=1359193&r2=1359194&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerViewMBean.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerViewMBean.java
Mon Jul  9 14:43:30 2012
@@ -19,6 +19,8 @@ package org.apache.activemq.broker.jmx;
 import javax.management.ObjectName;
 import org.apache.activemq.Service;
 
+import java.util.Map;
+
 
 /**
  * @author David Martin Clavo david(dot)martin(dot)clavo(at)gmail.com (for the reloadLog4jProperties
method)
@@ -249,21 +251,43 @@ public interface BrokerViewMBean extends
     @MBeanInfo(value="Reloads log4j.properties from the classpath.")
     public void reloadLog4jProperties() throws Throwable;
 
-    @MBeanInfo("The url of the openwire connector")
+    /**
+     * @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
+     */
+    @Deprecated
+    @MBeanInfo("The url of the openwire connector - deprecated, use getTransportConnectors
or getTransportConnectorByType instead")
     String getOpenWireURL();
 
-    @MBeanInfo("The url of the stomp connector")
+    /**
+     * @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
+     */
+    @Deprecated
+    @MBeanInfo("The url of the stomp connector - deprecated, use getTransportConnectors or
getTransportConnectorByType instead")
     String getStompURL();
 
-    @MBeanInfo("The url of the SSL connector")
+    /**
+     * @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
+     */
+    @Deprecated
+    @MBeanInfo("The url of the SSL connector - deprecated, use getTransportConnectors or
getTransportConnectorByType instead")
     String getSslURL();
 
-    @MBeanInfo("The url of the Stomp SSL connector")
+    /**
+     * @deprecated use {@link #getTransportConnectors()} or {@link #getTransportConnectorByType(String)}
+     */
+    @Deprecated
+    @MBeanInfo("The url of the Stomp SSL connector - deprecated, use getTransportConnectors
or getTransportConnectorByType instead")
     String getStompSslURL();
 
     @MBeanInfo("The url of the VM connector")
     String getVMURL();
 
+    @MBeanInfo("The map of all defined transport connectors, with transport name as a key")
+    Map<String, String> getTransportConnectors();
+
+    @MBeanInfo("The url of transport connector by it's type; e.g. tcp, stomp, ssl, etc.")
+    String getTransportConnectorByType(String type);
+
     @MBeanInfo("The location of the data directory")
     public String getDataDirectory();
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportServerSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportServerSupport.java?rev=1359194&r1=1359193&r2=1359194&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportServerSupport.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/TransportServerSupport.java
Mon Jul  9 14:43:30 2012
@@ -88,4 +88,6 @@ public abstract class TransportServerSup
     public void setTransportOption(Map<String, Object> transportOptions) {
         this.transportOptions = transportOptions;
     }
+
+
 }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java?rev=1359194&r1=1359193&r2=1359194&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
Mon Jul  9 14:43:30 2012
@@ -90,8 +90,9 @@ public class MBeanTest extends EmbeddedB
     public void testConnectors() throws Exception{
         ObjectName brokerName = assertRegisteredObjectName(domain + ":Type=Broker,BrokerName=localhost");
         BrokerViewMBean broker = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
brokerName, BrokerViewMBean.class, true);
+
         assertEquals("openwire URL port doesn't equal bind Address",
-                     new URI(broker.getOpenWireURL()).getPort(),
+                     new URI(broker.getTransportConnectorByType("tcp")).getPort(),
                      new URI(this.broker.getTransportConnectors().get(0).getPublishableConnectString()).getPort());
     }
 

Added: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/WebTransportServerSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/WebTransportServerSupport.java?rev=1359194&view=auto
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/WebTransportServerSupport.java
(added)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/WebTransportServerSupport.java
Mon Jul  9 14:43:30 2012
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.transport;
+
+import org.apache.activemq.util.InetAddressUtil;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+
+import java.net.InetAddress;
+import java.net.URI;
+
+abstract public class WebTransportServerSupport extends TransportServerSupport {
+
+    protected URI bindAddress;
+    protected Server server;
+    protected Connector connector;
+    protected SocketConnectorFactory socketConnectorFactory;
+    protected String host;
+
+    public WebTransportServerSupport(URI location) {
+        super(location);
+    }
+
+    public void bind() throws Exception {
+
+        URI bind = getBindLocation();
+
+        String bindHost = bind.getHost();
+        bindHost = (bindHost == null || bindHost.length() == 0) ? "localhost" : bindHost;
+        InetAddress addr = InetAddress.getByName(bindHost);
+        host = addr.getCanonicalHostName();
+        if (addr.isAnyLocalAddress()) {
+            host = InetAddressUtil.getLocalHostName();
+        }
+
+        connector.setHost(host);
+        connector.setPort(bindAddress.getPort());
+        connector.setServer(server);
+        server.addConnector(connector);
+
+    }
+}

Modified: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportServer.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportServer.java?rev=1359194&r1=1359193&r2=1359194&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportServer.java
(original)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportServer.java
Mon Jul  9 14:43:30 2012
@@ -19,6 +19,7 @@ package org.apache.activemq.transport.ht
 import org.apache.activemq.command.BrokerInfo;
 import org.apache.activemq.transport.SocketConnectorFactory;
 import org.apache.activemq.transport.TransportServerSupport;
+import org.apache.activemq.transport.WebTransportServerSupport;
 import org.apache.activemq.transport.util.TextWireFormat;
 import org.apache.activemq.transport.xstream.XStreamWireFormat;
 import org.apache.activemq.util.ServiceStopper;
@@ -28,18 +29,15 @@ import org.eclipse.jetty.server.handler.
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
 
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.URI;
 import java.util.Map;
 
-public class HttpTransportServer extends TransportServerSupport {
+public class HttpTransportServer extends WebTransportServerSupport {
 
-    private URI bindAddress;
     private TextWireFormat wireFormat;
-    private Server server;
-    private Connector connector;
     private HttpTransportFactory transportFactory;
-    protected SocketConnectorFactory socketConnectorFactory;
 
     public HttpTransportServer(URI uri, HttpTransportFactory factory) {
         super(uri);
@@ -79,10 +77,9 @@ public class HttpTransportServer extends
         if (connector == null) {
             connector = socketConnectorFactory.createConnector();
         }
-        connector.setHost(bindAddress.getHost());
-        connector.setPort(bindAddress.getPort());
-        connector.setServer(server);
-        server.addConnector(connector);
+
+        URI bind = getBindLocation();
+        bind();
 
         ServletContextHandler contextHandler =
             new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY);
@@ -100,6 +97,7 @@ public class HttpTransportServer extends
         contextHandler.setHandler(gzipHandler);
 
         server.start();
+        setConnectURI(new URI(bind.getScheme(), bind.getUserInfo(), host, connector.getLocalPort(),
bind.getPath(), bind.getQuery(), bind.getFragment()));
     }
 
     protected void doStop(ServiceStopper stopper) throws Exception {

Modified: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java?rev=1359194&r1=1359193&r2=1359194&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java
(original)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java
Mon Jul  9 14:43:30 2012
@@ -20,6 +20,8 @@ package org.apache.activemq.transport.ws
 import org.apache.activemq.command.BrokerInfo;
 import org.apache.activemq.transport.SocketConnectorFactory;
 import org.apache.activemq.transport.TransportServerSupport;
+import org.apache.activemq.transport.WebTransportServerSupport;
+import org.apache.activemq.util.InetAddressUtil;
 import org.apache.activemq.util.ServiceStopper;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.Server;
@@ -27,6 +29,7 @@ import org.eclipse.jetty.server.nio.Sele
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
 
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.URI;
 import java.util.Map;
@@ -35,12 +38,7 @@ import java.util.Map;
  * Creates a web server and registers web socket server
  *
  */
-public class WSTransportServer extends TransportServerSupport {
-
-    private URI bindAddress;
-    private Server server;
-    private Connector connector;
-    protected SocketConnectorFactory socketConnectorFactory;
+public class WSTransportServer extends WebTransportServerSupport {
 
     public WSTransportServer(URI location) {
         super(location);
@@ -50,13 +48,14 @@ public class WSTransportServer extends T
 
     protected void doStart() throws Exception {
         server = new Server();
+
         if (connector == null) {
             connector = socketConnectorFactory.createConnector();
         }
-        connector.setHost(bindAddress.getHost());
-        connector.setPort(bindAddress.getPort());
-        connector.setServer(server);
-        server.addConnector(connector);
+
+        URI bind = getBindLocation();
+
+        bind();
 
         ServletContextHandler contextHandler =
                 new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY);
@@ -68,6 +67,7 @@ public class WSTransportServer extends T
         contextHandler.setAttribute("acceptListener", getAcceptListener());
 
         server.start();
+        setConnectURI(new URI(bind.getScheme(), bind.getUserInfo(), host, connector.getLocalPort(),
bind.getPath(), bind.getQuery(), bind.getFragment()));
     }
 
     protected void doStop(ServiceStopper stopper) throws Exception {



Mime
View raw message