Method from org.apache.activemq.camel.component.CamelEndpointLoader Detail: |
protected void addQueue(ActiveMQQueue queue) throws Exception {
String queueUri = getQueueUri(queue);
ActiveMQComponent jmsComponent = getComponent();
Endpoint endpoint = new JmsQueueEndpoint(queueUri, jmsComponent, queue.getPhysicalName(), jmsComponent.getConfiguration());
camelContext.addEndpoint(queueUri, endpoint);
}
|
protected void addTopic(ActiveMQTopic topic) throws Exception {
String topicUri = getTopicUri(topic);
ActiveMQComponent jmsComponent = getComponent();
Endpoint endpoint = new JmsEndpoint(topicUri, jmsComponent, topic.getPhysicalName(), true, jmsComponent.getConfiguration());
camelContext.addEndpoint(topicUri, endpoint);
}
|
public void afterPropertiesSet() throws Exception {
ObjectHelper.notNull(camelContext, "camelContext");
if (connection == null) {
Connection value = getConnectionFactory().createConnection();
if (value instanceof EnhancedConnection) {
connection = (EnhancedConnection) value;
}
else {
throw new IllegalArgumentException("Created JMS Connection is not an EnhancedConnection: " + value);
}
}
connection.start();
DestinationSource source = connection.getDestinationSource();
source.setDestinationListener(new DestinationListener() {
public void onDestinationEvent(DestinationEvent event) {
try {
ActiveMQDestination destination = event.getDestination();
if (destination instanceof ActiveMQQueue) {
ActiveMQQueue queue = (ActiveMQQueue) destination;
if (event.isAddOperation()) {
addQueue(queue);
}
else {
removeQueue(queue);
}
}
else if (destination instanceof ActiveMQTopic) {
ActiveMQTopic topic = (ActiveMQTopic) destination;
if (event.isAddOperation()) {
addTopic(topic);
}
else {
removeTopic(topic);
}
}
}
catch (Exception e) {
LOG.warn("Caught: " + e, e);
}
}
});
Set< ActiveMQQueue > queues = source.getQueues();
for (ActiveMQQueue queue : queues) {
addQueue(queue);
}
Set< ActiveMQTopic > topics = source.getTopics();
for (ActiveMQTopic topic : topics) {
addTopic(topic);
}
}
|
public void destroy() throws Exception {
if (connection != null) {
connection.close();
connection = null;
}
}
|
public CamelContext getCamelContext() {
return camelContext;
}
|
public ActiveMQComponent getComponent() {
if (component == null) {
component = camelContext.getComponent("activemq", ActiveMQComponent.class);
}
return component;
}
|
public EnhancedConnection getConnection() {
return connection;
}
|
public ConnectionFactory getConnectionFactory() {
if (connectionFactory == null
&& getComponent().getConfiguration() instanceof ActiveMQConfiguration) {
connectionFactory = ((ActiveMQConfiguration) getComponent()
.getConfiguration()).createConnectionFactory();
}
return connectionFactory;
}
|
protected String getQueueUri(ActiveMQQueue queue) {
return "activemq:" + queue.getPhysicalName();
}
|
protected String getTopicUri(ActiveMQTopic topic) {
return "activemq:topic:" + topic.getPhysicalName();
}
|
protected void removeQueue(ActiveMQQueue queue) throws Exception {
String queueUri = getQueueUri(queue);
camelContext.removeEndpoints(queueUri);
}
|
protected void removeTopic(ActiveMQTopic topic) throws Exception {
String topicUri = getTopicUri(topic);
camelContext.removeEndpoints(topicUri);
}
|
public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}
|
public void setComponent(ActiveMQComponent component) {
this.component = component;
}
|
public void setConnectionFactory(ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
|