Skip to content

Commit 79de5cf

Browse files
author
Steve Powell
committed
Make fields of *Properties final:
adjust constructors to set everything; fix final few places that reply on updates; add builder() method to produce a builder from a built properties object.
1 parent 2f07f29 commit 79de5cf

20 files changed

+86
-93
lines changed

codegen.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ def printReadProperties(c):
262262
for f in c.fields:
263263
(jfName, jfType, jfClass) = (java_field_name(f.name), java_field_type(spec, f.domain), java_class_name(f.domain))
264264
if jfType in java_scalar_types:
265-
print " if (this.%sIsSet) this.%s = reader.read%s();" % (jfName, jfName, jfClass)
265+
print " if (this.%sIsSet) { this.%s = reader.read%s(); }" % (jfName, jfName, jfClass)
266+
print " else { this.%s = %s; }" % (jfName, java_scalar_default(jfType))
266267
else:
267268
print " this.%s = %s_present ? reader.read%s() : null;" % (jfName, jfName, jfClass)
268269

@@ -354,15 +355,25 @@ def ctorParm(field):
354355

355356
print " }"
356357

358+
def printPropertiesBuilder(c):
359+
print
360+
print " public Builder builder() {"
361+
print " Builder builder = new Builder();"
362+
setFieldList = [ "%s(%s)" % (fn, fn)
363+
for fn in [ java_field_name(f.name)
364+
for f in c.fields if java_field_type(spec, f.domain) not in java_scalar_types ] ]
365+
print " builder.%s;" % ("\n .".join(setFieldList))
366+
for f in c.fields:
367+
if java_field_type(spec, f.domain) in java_scalar_types:
368+
fn = java_field_name(f.name)
369+
print " if (%sIsSet) { builder.%s(%s); }" % (fn, fn, fn)
370+
print " return builder;"
371+
print " }"
372+
357373
def printPropertiesClass(c):
358-
def printGetterAndSetter(fieldType, fieldName):
374+
def printGetter(fieldType, fieldName):
359375
capFieldName = fieldName[0].upper() + fieldName[1:]
360376
print " public %s get%s() { return this.%s; }" % (fieldType, capFieldName, fieldName)
361-
if fieldType in java_scalar_types:
362-
print " public void set%s(%s %s)" % (capFieldName, fieldType, fieldName)
363-
print " { this.%s = %s; this.%sIsSet = true; }" % (fieldName, fieldName, fieldName)
364-
else:
365-
print " public void set%s(%s %s) { this.%s = %s; }" % (capFieldName, fieldType, fieldName, fieldName, fieldName)
366377

367378
jClassName = java_class_name(c.name)
368379

@@ -372,8 +383,8 @@ def printGetterAndSetter(fieldType, fieldName):
372383
for f in c.fields:
373384
(fType, fName) = (java_field_type(spec, f.domain), java_field_name(f.name))
374385
if fType in java_scalar_types:
375-
print " private boolean %sIsSet = false;" % (fName)
376-
print " private %s %s;" % (fType, fName)
386+
print " private final boolean %sIsSet;" % (fName)
387+
print " private final %s %s;" % (fType, fName)
377388

378389
#explicit constructor
379390
if c.fields:
@@ -409,10 +420,12 @@ def printGetterAndSetter(fieldType, fieldName):
409420
print " public int getClassId() { return %i; }" % (c.index)
410421
print " public String getClassName() { return \"%s\"; }" % (c.name)
411422

423+
printPropertiesBuilder(c)
424+
412425
#accessor methods
413426
print
414427
for f in c.fields:
415-
printGetterAndSetter(java_field_type(spec, f.domain), java_field_name(f.name))
428+
printGetter(java_field_type(spec, f.domain), java_field_name(f.name))
416429

417430
printWritePropertiesTo(c)
418431
printAppendArgumentDebugStringTo(c)

src/com/rabbitmq/client/RpcClient.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,8 @@ public byte[] primitiveCall(AMQP.BasicProperties props, byte[] message)
158158
synchronized (_continuationMap) {
159159
_correlationId++;
160160
String replyId = "" + _correlationId;
161-
if (props != null) {
162-
props.setCorrelationId(replyId);
163-
props.setReplyTo(_replyQueue);
164-
}
165-
else {
166-
props = new AMQP.BasicProperties(null, null, null, null,
167-
null, replyId,
168-
_replyQueue, null, null, null,
169-
null, null, null, null);
170-
}
161+
props = ((props==null) ? new AMQP.BasicProperties.Builder() : props.builder())
162+
.correlationId(replyId).replyTo(_replyQueue).build();
171163
_continuationMap.put(replyId, k);
172164
}
173165
publish(props, message);

src/com/rabbitmq/client/RpcServer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ public void processRequest(QueueingConsumer.Delivery request)
148148
AMQP.BasicProperties replyProperties
149149
= new AMQP.BasicProperties.Builder().correlationId(correlationId).build();
150150
byte[] replyBody = handleCall(request, replyProperties);
151-
replyProperties.setCorrelationId(correlationId);
152-
_channel.basicPublish("", replyTo,
153-
replyProperties, replyBody);
151+
_channel.basicPublish("", replyTo, replyProperties, replyBody);
154152
} else {
155153
handleCast(request);
156154
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// Copyright (c) 2007-2011 VMware, Inc. All rights reserved.
1515
//
1616

17-
1817
package com.rabbitmq.tools.jsonrpc;
1918

2019
import java.io.IOException;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ public JsonRpcServer(Channel channel,
100100
*/
101101
public String handleStringCall(String requestBody, AMQP.BasicProperties replyProperties)
102102
{
103-
replyProperties.setContentType("application/json");
104103
String replyBody = doCall(requestBody);
105-
//System.err.println(requestBody + " --> " + replyBody);
106104
return replyBody;
107105
}
108106

test/src/com/rabbitmq/client/test/ValueOrExceptionTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
public class ValueOrExceptionTest extends TestCase {
2727
public static class InsufficientMagicException extends Exception
2828
implements SensibleClone<InsufficientMagicException> {
29-
public InsufficientMagicException(String message) {
29+
/** Default for no check. */
30+
private static final long serialVersionUID = 1L;
31+
32+
public InsufficientMagicException(String message) {
3033
super(message);
3134
}
3235

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
package com.rabbitmq.client.test.functional;
1919

20-
import com.rabbitmq.client.test.BrokerTestCase;
21-
import com.rabbitmq.client.AMQP;
22-
import com.rabbitmq.client.ShutdownSignalException;
2320
import java.io.IOException;
2421

22+
import com.rabbitmq.client.AMQP;
23+
import com.rabbitmq.client.test.BrokerTestCase;
24+
2525
public class DoubleDeletion extends BrokerTestCase
2626
{
2727
protected static final String Q = "DoubleDeletionQueue";

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.IOException;
2121

2222
import com.rabbitmq.client.AMQP;
23-
import com.rabbitmq.client.ShutdownSignalException;
2423
import com.rabbitmq.client.test.BrokerTestCase;
2524

2625
/* Declare an exchange, bind a queue to it, then try to delete it,

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717

1818
package com.rabbitmq.client.test.functional;
1919

20-
import com.rabbitmq.client.AMQP;
21-
import com.rabbitmq.client.GetResponse;
22-
import com.rabbitmq.client.QueueingConsumer;
23-
2420
import java.util.HashSet;
2521
import java.util.Set;
2622

23+
import com.rabbitmq.client.AMQP;
24+
import com.rabbitmq.client.QueueingConsumer;
25+
2726
public class Nack extends AbstractRejectTest {
2827

2928
public void testSingleNack() throws Exception {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ public void testNoRequeueOnCancel()
4040
channel.basicPublish("", Q, null, "1".getBytes());
4141

4242
QueueingConsumer c;
43-
QueueingConsumer.Delivery d;
4443

4544
c = new QueueingConsumer(channel);
4645
String consumerTag = channel.basicConsume(Q, false, c);
47-
d = c.nextDelivery();
46+
c.nextDelivery();
4847
channel.basicCancel(consumerTag);
4948

5049
assertNull(channel.basicGet(Q, true));

0 commit comments

Comments
 (0)