View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.jms.integration.activemq;
8   
9   import org.mule.transport.jms.integration.JmsVendorConfiguration;
10  
11  import java.util.Collections;
12  import java.util.Map;
13  
14  import javax.jms.Connection;
15  import javax.jms.ConnectionFactory;
16  
17  import org.apache.activemq.ActiveMQConnectionFactory;
18  import org.apache.activemq.ActiveMQXAConnectionFactory;
19  
20  /**
21   * Abstracts all the Jms Vendor specific configuration.  This is the implementation for ActiveMQ.
22   */
23  public class ActiveMQJmsConfiguration implements JmsVendorConfiguration
24  {
25      public static final String DEFAULT_BROKER_URL = "vm://localhost?broker.persistent=false&broker.useJmx=false";
26  
27      public void initialise(Class callingClass) throws Exception
28      {
29          // empty
30      }
31      
32      public Connection getConnection(boolean topic, boolean xa) throws Exception
33      {
34          if (xa)
35          {
36              return new ActiveMQXAConnectionFactory(DEFAULT_BROKER_URL).createConnection();
37  
38          }
39          else
40          {
41              return new ActiveMQConnectionFactory(DEFAULT_BROKER_URL).createConnection();
42          }
43      }
44  
45      public String getInboundEndpoint()
46      {
47          return getProtocol() + "://" + getInboundDestinationName();
48      }
49  
50      public String getOutboundEndpoint()
51      {
52          return getProtocol() + "://" + getOutboundDestinationName();
53      }
54  
55      public String getMiddleEndpoint()
56      {
57          return getProtocol() + "://" + getMiddleDestinationName();
58      }
59  
60      public String getTopicBroadcastEndpoint()
61      {
62          return getProtocol() + "://topic:" + getBroadcastDestinationName();
63      }
64  
65      public String getDeadLetterEndpoint()
66      {
67          return getProtocol() + "://" + getDeadLetterDestinationName();
68      }
69  
70      public String getInboundDestinationName()
71      {
72          return "in";
73      }
74  
75      public String getOutboundDestinationName()
76      {
77          return "out";
78      }
79  
80      public String getMiddleDestinationName()
81      {
82          return "middle";
83      }
84  
85      public String getBroadcastDestinationName()
86      {
87          return "broadcast";
88      }
89  
90      public String getDeadLetterDestinationName()
91      {
92          return "dlq";
93      }
94  
95      /**
96       * Timeout used when checking that a message is NOT present
97       */
98      public long getSmallTimeout()
99      {
100         return 1000L;
101     }
102 
103     /**
104      * The timeout used when waiting for a message to arrive
105      */
106     public long getTimeout()
107     {
108         return 5000L;
109     }
110 
111     public String getProtocol()
112     {
113         return "jms";
114     }
115 
116     public String getName()
117     {
118         return "activemq";
119     }
120 
121     public Map getProperties()
122     {
123         return Collections.EMPTY_MAP;
124     }
125 
126     public ConnectionFactory getTestConnectionFactory()
127     {
128         return new ActiveMQTestReconnectionConnectionFactoryWrapper();       
129     }
130     
131     public boolean isEnabled()
132     {
133         return true;
134     }
135 }