A factory of the ActiveMQ InitialContext which contains
which contain all of the current active destinations, in
child context depending on the QoS such as transient or durable and queue or
topic.
| Method from org.apache.activemq.jndi.ActiveMQInitialContextFactory Detail: |
protected ActiveMQConnectionFactory createConnectionFactory(Hashtable environment) throws URISyntaxException {
ActiveMQConnectionFactory answer = new ActiveMQConnectionFactory();
Properties properties = new Properties();
properties.putAll(environment);
answer.setProperties(properties);
return answer;
}
Factory method to create a new connection factory from the given
environment |
protected ActiveMQConnectionFactory createConnectionFactory(String name,
Hashtable environment) throws URISyntaxException {
Hashtable temp = new Hashtable(environment);
String prefix = connectionPrefix + name + ".";
for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry)iter.next();
String key = (String)entry.getKey();
if (key.startsWith(prefix)) {
// Rename the key...
temp.remove(key);
key = key.substring(prefix.length());
temp.put(key, entry.getValue());
}
}
return createConnectionFactory(temp);
}
|
protected ReadOnlyContext createContext(Hashtable environment,
Map data) {
return new ReadOnlyContext(environment, data);
}
|
protected Queue createQueue(String name) {
return new ActiveMQQueue(name);
}
Factory method to create new Queue instances |
protected void createQueues(Map data,
Hashtable environment) {
for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry)iter.next();
String key = entry.getKey().toString();
if (key.startsWith(queuePrefix)) {
String jndiName = key.substring(queuePrefix.length());
data.put(jndiName, createQueue(entry.getValue().toString()));
}
}
}
|
protected Topic createTopic(String name) {
return new ActiveMQTopic(name);
}
Factory method to create new Topic instances |
protected void createTopics(Map data,
Hashtable environment) {
for (Iterator iter = environment.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry)iter.next();
String key = entry.getKey().toString();
if (key.startsWith(topicPrefix)) {
String jndiName = key.substring(topicPrefix.length());
data.put(jndiName, createTopic(entry.getValue().toString()));
}
}
}
|
protected String[] getConnectionFactoryNames(Map environment) {
String factoryNames = (String)environment.get("connectionFactoryNames");
if (factoryNames != null) {
List< String > list = new ArrayList< String >();
for (StringTokenizer enumeration = new StringTokenizer(factoryNames, ","); enumeration.hasMoreTokens();) {
list.add(enumeration.nextToken().trim());
}
int size = list.size();
if (size > 0) {
String[] answer = new String[size];
list.toArray(answer);
return answer;
}
}
return DEFAULT_CONNECTION_FACTORY_NAMES;
}
|
public String getConnectionPrefix() {
return connectionPrefix;
}
|
public Context getInitialContext(Hashtable environment) throws NamingException {
// lets create a factory
Map< String, Object > data = new ConcurrentHashMap< String, Object >();
String[] names = getConnectionFactoryNames(environment);
for (int i = 0; i < names.length; i++) {
ActiveMQConnectionFactory factory = null;
String name = names[i];
try {
factory = createConnectionFactory(name, environment);
} catch (Exception e) {
throw new NamingException("Invalid broker URL");
}
/*
* if( broker==null ) { try { broker = factory.getEmbeddedBroker(); }
* catch (JMSException e) { log.warn("Failed to get embedded
* broker", e); } }
*/
data.put(name, factory);
}
createQueues(data, environment);
createTopics(data, environment);
/*
* if (broker != null) { data.put("destinations",
* broker.getDestinationContext(environment)); }
*/
data.put("dynamicQueues", new LazyCreateContext() {
private static final long serialVersionUID = 6503881346214855588L;
protected Object createEntry(String name) {
return new ActiveMQQueue(name);
}
});
data.put("dynamicTopics", new LazyCreateContext() {
private static final long serialVersionUID = 2019166796234979615L;
protected Object createEntry(String name) {
return new ActiveMQTopic(name);
}
});
return createContext(environment, data);
}
|
public String getQueuePrefix() {
return queuePrefix;
}
|
public String getTopicPrefix() {
return topicPrefix;
}
|
public void setConnectionPrefix(String connectionPrefix) {
this.connectionPrefix = connectionPrefix;
}
|
public void setQueuePrefix(String queuePrefix) {
this.queuePrefix = queuePrefix;
}
|
public void setTopicPrefix(String topicPrefix) {
this.topicPrefix = topicPrefix;
}
|