2
* Copyright 2001, 2002,2004 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package org.apache.axis.transport.jms;
19
import org.apache.axis.components.jms.JMSVendorAdapter;
20
import org.apache.axis.components.logger.LogFactory;
21
import org.apache.commons.logging.Log;
23
import java.util.HashMap;
26
* JMSConnectorFactory is a factory class for creating JMSConnectors. It can
27
* create both client connectors and server connectors. A server connector
28
* is configured to allow asynchronous message receipt, while a client
31
* JMSConnectorFactory can also be used to select an appropriately configured
32
* JMSConnector from an existing pool of connectors.
34
* @author Jaime Meritt (jmeritt@sonicsoftware.com)
35
* @author Richard Chung (rchung@sonicsoftware.com)
36
* @author Dave Chappell (chappell@sonicsoftware.com)
37
* @author Ray Chun (rchun@sonicsoftware.com)
39
public abstract class JMSConnectorFactory
41
protected static Log log =
42
LogFactory.getLog(JMSConnectorFactory.class.getName());
45
* Performs an initial check on the connector properties, and then defers
46
* to the vendor adapter for matching on the vendor-specific connection factory.
48
* @param connectors the list of potential matches
49
* @param connectorProps the set of properties to be used for matching the connector
50
* @param cfProps the set of properties to be used for matching the connection factory
51
* @param username the user requesting the connector
52
* @param password the password associated with the requesting user
53
* @param adapter the vendor adapter specified in the JMS URL
54
* @return a JMSConnector that matches the specified properties
56
public static JMSConnector matchConnector(java.util.Set connectors,
57
HashMap connectorProps,
61
JMSVendorAdapter adapter)
63
java.util.Iterator iter = connectors.iterator();
64
while (iter.hasNext())
66
JMSConnector conn = (JMSConnector) iter.next();
69
String connectorUsername = conn.getUsername();
70
if (!( ((connectorUsername == null) && (username == null)) ||
71
((connectorUsername != null) && (username != null) && (connectorUsername.equals(username))) ))
75
String connectorPassword = conn.getPassword();
76
if (!( ((connectorPassword == null) && (password == null)) ||
77
((connectorPassword != null) && (password != null) && (connectorPassword.equals(password))) ))
81
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)
90
String connectorClientID = conn.getClientID();
91
String clientID = (String)connectorProps.get(JMSConstants.CLIENT_ID);
92
if (!( ((connectorClientID == null) && (clientID == null))
94
((connectorClientID != null) && (clientID != null) && connectorClientID.equals(clientID)) ))
98
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))
105
((connectorDomain != null) && (domain != null) && connectorDomain.equalsIgnoreCase(domain)) ))
108
// the connection factory must also match for the connector to be reused
109
JMSURLHelper jmsurl = conn.getJMSURL();
110
if (adapter.isMatchingConnectionFactory(conn.getConnectionFactory(), jmsurl, cfProps))
112
// attempt to reserve the connector
115
JMSConnectorManager.getInstance().reserve(conn);
117
if (log.isDebugEnabled()) {
118
log.debug("JMSConnectorFactory: Found matching connector");
123
// ignore. the connector may be in the process of shutting down, so try the next element
131
if (log.isDebugEnabled()) {
132
log.debug("JMSConnectorFactory: No matching connectors found");
139
* Static method to create a server connector. Server connectors can
140
* accept incoming requests.
142
* @param connectorConfig
149
public static JMSConnector createServerConnector(HashMap connectorConfig,
153
JMSVendorAdapter adapter)
156
return createConnector(connectorConfig, cfConfig, true,
157
username, password, adapter);
161
* Static method to create a client connector. Client connectors cannot
162
* accept incoming requests.
164
* @param connectorConfig
171
public static JMSConnector createClientConnector(HashMap connectorConfig,
175
JMSVendorAdapter adapter)
178
return createConnector(connectorConfig, cfConfig, false,
179
username, password, adapter);
182
private static JMSConnector createConnector(HashMap connectorConfig,
184
boolean allowReceive,
187
JMSVendorAdapter adapter)
190
if(connectorConfig != null)
191
connectorConfig = (HashMap)connectorConfig.clone();
192
int numRetries = MapUtils.removeIntProperty(connectorConfig,
193
JMSConstants.NUM_RETRIES,
194
JMSConstants.DEFAULT_NUM_RETRIES);
196
int numSessions = MapUtils.removeIntProperty(connectorConfig,
197
JMSConstants.NUM_SESSIONS,
198
JMSConstants.DEFAULT_NUM_SESSIONS);
200
long connectRetryInterval = MapUtils.removeLongProperty(connectorConfig,
201
JMSConstants.CONNECT_RETRY_INTERVAL,
202
JMSConstants.DEFAULT_CONNECT_RETRY_INTERVAL);
204
long interactRetryInterval = MapUtils.removeLongProperty(connectorConfig,
205
JMSConstants.INTERACT_RETRY_INTERVAL,
206
JMSConstants.DEFAULT_INTERACT_RETRY_INTERVAL);
208
long timeoutTime = MapUtils.removeLongProperty(connectorConfig,
209
JMSConstants.TIMEOUT_TIME,
210
JMSConstants.DEFAULT_TIMEOUT_TIME);
212
String clientID = MapUtils.removeStringProperty(connectorConfig,
213
JMSConstants.CLIENT_ID,
215
String domain = MapUtils.removeStringProperty(connectorConfig,
217
JMSConstants.DOMAIN_DEFAULT);
219
// this will be set if the target endpoint address was set on the Axis call
220
JMSURLHelper jmsurl = (JMSURLHelper)connectorConfig.get(JMSConstants.JMS_URL);
223
throw new IllegalArgumentException("noCfConfig");
225
if(domain.equals(JMSConstants.DOMAIN_QUEUE))
227
return new QueueConnector(adapter.getQueueConnectionFactory(cfConfig),
228
numRetries, numSessions, connectRetryInterval,
229
interactRetryInterval, timeoutTime,
230
allowReceive, clientID, username, password,
233
else // domain is Topic
235
return new TopicConnector(adapter.getTopicConnectionFactory(cfConfig),
236
numRetries, numSessions, connectRetryInterval,
237
interactRetryInterval, timeoutTime,
238
allowReceive, clientID, username, password,
b'\\ No newline at end of file'