AMQ-6379 - Add openwire properties for provider name, provider version,

and platform details
This commit is contained in:
Michael L. Bloom 2016-07-22 13:40:06 -04:00
parent 1a598277cf
commit 8d5e84bb67
4 changed files with 222 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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();
}
}
}