You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cs...@apache.org on 2016/07/28 17:11:59 UTC

[1/3] activemq git commit: AMQ-6379 - Add openwire properties for provider name, provider version, and platform details

Repository: activemq
Updated Branches:
  refs/heads/master 1a598277c -> 7118247b6


AMQ-6379 - Add openwire properties for provider name, provider version,
and platform details


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/8d5e84bb
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/8d5e84bb
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/8d5e84bb

Branch: refs/heads/master
Commit: 8d5e84bb67664811a6ead9c65bb0eace919d3e95
Parents: 1a59827
Author: Michael L. Bloom <bl...@gmail.com>
Authored: Fri Jul 22 13:40:06 2016 -0400
Committer: Michael L. Bloom <bl...@gmail.com>
Committed: Thu Jul 28 12:25:13 2016 -0400

----------------------------------------------------------------------
 .../activemq/ActiveMQConnectionMetaData.java    |  32 +++++
 .../apache/activemq/command/WireFormatInfo.java |  36 ++++++
 .../openwire/OpenWireFormatFactory.java         |  31 +++++
 .../openwire/WireFormatInfoPropertiesTest.java  | 123 +++++++++++++++++++
 4 files changed, 222 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/8d5e84bb/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java
index 74b1039..64ec077 100755
--- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java
+++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java
@@ -32,6 +32,8 @@ public final class ActiveMQConnectionMetaData implements ConnectionMetaData {
     public static final String PROVIDER_VERSION;
     public static final int PROVIDER_MAJOR_VERSION;
     public static final int PROVIDER_MINOR_VERSION;
+    public static final String PROVIDER_NAME = "ActiveMQ";
+    public static final String PLATFORM_DETAILS;
 
     public static final ActiveMQConnectionMetaData INSTANCE = new ActiveMQConnectionMetaData();
 
@@ -57,6 +59,7 @@ public final class ActiveMQConnectionMetaData implements ConnectionMetaData {
         PROVIDER_VERSION = version;
         PROVIDER_MAJOR_VERSION = major;
         PROVIDER_MINOR_VERSION = minor;
+        PLATFORM_DETAILS = ActiveMQConnectionMetaData.getPlatformDetails();
     }
 
     private ActiveMQConnectionMetaData() {
@@ -147,4 +150,33 @@ public final class ActiveMQConnectionMetaData implements ConnectionMetaData {
         jmxProperties.add("JMSXProducerTXID");
         return jmxProperties.elements();
     }
+
+    /**
+     * Get the platform details for the JMS provider.
+     *
+     * @return String containing the platform details
+     */
+    private static String getPlatformDetails() {
+        String details = "unknown";
+        try {
+            StringBuilder platformInfo = new StringBuilder(128);
+
+            platformInfo.append("JVM: ");
+            platformInfo.append(System.getProperty("java.version"));
+            platformInfo.append(", ");
+            platformInfo.append(System.getProperty("java.vm.version"));
+            platformInfo.append(", ");
+            platformInfo.append(System.getProperty("java.vendor"));
+            platformInfo.append(", OS: ");
+            platformInfo.append(System.getProperty("os.name"));
+            platformInfo.append(", ");
+            platformInfo.append(System.getProperty("os.version"));
+            platformInfo.append(", ");
+            platformInfo.append(System.getProperty("os.arch"));
+
+            details = platformInfo.toString();
+        } catch (Throwable e) {
+        }
+        return details;
+    }
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/8d5e84bb/activemq-client/src/main/java/org/apache/activemq/command/WireFormatInfo.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/command/WireFormatInfo.java b/activemq-client/src/main/java/org/apache/activemq/command/WireFormatInfo.java
index 9848e66..8d61578 100755
--- a/activemq-client/src/main/java/org/apache/activemq/command/WireFormatInfo.java
+++ b/activemq-client/src/main/java/org/apache/activemq/command/WireFormatInfo.java
@@ -318,6 +318,42 @@ public class WireFormatInfo implements Command, MarshallAware {
         setProperty("CacheSize", new Integer(cacheSize));
     }
 
+    /**
+     * @throws IOException
+     */
+    public String getProviderName() throws IOException {
+        Object o = getProperty("ProviderName");
+        return o == null ? null : o.toString();
+    }
+
+    public void setProviderName(String providerName) throws IOException {
+        setProperty("ProviderName", providerName);
+    }
+
+    /**
+     * @throws IOException
+     */
+    public String getProviderVersion() throws IOException {
+        Object o = getProperty("ProviderVersion");
+        return o == null ? null : o.toString();
+    }
+
+    public void setProviderVersion(String providerVersion) throws IOException {
+        setProperty("ProviderVersion", providerVersion);
+    }
+
+    /**
+     * @throws IOException
+     */
+    public String getPlatformDetails() throws IOException {
+        Object o = getProperty("PlatformDetails");
+        return o == null ? null : o.toString();
+    }
+
+    public void setPlatformDetails(String platformDetails) throws IOException {
+        setProperty("PlatformDetails", platformDetails);
+    }
+
     @Override
     public Response visit(CommandVisitor visitor) throws Exception {
         return visitor.processWireFormat(this);

http://git-wip-us.apache.org/repos/asf/activemq/blob/8d5e84bb/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java
index b7f0e4f..ba6d643 100755
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.openwire;
 
+import org.apache.activemq.ActiveMQConnectionMetaData;
 import org.apache.activemq.command.WireFormatInfo;
 import org.apache.activemq.wireformat.WireFormat;
 import org.apache.activemq.wireformat.WireFormatFactory;
@@ -41,6 +42,9 @@ public class OpenWireFormatFactory implements WireFormatFactory {
     private int cacheSize = 1024;
     private long maxFrameSize = OpenWireFormat.DEFAULT_MAX_FRAME_SIZE;
     private String host=null;
+    private String providerName = ActiveMQConnectionMetaData.PROVIDER_NAME;
+    private String providerVersion = ActiveMQConnectionMetaData.PROVIDER_VERSION;
+    private String platformDetails = ActiveMQConnectionMetaData.PLATFORM_DETAILS;
 
     public WireFormat createWireFormat() {
         WireFormatInfo info = new WireFormatInfo();
@@ -59,6 +63,9 @@ public class OpenWireFormatFactory implements WireFormatFactory {
             if( host!=null ) {
                 info.setHost(host);
             }
+            info.setProviderName(providerName);
+            info.setProviderVersion(providerVersion);
+            info.setPlatformDetails(platformDetails);
         } catch (Exception e) {
             IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo");
             ise.initCause(e);
@@ -159,4 +166,28 @@ public class OpenWireFormatFactory implements WireFormatFactory {
     public void setHost(String host) {
         this.host = host;
     }
+
+    public String getProviderName() {
+        return providerName;
+    }
+
+    public void setProviderName(String providerName) {
+        this.providerName = providerName;
+    }
+
+    public String getProviderVersion() {
+        return providerVersion;
+    }
+
+    public void setProviderVersion(String providerVersion) {
+        this.providerVersion = providerVersion;
+    }
+
+    public String getPlatformDetails() {
+        return platformDetails;
+    }
+
+    public void setPlatformDetails(String platformDetails) {
+        this.platformDetails = platformDetails;
+    }
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/8d5e84bb/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java
new file mode 100644
index 0000000..6dfb6b1
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java
@@ -0,0 +1,123 @@
+/**
+ * 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.openwire;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.ActiveMQConnectionMetaData;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.command.WireFormatInfo;
+import org.apache.activemq.transport.DefaultTransportListener;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class WireFormatInfoPropertiesTest {
+
+    static final Logger LOG = LoggerFactory.getLogger(WireFormatInfoPropertiesTest.class);
+
+    protected BrokerService master;
+
+    protected final String brokerUri = "tcp://localhost:61616";
+
+    @Test
+    public void testClientProperties() throws Exception{
+        BrokerService service = createBrokerService();
+        try {
+            ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(new URI(brokerUri));
+            ActiveMQConnection conn = (ActiveMQConnection)factory.createConnection();
+            final AtomicReference<WireFormatInfo> clientWf = new AtomicReference<WireFormatInfo>();
+            conn.addTransportListener(new DefaultTransportListener() {
+                @Override
+                public void onCommand(Object command) {
+                    if (command instanceof WireFormatInfo) {
+                        clientWf.set((WireFormatInfo)command);
+                    }
+                }
+            });
+            conn.start();
+            if (clientWf.get() == null) {
+                fail("Wire format info is null");
+            }
+            assertTrue(clientWf.get().getProperties().containsKey("ProviderName"));
+            assertTrue(clientWf.get().getProperties().containsKey("ProviderVersion"));
+            assertTrue(clientWf.get().getProperties().containsKey("PlatformDetails"));
+            assertTrue(clientWf.get().getProviderName().equals(ActiveMQConnectionMetaData.PROVIDER_NAME));
+            assertTrue(clientWf.get().getPlatformDetails().equals(ActiveMQConnectionMetaData.PLATFORM_DETAILS));
+            // the version won't be valid until runtime
+            assertTrue(clientWf.get().getProviderVersion() == null);
+        } finally {
+            stopBroker(service);
+        }
+    }
+
+    @Test
+    public void testMarshalClientProperties() throws IOException {
+        // marshal object
+        OpenWireFormatFactory factory = new OpenWireFormatFactory();
+        OpenWireFormat wf = (OpenWireFormat)factory.createWireFormat();
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        DataOutputStream ds = new DataOutputStream(buffer);
+        WireFormatInfo orig = wf.getPreferedWireFormatInfo();
+        wf.marshal(orig, ds);
+        ds.close();
+
+        // unmarshal object and check that the properties are present.
+        ByteArrayInputStream in = new ByteArrayInputStream(buffer.toByteArray());
+        DataInputStream dis = new DataInputStream(in);
+        Object actual = wf.unmarshal(dis);
+
+        if (!(actual instanceof WireFormatInfo)) {
+            fail("Unknown type");
+        }
+        WireFormatInfo result = (WireFormatInfo)actual;
+        assertTrue(result.getProviderName().equals(orig.getProviderName()));
+        // the version won't be valid until runtime
+        assertTrue(result.getProviderVersion() == null || result.getProviderVersion().equals(orig.getProviderVersion()));
+        assertTrue(result.getPlatformDetails().equals(orig.getPlatformDetails()));
+    }
+
+    private BrokerService createBrokerService() throws Exception {
+        BrokerService service = new BrokerService();
+        service.addConnector(brokerUri);
+        service.setPersistent(false);
+        service.setUseJmx(false);
+        service.setBrokerName("Master");
+        service.start();
+        service.waitUntilStarted();
+        return service;
+    }
+
+    private void stopBroker(BrokerService service) throws Exception {
+        if (service != null) {
+            service.stop();
+            service.waitUntilStopped();
+        }
+    }
+
+}


[3/3] activemq git commit: https://issues.apache.org/jira/browse/AMQ-6379

Posted by cs...@apache.org.
https://issues.apache.org/jira/browse/AMQ-6379

Fixing unit test so that it uses a random port and changing the default
platform details to be "java" if there is an error


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/7118247b
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/7118247b
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/7118247b

Branch: refs/heads/master
Commit: 7118247b658335839bc792dde8f70eee2acc1f18
Parents: 8d7d4e6
Author: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Authored: Thu Jul 28 13:10:44 2016 -0400
Committer: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Committed: Thu Jul 28 13:10:44 2016 -0400

----------------------------------------------------------------------
 .../java/org/apache/activemq/ActiveMQConnectionMetaData.java  | 2 +-
 .../activemq/openwire/WireFormatInfoPropertiesTest.java       | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/7118247b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java
index 64ec077..ff6c38f 100755
--- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java
+++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java
@@ -157,7 +157,7 @@ public final class ActiveMQConnectionMetaData implements ConnectionMetaData {
      * @return String containing the platform details
      */
     private static String getPlatformDetails() {
-        String details = "unknown";
+        String details = "java";
         try {
             StringBuilder platformInfo = new StringBuilder(128);
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/7118247b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java
index 6dfb6b1..5e90f87 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java
@@ -31,6 +31,7 @@ import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.ActiveMQConnectionMetaData;
 import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.TransportConnector;
 import org.apache.activemq.command.WireFormatInfo;
 import org.apache.activemq.transport.DefaultTransportListener;
 import org.junit.Test;
@@ -42,8 +43,7 @@ public class WireFormatInfoPropertiesTest {
     static final Logger LOG = LoggerFactory.getLogger(WireFormatInfoPropertiesTest.class);
 
     protected BrokerService master;
-
-    protected final String brokerUri = "tcp://localhost:61616";
+    protected String brokerUri;
 
     @Test
     public void testClientProperties() throws Exception{
@@ -104,7 +104,8 @@ public class WireFormatInfoPropertiesTest {
 
     private BrokerService createBrokerService() throws Exception {
         BrokerService service = new BrokerService();
-        service.addConnector(brokerUri);
+        TransportConnector connector = service.addConnector("tcp://localhost:0");
+        brokerUri = connector.getPublishableConnectString();
         service.setPersistent(false);
         service.setUseJmx(false);
         service.setBrokerName("Master");


[2/3] activemq git commit: https://issues.apache.org/jira/browse/AMQ-6379

Posted by cs...@apache.org.
https://issues.apache.org/jira/browse/AMQ-6379

Merging patch for AMQ-6379

This closes #192


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/8d7d4e6d
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/8d7d4e6d
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/8d7d4e6d

Branch: refs/heads/master
Commit: 8d7d4e6df9d3c17ae068a7e8e50e0c0e0c8b22c2
Parents: 1a59827 8d5e84b
Author: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Authored: Thu Jul 28 13:10:13 2016 -0400
Committer: Christopher L. Shannon (cshannon) <ch...@gmail.com>
Committed: Thu Jul 28 13:10:13 2016 -0400

----------------------------------------------------------------------
 .../activemq/ActiveMQConnectionMetaData.java    |  32 +++++
 .../apache/activemq/command/WireFormatInfo.java |  36 ++++++
 .../openwire/OpenWireFormatFactory.java         |  31 +++++
 .../openwire/WireFormatInfoPropertiesTest.java  | 123 +++++++++++++++++++
 4 files changed, 222 insertions(+)
----------------------------------------------------------------------