1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.jms; |
12 | |
|
13 | |
import javax.jms.Connection; |
14 | |
import javax.jms.ConnectionFactory; |
15 | |
import javax.jms.DeliveryMode; |
16 | |
import javax.jms.Destination; |
17 | |
import javax.jms.JMSException; |
18 | |
import javax.jms.Message; |
19 | |
import javax.jms.MessageConsumer; |
20 | |
import javax.jms.MessageProducer; |
21 | |
import javax.jms.Session; |
22 | |
import javax.jms.Topic; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class Jms11Support implements JmsSupport |
30 | |
{ |
31 | |
protected JmsConnector connector; |
32 | |
|
33 | |
public Jms11Support(JmsConnector connector) |
34 | 192 | { |
35 | 192 | this.connector = connector; |
36 | 192 | } |
37 | |
|
38 | |
public Connection createConnection(ConnectionFactory connectionFactory, String username, String password) |
39 | |
throws JMSException |
40 | |
{ |
41 | 0 | if (connectionFactory == null) |
42 | |
{ |
43 | 0 | throw new IllegalArgumentException("connectionFactory cannot be null"); |
44 | |
} |
45 | 0 | return connectionFactory.createConnection(username, password); |
46 | |
} |
47 | |
|
48 | |
public Connection createConnection(ConnectionFactory connectionFactory) throws JMSException |
49 | |
{ |
50 | 60 | if (connectionFactory == null) |
51 | |
{ |
52 | 0 | throw new IllegalArgumentException("connectionFactory cannot be null"); |
53 | |
} |
54 | 60 | return connectionFactory.createConnection(); |
55 | |
} |
56 | |
|
57 | |
public Session createSession(Connection connection, |
58 | |
boolean topic, |
59 | |
boolean transacted, |
60 | |
int ackMode, |
61 | |
boolean noLocal) throws JMSException |
62 | |
{ |
63 | 100 | return connection.createSession(transacted, (transacted ? Session.SESSION_TRANSACTED : ackMode)); |
64 | |
} |
65 | |
|
66 | |
public MessageProducer createProducer(Session session, Destination destination, boolean topic) |
67 | |
throws JMSException |
68 | |
{ |
69 | 32 | return session.createProducer(destination); |
70 | |
} |
71 | |
|
72 | |
public MessageConsumer createConsumer(Session session, Destination destination, boolean topic) |
73 | |
throws JMSException |
74 | |
{ |
75 | 2 | return createConsumer(session, destination, null, false, null, topic); |
76 | |
} |
77 | |
|
78 | |
public MessageConsumer createConsumer(Session session, |
79 | |
Destination destination, |
80 | |
String messageSelector, |
81 | |
boolean noLocal, |
82 | |
String durableName, |
83 | |
boolean topic) throws JMSException |
84 | |
{ |
85 | 78 | if (durableName == null) |
86 | |
{ |
87 | 62 | if (topic) |
88 | |
{ |
89 | 2 | return session.createConsumer(destination, messageSelector, noLocal); |
90 | |
} |
91 | |
else |
92 | |
{ |
93 | 60 | return session.createConsumer(destination, messageSelector); |
94 | |
} |
95 | |
} |
96 | |
else |
97 | |
{ |
98 | 16 | if (topic) |
99 | |
{ |
100 | 14 | return session.createDurableSubscriber((Topic) destination, durableName, messageSelector, |
101 | |
noLocal); |
102 | |
} |
103 | |
else |
104 | |
{ |
105 | 2 | throw new JMSException( |
106 | |
"A durable subscriber name was set but the destination was not a Topic"); |
107 | |
} |
108 | |
} |
109 | |
} |
110 | |
|
111 | |
public Destination createDestination(Session session, String name, boolean topic) throws JMSException |
112 | |
{ |
113 | 102 | if (session == null) |
114 | |
{ |
115 | 0 | throw new IllegalArgumentException("MuleSession cannot be null when creating a destination"); |
116 | |
} |
117 | 102 | if (name == null) |
118 | |
{ |
119 | 0 | throw new IllegalArgumentException("Destination name cannot be null when creating a destination"); |
120 | |
} |
121 | |
|
122 | 102 | if (topic) |
123 | |
{ |
124 | 18 | return session.createTopic(name); |
125 | |
} |
126 | |
else |
127 | |
{ |
128 | 84 | return session.createQueue(name); |
129 | |
} |
130 | |
} |
131 | |
|
132 | |
public Destination createTemporaryDestination(Session session, boolean topic) throws JMSException |
133 | |
{ |
134 | 0 | if (session == null) |
135 | |
{ |
136 | 0 | throw new IllegalArgumentException("MuleSession cannot be null when creating a destination"); |
137 | |
} |
138 | |
|
139 | 0 | if (topic) |
140 | |
{ |
141 | 0 | return session.createTemporaryTopic(); |
142 | |
} |
143 | |
else |
144 | |
{ |
145 | 0 | return session.createTemporaryQueue(); |
146 | |
} |
147 | |
} |
148 | |
|
149 | |
public void send(MessageProducer producer, Message message, boolean topic) throws JMSException |
150 | |
{ |
151 | 2 | send(producer, message, connector.isPersistentDelivery(), Message.DEFAULT_PRIORITY, |
152 | |
Message.DEFAULT_TIME_TO_LIVE, topic); |
153 | 2 | } |
154 | |
|
155 | |
public void send(MessageProducer producer, Message message, Destination dest, boolean topic) |
156 | |
throws JMSException |
157 | |
{ |
158 | 0 | send(producer, message, dest, connector.isPersistentDelivery(), Message.DEFAULT_PRIORITY, |
159 | |
Message.DEFAULT_TIME_TO_LIVE, topic); |
160 | 0 | } |
161 | |
|
162 | |
public void send(MessageProducer producer, |
163 | |
Message message, |
164 | |
boolean persistent, |
165 | |
int priority, |
166 | |
long ttl, |
167 | |
boolean topic) throws JMSException |
168 | |
{ |
169 | 32 | producer.send(message, (persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT), |
170 | |
priority, ttl); |
171 | 32 | } |
172 | |
|
173 | |
public void send(MessageProducer producer, |
174 | |
Message message, |
175 | |
Destination dest, |
176 | |
boolean persistent, |
177 | |
int priority, |
178 | |
long ttl, |
179 | |
boolean topic) throws JMSException |
180 | |
{ |
181 | 0 | producer.send(dest, message, (persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT), |
182 | |
priority, ttl); |
183 | 0 | } |
184 | |
|
185 | |
} |