Skip to content

Commit 92459ca

Browse files
author
Tim Watson
committed
merge default
2 parents 7da61d7 + a82d39d commit 92459ca

File tree

18 files changed

+361
-239
lines changed

18 files changed

+361
-239
lines changed

pom.xml

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,8 @@
2929

3030
<developers>
3131
<developer>
32-
<id>matthias.radestock</id>
33-
<name>Matthias Radestock</name>
34-
<roles>
35-
<role>Developer</role>
36-
</roles>
37-
</developer>
38-
<developer>
39-
<id>tonyg</id>
40-
<name>Tony Garnock-Jones</name>
41-
<roles>
42-
<role>Developer</role>
43-
</roles>
44-
</developer>
45-
<developer>
46-
<id>matthew.sackman</id>
47-
<name>Matthias Sackman</name>
48-
<roles>
49-
<role>Developer</role>
50-
</roles>
51-
</developer>
52-
<developer>
53-
<id>david.maciver</id>
54-
<name>David MacIver</name>
55-
<roles>
56-
<role>Developer</role>
57-
</roles>
58-
</developer>
59-
<developer>
60-
<id>paul.jones</id>
61-
<name>Paul Jones</name>
32+
<id>rabbitmq.team</id>
33+
<name>The RabbitMQ Team</name>
6234
<roles>
6335
<role>Developer</role>
6436
</roles>

src/com/rabbitmq/client/Channel.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public interface Channel extends ShutdownNotifier {
231231
void basicQos(int prefetchCount) throws IOException;
232232

233233
/**
234-
* Publish a message with both "mandatory" and "immediate" flags set to false
234+
* Publish a message
235235
* @see com.rabbitmq.client.AMQP.Basic.Publish
236236
* @param exchange the exchange to publish the message to
237237
* @param routingKey the routing key
@@ -246,8 +246,22 @@ public interface Channel extends ShutdownNotifier {
246246
* @see com.rabbitmq.client.AMQP.Basic.Publish
247247
* @param exchange the exchange to publish the message to
248248
* @param routingKey the routing key
249-
* @param mandatory true if we are requesting a mandatory publish
250-
* @param immediate true if we are requesting an immediate publish
249+
* @param mandatory true if the 'mandatory' flag is to be set
250+
* @param props other properties for the message - routing headers etc
251+
* @param body the message body
252+
* @throws java.io.IOException if an error is encountered
253+
*/
254+
void basicPublish(String exchange, String routingKey, boolean mandatory, BasicProperties props, byte[] body)
255+
throws IOException;
256+
257+
/**
258+
* Publish a message
259+
* @see com.rabbitmq.client.AMQP.Basic.Publish
260+
* @param exchange the exchange to publish the message to
261+
* @param routingKey the routing key
262+
* @param mandatory true if the 'mandatory' flag is to be set
263+
* @param immediate true if the 'immediate' flag is to be
264+
* set. Note that the RabbitMQ server does not support this flag.
251265
* @param props other properties for the message - routing headers etc
252266
* @param body the message body
253267
* @throws java.io.IOException if an error is encountered

src/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.rabbitmq.client.SaslConfig;
4242
import com.rabbitmq.client.SaslMechanism;
4343
import com.rabbitmq.client.ShutdownSignalException;
44+
import com.rabbitmq.client.impl.AMQChannel.BlockingRpcContinuation;
4445
import com.rabbitmq.utility.BlockingCell;
4546
import com.rabbitmq.utility.Utility;
4647

@@ -663,6 +664,16 @@ public ShutdownSignalException shutdown(Object reason,
663664
boolean initiatedByApplication,
664665
Throwable cause,
665666
boolean notifyRpc)
667+
{
668+
ShutdownSignalException sse = startShutdown(reason, initiatedByApplication, cause, notifyRpc);
669+
finishShutdown(sse);
670+
return sse;
671+
}
672+
673+
private ShutdownSignalException startShutdown(Object reason,
674+
boolean initiatedByApplication,
675+
Throwable cause,
676+
boolean notifyRpc)
666677
{
667678
ShutdownSignalException sse = new ShutdownSignalException(true,initiatedByApplication,
668679
reason, this);
@@ -677,10 +688,12 @@ public ShutdownSignalException shutdown(Object reason,
677688

678689
_channel0.processShutdownSignal(sse, !initiatedByApplication, notifyRpc);
679690

691+
return sse;
692+
}
693+
694+
private void finishShutdown(ShutdownSignalException sse) {
680695
ChannelManager cm = _channelManager;
681696
if (cm != null) cm.handleSignal(sse);
682-
683-
return sse;
684697
}
685698

686699
/** Public API - {@inheritDoc} */
@@ -775,10 +788,15 @@ public void close(int closeCode,
775788
.replyText(closeMessage)
776789
.build();
777790

778-
shutdown(reason, initiatedByApplication, cause, true);
791+
final ShutdownSignalException sse = startShutdown(reason, initiatedByApplication, cause, true);
779792
if(sync){
780-
AMQChannel.SimpleBlockingRpcContinuation k =
781-
new AMQChannel.SimpleBlockingRpcContinuation();
793+
BlockingRpcContinuation<AMQCommand> k = new BlockingRpcContinuation<AMQCommand>(){
794+
@Override
795+
public AMQCommand transformReply(AMQCommand command) {
796+
AMQConnection.this.finishShutdown(sse);
797+
return command;
798+
}};
799+
782800
_channel0.quiescingRpc(reason, k);
783801
k.getReply(timeout);
784802
} else {

src/com/rabbitmq/client/impl/ChannelN.java

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,32 +239,51 @@ public void setDefaultConsumer(Consumer consumer) {
239239

240240
/**
241241
* Sends a ShutdownSignal to all active consumers.
242+
* Idempotent.
242243
* @param signal an exception signalling channel shutdown
243244
*/
244-
private CountDownLatch broadcastShutdownSignal(ShutdownSignalException signal) {
245+
private void broadcastShutdownSignal(ShutdownSignalException signal) {
245246
Map<String, Consumer> snapshotConsumers;
246247
synchronized (_consumers) {
247248
snapshotConsumers = new HashMap<String, Consumer>(_consumers);
248249
}
249-
return this.dispatcher.handleShutdownSignal(snapshotConsumers, signal);
250+
this.finishedShutdownFlag = this.dispatcher.handleShutdownSignal(snapshotConsumers, signal);
250251
}
251252

252253
/**
253-
* Protected API - overridden to quiesce consumer work and broadcast the signal
254-
* to all consumers after calling the superclass's method.
254+
* Start to shutdown -- defer rest of processing until ready
255255
*/
256-
@Override public void processShutdownSignal(ShutdownSignalException signal,
256+
private void startProcessShutdownSignal(ShutdownSignalException signal,
257257
boolean ignoreClosed,
258258
boolean notifyRpc)
259+
{ super.processShutdownSignal(signal, ignoreClosed, notifyRpc);
260+
}
261+
262+
/**
263+
* Finish shutdown processing -- idempotent
264+
*/
265+
private void finishProcessShutdownSignal()
259266
{
260267
this.dispatcher.quiesce();
261-
super.processShutdownSignal(signal, ignoreClosed, notifyRpc);
262-
this.finishedShutdownFlag = broadcastShutdownSignal(signal);
268+
broadcastShutdownSignal(getCloseReason());
269+
263270
synchronized (unconfirmedSet) {
264271
unconfirmedSet.notifyAll();
265272
}
266273
}
267274

275+
/**
276+
* Protected API - overridden to quiesce consumer work and broadcast the signal
277+
* to all consumers after calling the superclass's method.
278+
*/
279+
@Override public void processShutdownSignal(ShutdownSignalException signal,
280+
boolean ignoreClosed,
281+
boolean notifyRpc)
282+
{
283+
startProcessShutdownSignal(signal, ignoreClosed, notifyRpc);
284+
finishProcessShutdownSignal();
285+
}
286+
268287
CountDownLatch getShutdownLatch() {
269288
return this.finishedShutdownFlag;
270289
}
@@ -526,13 +545,18 @@ public void close(int closeCode,
526545
signal.initCause(cause);
527546
}
528547

529-
BlockingRpcContinuation<AMQCommand> k = new SimpleBlockingRpcContinuation();
548+
BlockingRpcContinuation<AMQCommand> k = new BlockingRpcContinuation<AMQCommand>(){
549+
@Override
550+
public AMQCommand transformReply(AMQCommand command) {
551+
ChannelN.this.finishProcessShutdownSignal();
552+
return command;
553+
}};
530554
boolean notify = false;
531555
try {
532556
// Synchronize the block below to avoid race conditions in case
533557
// connnection wants to send Connection-CloseOK
534558
synchronized (_channelMutex) {
535-
processShutdownSignal(signal, !initiatedByApplication, true);
559+
startProcessShutdownSignal(signal, !initiatedByApplication, true);
536560
quiescingRpc(reason, k);
537561
}
538562

@@ -581,7 +605,16 @@ public void basicPublish(String exchange, String routingKey,
581605
BasicProperties props, byte[] body)
582606
throws IOException
583607
{
584-
basicPublish(exchange, routingKey, false, false, props, body);
608+
basicPublish(exchange, routingKey, false, props, body);
609+
}
610+
611+
/** Public API - {@inheritDoc} */
612+
public void basicPublish(String exchange, String routingKey,
613+
boolean mandatory,
614+
BasicProperties props, byte[] body)
615+
throws IOException
616+
{
617+
basicPublish(exchange, routingKey, mandatory, false, props, body);
585618
}
586619

587620
/** Public API - {@inheritDoc} */

src/com/rabbitmq/client/impl/ConsumerDispatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Dispatches notifications to a {@link Consumer} on an internally-managed executor service and work
3131
* pool.
3232
* <p/>
33-
* Each {@link Channel} has a single {@link ConsumerDispatcher}, but the executor service and work
33+
* Each {@link Channel} has a single <code>ConsumerDispatcher</code>, but the executor service and work
3434
* pool may be shared with other channels, typically those on the same {@link AMQConnection}.
3535
*/
3636
final class ConsumerDispatcher {

src/com/rabbitmq/client/impl/WorkPool.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,16 @@ private static <W> int drainTo(LinkedList<W> deList, Collection<W> c, int maxEle
164164
* @param item the work item to add to the client queue
165165
* @return <code><b>true</b></code> if and only if the client is marked <i>ready</i>
166166
* &mdash; <i>as a result of this work item</i>
167-
* @throws IllegalArgumentException if key not registered.
168167
*/
169168
public boolean addWorkItem(K key, W item) {
170169
synchronized (this.monitor) {
171170
Queue<W> queue = this.pool.get(key);
172-
if (queue == null) {
173-
throw new IllegalArgumentException("Client " + key + " not registered");
174-
}
175-
queue.offer(item);
176-
if (isDormant(key)) {
177-
dormantToReady(key);
178-
return true;
171+
if (queue != null) {
172+
queue.offer(item);
173+
if (isDormant(key)) {
174+
dormantToReady(key);
175+
return true;
176+
}
179177
}
180178
return false;
181179
}

src/com/rabbitmq/tools/jsonrpc/JsonRpcClient.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@
3131
import com.rabbitmq.tools.json.JSONWriter;
3232

3333
/**
34-
<a
35-
href="http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html">JSON-RPC</a>
36-
is a lightweight RPC mechanism using <a
37-
href="http://www.json.org/">JSON</a> as a data language for
38-
request and reply messages. It is rapidly becoming a
39-
standard in web development, where it is used to make RPC
40-
requests over HTTP. RabbitMQ provides an AMQP transport
41-
binding for JSON-RPC in the form of
42-
the <code>JsonRpcClient</code> class.
34+
<a href="http://json-rpc.org">JSON-RPC</a> is a lightweight
35+
RPC mechanism using <a href="http://www.json.org/">JSON</a>
36+
as a data language for request and reply messages. It is
37+
rapidly becoming a standard in web development, where it is
38+
used to make RPC requests over HTTP. RabbitMQ provides an
39+
AMQP transport binding for JSON-RPC in the form of the
40+
<code>JsonRpcClient</code> class.
4341
4442
JSON-RPC services are self-describing - each service is able
4543
to list its supported procedures, and each procedure

src/com/rabbitmq/utility/IntAllocator.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@
2828
* <p/><b>Implementation notes:</b>
2929
* <br/>This was originally an ordered chain of non-overlapping Intervals,
3030
* together with a fixed size array cache for freed integers.
31-
* <br/>{@link #reserve()} was expensive in this scheme, whereas in the
32-
* present implementation it is O(1), as is {@link #free()}.
33-
* <br/>Although {@link #allocate()} is slightly slower than O(1) and in the
34-
* worst case could be O(N), the use of the {@link #lastIndex} field
31+
* <br/>{@link #reserve(int)} was expensive in this scheme, whereas in the
32+
* present implementation it is O(1), as is {@link #free(int)}.
33+
* <p>Although {@link #allocate()} is slightly slower than O(1) and in the
34+
* worst case could be O(N), the use of a "<code>lastIndex</code>" field
3535
* for starting the next scan for free integers means this is negligible.
36-
* <br/>The data representation overhead is O(N) where N is the size of the
36+
* </p>
37+
* <p>The data representation overhead is O(N) where N is the size of the
3738
* allocation range. One <code>long</code> is used for every 64 integers in the
3839
* range.
39-
* <br/>Very little Object creation and destruction occurs in use.
40+
* </p>
41+
* <p>Very little Object creation and destruction occurs in use.</p>
4042
*/
4143
public class IntAllocator {
4244

4345
private final int loRange; // the integer bit 0 represents
44-
private final int hiRange; // the integer(+1) the highest bit represents
46+
private final int hiRange; // one more than the integer the highest bit represents
4547
private final int numberOfBits; // relevant in freeSet
4648
private int lastIndex = 0; // for searching for FREE integers
4749
/** A bit is SET in freeSet if the corresponding integer is FREE

test/src/com/rabbitmq/client/impl/WorkPoolTests.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ public class WorkPoolTests extends TestCase {
1313
private WorkPool<String, Object> pool = new WorkPool<String, Object>();
1414

1515
/**
16-
* Test that an unknown key is rejected.
16+
* Test unknown key tolerated silently
17+
* @throws Exception untested
1718
*/
18-
public void testUnkownKey() {
19-
try {
20-
this.pool.addWorkItem("test", new Object());
21-
fail("Expected IllegalArgumentException");
22-
} catch (IllegalArgumentException e) {
23-
// expected
24-
}
19+
public void testUnknownKey() throws Exception{
20+
assertFalse(this.pool.addWorkItem("test", new Object()));
2521
}
2622

2723
/**
28-
* Test basic add work and remove work.
24+
* Test add work and remove work
2925
* @throws Exception untested
3026
*/
3127
public void testBasicInOut() throws Exception {

test/src/com/rabbitmq/client/test/functional/AlternateExchange.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,36 +139,35 @@ protected void checkGet(boolean[] expected) throws IOException {
139139
*
140140
* @param key the routing key of the message to be sent
141141
* @param mandatory whether the message should be marked as 'mandatory'
142-
* @param immediate whether the message should be marked as 'immediate'
143142
* @param expected indicates which queues we expect the message to
144143
* get routed to
145144
* @param ret whether a 'basic.return' is expected
146145
*
147146
* @see #checkGet(boolean[])
148147
*/
149-
protected void check(String key, boolean mandatory, boolean immediate,
150-
boolean[] expected, boolean ret)
148+
protected void check(String key, boolean mandatory, boolean[] expected,
149+
boolean ret)
151150
throws IOException {
152151

153152
gotReturn.set(false);
154-
channel.basicPublish("x", key, mandatory, immediate, null,
153+
channel.basicPublish("x", key, mandatory, false, null,
155154
"ae-test".getBytes());
156155
checkGet(expected);
157156
assertEquals(ret, gotReturn.get());
158157
}
159158

160159
protected void check(String key, boolean[] expected, boolean ret)
161160
throws IOException {
162-
check(key, false, false, expected, ret);
161+
check(key, false, expected, ret);
163162
}
164163

165-
protected void check(String key, boolean mandatory, boolean immediate,
166-
boolean ret) throws IOException {
167-
check(key, mandatory, immediate, expected(key), ret);
164+
protected void check(String key, boolean mandatory, boolean ret)
165+
throws IOException {
166+
check(key, mandatory, expected(key), ret);
168167
}
169168

170169
protected void check(String key, boolean ret) throws IOException {
171-
check(key, false, false, ret);
170+
check(key, false, ret);
172171
}
173172

174173
/**
@@ -198,9 +197,7 @@ public void testAe() throws IOException {
198197
//ordinary
199198
check(k, false);
200199
//mandatory
201-
check(k, true, false, k.equals("z"));
202-
//immediate
203-
check(k, false, true, unrouted, true);
200+
check(k, true, k.equals("z"));
204201
}
205202

206203
cleanup();

0 commit comments

Comments
 (0)