View Javadoc

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