1 23 package com.sun.enterprise.jms; 24 25 import java.io.*; 26 import java.util.*; 27 import java.util.logging.*; 28 29 import javax.naming.*; 30 import javax.jms.*; 31 import com.sun.enterprise.util.FileUtil; 32 import com.sun.enterprise.ServerConfiguration; 33 import com.sun.enterprise.repository.*; 34 import com.sun.enterprise.util.i18n.StringManager; 35 import com.sun.enterprise.server.ApplicationServer; 36 import com.sun.enterprise.server.ServerContext; 37 import com.sun.enterprise.config.serverbeans.*; 38 import com.sun.messaging.jmq.jmsspi.JMSAdminFactory; 39 import com.sun.messaging.jmq.jmsspi.JMSAdmin; 40 import com.sun.logging.LogDomains; 41 42 import com.sun.appserv.server.util.Version; 43 44 48 public class IASJmsUtil { 49 50 private static Logger _logger = LogDomains.getLogger(LogDomains.JMS_LOGGER); 51 52 public static final String MDB_CONTAINER_QUEUE_XACF = "MDB_CONTAINER_QUEUE_CF__jmsxa_default"; 54 public static final String MDB_CONTAINER_TOPIC_XACF = "MDB_CONTAINER_TOPIC_CF__jmsxa_default"; 55 public static final String MQ_DIR_NAME = "imq"; 56 57 private static String DEFAULT_SERVER = "server"; 58 private static String DEFAULT_MQ_INSTANCE = "imqbroker"; 59 60 public static final String DEFAULT_USER = "admin"; 61 public static final String DEFAULT_PASSWORD = "admin"; 62 public static final String DEFAULT_MAX_ACTIVE_CONSUMERS = "-1"; 63 public static final String MAX_ACTIVE_CONSUMERS_ATTRIBUTE = "MaxNumActiveConsumers"; 64 public static final String MAX_ACTIVE_CONSUMERS_PROPERTY = "maxNumActiveConsumers"; 65 66 private static StringManager _sm = StringManager.getManager(IASJmsUtil.class); 67 68 private static final boolean debug = false; 69 70 71 75 public static String getXAConnectionFactoryName(String 76 connectionFactoryName) { 77 return "JMSXA" + connectionFactoryName + "__jmsxa"; 78 } 79 80 public static String getDestinationName(Destination destination) { 81 String name = null; 82 try { 83 name = (destination instanceof javax.jms.Queue ) ? 84 ((javax.jms.Queue ) destination).getQueueName() : 85 ((javax.jms.Topic ) destination).getTopicName(); 86 } catch(Exception e) {} 87 return name; 88 } 89 90 public static void checkVersion(JMSAdmin ja) { 91 float version = 0.0f; 92 String vs = "?.?"; 93 94 try { 95 vs = ja.getVersion(); 96 version = Float.parseFloat(vs); 97 } 98 catch (Exception e) { 99 throw new RuntimeException ("Error detected while parsing JMS " + 100 "provider SPI version string (" + vs + ")."); 101 } 102 103 if (version < 2.0 || version >= 3.0) 104 throw new RuntimeException ( 105 "Incorrect JMS Provider SPI version detected (" + 106 vs + ")." + 107 " Please make sure that you are using the correct" + 108 " version of the JMS provider."); 109 } 110 111 118 public static JMSAdminFactory getJMSAdminFactory() throws Exception { 119 JMSAdminFactory jmsAdminFactory = null; 120 121 Class jmsAdminFactoryClass = Class.forName("com.sun.messaging.jmq.admin.jmsspi.JMSAdminFactoryImpl"); 122 jmsAdminFactory = (JMSAdminFactory)jmsAdminFactoryClass.newInstance(); 123 124 checkVersion(jmsAdminFactory.getJMSAdmin()); 125 126 return jmsAdminFactory; 127 } 128 129 protected static JMSAdmin getJMSAdmin() throws Exception { 130 JMSAdmin jmsAdmin = JmsProviderLifecycle.getJMSAdmin(); 131 if (jmsAdmin == null) { 132 jmsAdmin = getJMSAdminFactory().getJMSAdmin(); 133 } 134 return jmsAdmin; 135 } 136 137 142 public static void validateJMSSelector(String selector) 143 throws Exception , JMSException { 144 145 getJMSAdmin().validateJMSSelector(selector); 146 } 147 148 151 public static String clientIDPropertyName() throws Exception { 152 return getJMSAdmin().clientIDPropertyName(); 153 } 154 155 163 public static Object wrapJMSConnectionFactoryObject(Object obj) 164 throws Exception , JMSException { 165 166 return getJMSAdmin().wrapJMSConnectionFactoryObject(obj); 167 } 168 169 172 public static String getBrokerInstanceName(String asDomain, 173 String asInstance, JmsService js) { 174 175 ElementProperty[] jmsProperties = js.getElementProperty(); 176 177 String instanceName = null; 178 String suffix = null; 179 180 if (jmsProperties != null) { 181 for (int ii=0; ii < jmsProperties.length; ii++) { 182 ElementProperty p = jmsProperties[ii]; 183 String name = p.getName(); 184 185 if (name.equals("instance-name")) 186 instanceName = p.getValue(); 187 if (name.equals("instance-name-suffix")) 188 suffix = p.getValue(); 189 if (name.equals("append-version") && 190 Boolean.valueOf(p.getValue()).booleanValue()) { 191 suffix = Version.getMajorVersion() + "_" + 192 Version.getMinorVersion(); 193 } 194 } 195 } 196 197 if (instanceName != null) 198 return instanceName; 199 200 if (asInstance.equals(DEFAULT_SERVER)) { 201 instanceName = DEFAULT_MQ_INSTANCE; 202 } else { 203 instanceName = asDomain + "_" + asInstance; 204 } 205 206 if (suffix != null) 207 instanceName = instanceName + "_" + suffix; 208 209 return instanceName; 210 } 211 212 215 public static String getDefaultMaxActiveConsumers () { 216 return DEFAULT_MAX_ACTIVE_CONSUMERS; 217 } 218 219 222 public static String getMaxActiveConsumersProperty () { 223 return MAX_ACTIVE_CONSUMERS_PROPERTY; 224 } 225 226 229 public static String getMaxActiveConsumersAttribute () { 230 return MAX_ACTIVE_CONSUMERS_ATTRIBUTE; 231 } 232 } 233 | Popular Tags |