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 038 public static final ActiveMQConnectionMetaData INSTANCE = new ActiveMQConnectionMetaData(); 039 040 static { 041 String version = null; 042 int major = 0; 043 int minor = 0; 044 try { 045 Package p = Package.getPackage("org.apache.activemq"); 046 if (p != null) { 047 version = p.getImplementationVersion(); 048 if (version != null) { 049 Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*"); 050 Matcher m = pattern.matcher(version); 051 if (m.matches()) { 052 major = Integer.parseInt(m.group(1)); 053 minor = Integer.parseInt(m.group(2)); 054 } 055 } 056 } 057 } catch (Throwable e) { 058 } 059 PROVIDER_VERSION = version; 060 PROVIDER_MAJOR_VERSION = major; 061 PROVIDER_MINOR_VERSION = minor; 062 PLATFORM_DETAILS = ActiveMQConnectionMetaData.getPlatformDetails(); 063 } 064 065 private ActiveMQConnectionMetaData() { 066 } 067 068 /** 069 * Gets the JMS API version. 070 * 071 * @return the JMS API version 072 */ 073 @Override 074 public String getJMSVersion() { 075 return "1.1"; 076 } 077 078 /** 079 * Gets the JMS major version number. 080 * 081 * @return the JMS API major version number 082 */ 083 @Override 084 public int getJMSMajorVersion() { 085 return 1; 086 } 087 088 /** 089 * Gets the JMS minor version number. 090 * 091 * @return the JMS API minor version number 092 */ 093 @Override 094 public int getJMSMinorVersion() { 095 return 1; 096 } 097 098 /** 099 * Gets the JMS provider name. 100 * 101 * @return the JMS provider name 102 */ 103 @Override 104 public String getJMSProviderName() { 105 return "ActiveMQ"; 106 } 107 108 /** 109 * Gets the JMS provider version. 110 * 111 * @return the JMS provider version 112 */ 113 @Override 114 public String getProviderVersion() { 115 return PROVIDER_VERSION; 116 } 117 118 /** 119 * Gets the JMS provider major version number. 120 * 121 * @return the JMS provider major version number 122 */ 123 @Override 124 public int getProviderMajorVersion() { 125 return PROVIDER_MAJOR_VERSION; 126 } 127 128 /** 129 * Gets the JMS provider minor version number. 130 * 131 * @return the JMS provider minor version number 132 */ 133 @Override 134 public int getProviderMinorVersion() { 135 return PROVIDER_MINOR_VERSION; 136 } 137 138 /** 139 * Gets an enumeration of the JMSX property names. 140 * 141 * @return an Enumeration of JMSX property names 142 */ 143 @Override 144 public Enumeration<String> getJMSXPropertyNames() { 145 Vector<String> jmxProperties = new Vector<String>(); 146 jmxProperties.add("JMSXUserID"); 147 jmxProperties.add("JMSXGroupID"); 148 jmxProperties.add("JMSXGroupSeq"); 149 jmxProperties.add("JMSXDeliveryCount"); 150 jmxProperties.add("JMSXProducerTXID"); 151 return jmxProperties.elements(); 152 } 153 154 /** 155 * Get the platform details for the JMS provider. 156 * 157 * @return String containing the platform details 158 */ 159 private static String getPlatformDetails() { 160 String details = "java"; 161 try { 162 StringBuilder platformInfo = new StringBuilder(128); 163 164 platformInfo.append("JVM: "); 165 platformInfo.append(System.getProperty("java.version")); 166 platformInfo.append(", "); 167 platformInfo.append(System.getProperty("java.vm.version")); 168 platformInfo.append(", "); 169 platformInfo.append(System.getProperty("java.vendor")); 170 platformInfo.append(", OS: "); 171 platformInfo.append(System.getProperty("os.name")); 172 platformInfo.append(", "); 173 platformInfo.append(System.getProperty("os.version")); 174 platformInfo.append(", "); 175 platformInfo.append(System.getProperty("os.arch")); 176 177 details = platformInfo.toString(); 178 } catch (Throwable e) { 179 } 180 return details; 181 } 182}