1 16 17 package org.apache.axis.transport.jms; 18 19 import org.apache.axis.components.jms.JMSVendorAdapter; 20 import org.apache.axis.components.logger.LogFactory; 21 import org.apache.commons.logging.Log; 22 23 import java.util.HashMap ; 24 25 39 public abstract class JMSConnectorFactory 40 { 41 protected static Log log = 42 LogFactory.getLog(JMSConnectorFactory.class.getName()); 43 44 56 public static JMSConnector matchConnector(java.util.Set connectors, 57 HashMap connectorProps, 58 HashMap cfProps, 59 String username, 60 String password, 61 JMSVendorAdapter adapter) 62 { 63 java.util.Iterator iter = connectors.iterator(); 64 while (iter.hasNext()) 65 { 66 JMSConnector conn = (JMSConnector) iter.next(); 67 68 String connectorUsername = conn.getUsername(); 70 if (!( ((connectorUsername == null) && (username == null)) || 71 ((connectorUsername != null) && (username != null) && (connectorUsername.equals(username))) )) 72 continue; 73 74 String connectorPassword = conn.getPassword(); 76 if (!( ((connectorPassword == null) && (password == null)) || 77 ((connectorPassword != null) && (password != null) && (connectorPassword.equals(password))) )) 78 continue; 79 80 int connectorNumRetries = conn.getNumRetries(); 82 String propertyNumRetries = (String )connectorProps.get(JMSConstants.NUM_RETRIES); 83 int numRetries = JMSConstants.DEFAULT_NUM_RETRIES; 84 if (propertyNumRetries != null) 85 numRetries = Integer.parseInt(propertyNumRetries); 86 if (connectorNumRetries != numRetries) 87 continue; 88 89 String connectorClientID = conn.getClientID(); 91 String clientID = (String )connectorProps.get(JMSConstants.CLIENT_ID); 92 if (!( ((connectorClientID == null) && (clientID == null)) 93 || 94 ((connectorClientID != null) && (clientID != null) && connectorClientID.equals(clientID)) )) 95 continue; 96 97 String connectorDomain = (conn instanceof QueueConnector) ? JMSConstants.DOMAIN_QUEUE : JMSConstants.DOMAIN_TOPIC; 99 String propertyDomain = (String )connectorProps.get(JMSConstants.DOMAIN); 100 String domain = JMSConstants.DOMAIN_DEFAULT; 101 if (propertyDomain != null) 102 domain = propertyDomain; 103 if (!( ((connectorDomain == null) && (domain == null)) 104 || 105 ((connectorDomain != null) && (domain != null) && connectorDomain.equalsIgnoreCase(domain)) )) 106 continue; 107 108 JMSURLHelper jmsurl = conn.getJMSURL(); 110 if (adapter.isMatchingConnectionFactory(conn.getConnectionFactory(), jmsurl, cfProps)) 111 { 112 try 114 { 115 JMSConnectorManager.getInstance().reserve(conn); 116 117 if (log.isDebugEnabled()) { 118 log.debug("JMSConnectorFactory: Found matching connector"); 119 } 120 } 121 catch (Exception e) 122 { 123 continue; 125 } 126 127 return conn; 128 } 129 } 130 131 if (log.isDebugEnabled()) { 132 log.debug("JMSConnectorFactory: No matching connectors found"); 133 } 134 135 return null; 136 } 137 138 149 public static JMSConnector createServerConnector(HashMap connectorConfig, 150 HashMap cfConfig, 151 String username, 152 String password, 153 JMSVendorAdapter adapter) 154 throws Exception 155 { 156 return createConnector(connectorConfig, cfConfig, true, 157 username, password, adapter); 158 } 159 160 171 public static JMSConnector createClientConnector(HashMap connectorConfig, 172 HashMap cfConfig, 173 String username, 174 String password, 175 JMSVendorAdapter adapter) 176 throws Exception 177 { 178 return createConnector(connectorConfig, cfConfig, false, 179 username, password, adapter); 180 } 181 182 private static JMSConnector createConnector(HashMap connectorConfig, 183 HashMap cfConfig, 184 boolean allowReceive, 185 String username, 186 String password, 187 JMSVendorAdapter adapter) 188 throws Exception 189 { 190 if(connectorConfig != null) 191 connectorConfig = (HashMap )connectorConfig.clone(); 192 int numRetries = MapUtils.removeIntProperty(connectorConfig, 193 JMSConstants.NUM_RETRIES, 194 JMSConstants.DEFAULT_NUM_RETRIES); 195 196 int numSessions = MapUtils.removeIntProperty(connectorConfig, 197 JMSConstants.NUM_SESSIONS, 198 JMSConstants.DEFAULT_NUM_SESSIONS); 199 200 long connectRetryInterval = MapUtils.removeLongProperty(connectorConfig, 201 JMSConstants.CONNECT_RETRY_INTERVAL, 202 JMSConstants.DEFAULT_CONNECT_RETRY_INTERVAL); 203 204 long interactRetryInterval = MapUtils.removeLongProperty(connectorConfig, 205 JMSConstants.INTERACT_RETRY_INTERVAL, 206 JMSConstants.DEFAULT_INTERACT_RETRY_INTERVAL); 207 208 long timeoutTime = MapUtils.removeLongProperty(connectorConfig, 209 JMSConstants.TIMEOUT_TIME, 210 JMSConstants.DEFAULT_TIMEOUT_TIME); 211 212 String clientID = MapUtils.removeStringProperty(connectorConfig, 213 JMSConstants.CLIENT_ID, 214 null); 215 String domain = MapUtils.removeStringProperty(connectorConfig, 216 JMSConstants.DOMAIN, 217 JMSConstants.DOMAIN_DEFAULT); 218 219 JMSURLHelper jmsurl = (JMSURLHelper)connectorConfig.get(JMSConstants.JMS_URL); 221 222 if(cfConfig == null) 223 throw new IllegalArgumentException ("noCfConfig"); 224 225 if(domain.equals(JMSConstants.DOMAIN_QUEUE)) 226 { 227 return new QueueConnector(adapter.getQueueConnectionFactory(cfConfig), 228 numRetries, numSessions, connectRetryInterval, 229 interactRetryInterval, timeoutTime, 230 allowReceive, clientID, username, password, 231 adapter, jmsurl); 232 } 233 else { 235 return new TopicConnector(adapter.getTopicConnectionFactory(cfConfig), 236 numRetries, numSessions, connectRetryInterval, 237 interactRetryInterval, timeoutTime, 238 allowReceive, clientID, username, password, 239 adapter, jmsurl); 240 } 241 } 242 } | Popular Tags |