001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.activemq; 018 019import java.util.Enumeration; 020import java.util.Vector; 021import java.util.regex.Matcher; 022import java.util.regex.Pattern; 023 024import javax.jms.ConnectionMetaData; 025 026/** 027 * A <CODE>ConnectionMetaData</CODE> object provides information describing 028 * the <CODE>Connection</CODE> object. 029 */ 030public final class ActiveMQConnectionMetaData implements ConnectionMetaData { 031 032 public static final String PROVIDER_VERSION; 033 public static final int PROVIDER_MAJOR_VERSION; 034 public static final int PROVIDER_MINOR_VERSION; 035 public static final String PROVIDER_NAME = "ActiveMQ"; 036 public static final String PLATFORM_DETAILS; 037 public static final String DEFAULT_PLATFORM_DETAILS = "Java"; 038 039 public static final ActiveMQConnectionMetaData INSTANCE = new ActiveMQConnectionMetaData(); 040 041 static { 042 String version = null; 043 int major = 0; 044 int minor = 0; 045 try { 046 Package p = Package.getPackage("org.apache.activemq"); 047 if (p != null) { 048 version = p.getImplementationVersion(); 049 if (version != null) { 050 Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*"); 051 Matcher m = pattern.matcher(version); 052 if (m.matches()) { 053 major = Integer.parseInt(m.group(1)); 054 minor = Integer.parseInt(m.group(2)); 055 } 056 } 057 } 058 } catch (Throwable e) { 059 } 060 PROVIDER_VERSION = version; 061 PROVIDER_MAJOR_VERSION = major; 062 PROVIDER_MINOR_VERSION = minor; 063 PLATFORM_DETAILS = ActiveMQConnectionMetaData.getPlatformDetails(); 064 } 065 066 private ActiveMQConnectionMetaData() { 067 } 068 069 /** 070 * Gets the JMS API version. 071 * 072 * @return the JMS API version 073 */ 074 @Override 075 public String getJMSVersion() { 076 return "1.1"; 077 } 078 079 /** 080 * Gets the JMS major version number. 081 * 082 * @return the JMS API major version number 083 */ 084 @Override 085 public int getJMSMajorVersion() { 086 return 1; 087 } 088 089 /** 090 * Gets the JMS minor version number. 091 * 092 * @return the JMS API minor version number 093 */ 094 @Override 095 public int getJMSMinorVersion() { 096 return 1; 097 } 098 099 /** 100 * Gets the JMS provider name. 101 * 102 * @return the JMS provider name 103 */ 104 @Override 105 public String getJMSProviderName() { 106 return "ActiveMQ"; 107 } 108 109 /** 110 * Gets the JMS provider version. 111 * 112 * @return the JMS provider version 113 */ 114 @Override 115 public String getProviderVersion() { 116 return PROVIDER_VERSION; 117 } 118 119 /** 120 * Gets the JMS provider major version number. 121 * 122 * @return the JMS provider major version number 123 */ 124 @Override 125 public int getProviderMajorVersion() { 126 return PROVIDER_MAJOR_VERSION; 127 } 128 129 /** 130 * Gets the JMS provider minor version number. 131 * 132 * @return the JMS provider minor version number 133 */ 134 @Override 135 public int getProviderMinorVersion() { 136 return PROVIDER_MINOR_VERSION; 137 } 138 139 /** 140 * Gets an enumeration of the JMSX property names. 141 * 142 * @return an Enumeration of JMSX property names 143 */ 144 @Override 145 public Enumeration<String> getJMSXPropertyNames() { 146 Vector<String> jmxProperties = new Vector<String>(); 147 jmxProperties.add("JMSXUserID"); 148 jmxProperties.add("JMSXGroupID"); 149 jmxProperties.add("JMSXGroupSeq"); 150 jmxProperties.add("JMSXDeliveryCount"); 151 jmxProperties.add("JMSXProducerTXID"); 152 return jmxProperties.elements(); 153 } 154 155 /** 156 * Get the platform details for the JMS provider. 157 * 158 * @return String containing the platform details 159 */ 160 private static String getPlatformDetails() { 161 String details = "java"; 162 try { 163 StringBuilder platformInfo = new StringBuilder(128); 164 165 platformInfo.append("JVM: "); 166 platformInfo.append(System.getProperty("java.version")); 167 platformInfo.append(", "); 168 platformInfo.append(System.getProperty("java.vm.version")); 169 platformInfo.append(", "); 170 platformInfo.append(System.getProperty("java.vendor")); 171 platformInfo.append(", OS: "); 172 platformInfo.append(System.getProperty("os.name")); 173 platformInfo.append(", "); 174 platformInfo.append(System.getProperty("os.version")); 175 platformInfo.append(", "); 176 platformInfo.append(System.getProperty("os.arch")); 177 178 details = platformInfo.toString(); 179 } catch (Throwable e) { 180 } 181 return details; 182 } 183}