Skip to content

Commit 0b68373

Browse files
committed
Reduced ConnectionFactory's API, moving getDefaultClientProperties
over to AMQConnection; added more documentation; start from a filled-in table, rather than augmenting the table with other parameters at connect time, to permit inspection and modification of default values.
1 parent 27a914a commit 0b68373

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class ConnectionFactory implements Cloneable {
9898
private int requestedChannelMax = DEFAULT_CHANNEL_MAX;
9999
private int requestedFrameMax = DEFAULT_FRAME_MAX;
100100
private int requestedHeartbeat = DEFAULT_HEARTBEAT;
101-
private Map<String, Object> _clientProperties = getDefaultClientProperties();
101+
private Map<String, Object> _clientProperties = AMQConnection.defaultClientProperties();
102102
private SocketFactory factory = SocketFactory.getDefault();
103103

104104
/**
@@ -238,25 +238,23 @@ public void setRequestedHeartbeat(int requestedHeartbeat) {
238238
}
239239

240240
/**
241-
* Retrieve the default table of extra client properties to be sent to the
242-
* server.
243-
* @return the map of extra client properties
244-
*/
245-
public static Map<String, Object> getDefaultClientProperties() {
246-
return new HashMap<String, Object>();
247-
}
248-
249-
/**
250-
* Retrieve the map of extra client properties to be sent to the server
251-
* @return the map of extra client properties
241+
* Retrieve the currently-configured table of client properties
242+
* that will be sent to the server during connection
243+
* startup. Clients may add, delete, and alter keys in this
244+
* table. Such changes will take effect when the next new
245+
* connection is started using this factory.
246+
* @return the map of client properties
247+
* @see setClientProperties()
252248
*/
253249
public Map<String, Object> getClientProperties() {
254250
return _clientProperties;
255251
}
256252

257253
/**
258-
* Set the extra client properties to be sent to the server
254+
* Replace the table of client properties that will be sent to the
255+
* server during subsequent connection startups.
259256
* @param clientProperties the map of extra client properties
257+
* @see getClientProperties()
260258
*/
261259
public void setClientProperties(Map<String, Object> clientProperties) {
262260
_clientProperties = clientProperties;

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,27 @@ public class AMQConnection extends ShutdownNotifierComponent implements Connecti
7373
/** Timeout used while waiting for a connection.close-ok (milliseconds) */
7474
public static final int CONNECTION_CLOSING_TIMEOUT = 10000;
7575

76-
private static final Object[] DEFAULT_CLIENT_PROPERTIES_ARRAY =
77-
new Object[] {
78-
"product", LongStringHelper.asLongString("RabbitMQ"),
79-
"version", LongStringHelper.asLongString(ClientVersion.VERSION),
80-
"platform", LongStringHelper.asLongString("Java"),
81-
"copyright", LongStringHelper.asLongString(
82-
"Copyright (C) 2007-2008 LShift Ltd., " +
83-
"Cohesive Financial Technologies LLC., " +
84-
"and Rabbit Technologies Ltd."),
85-
"information", LongStringHelper.asLongString(
86-
"Licensed under the MPL. " +
87-
"See http://www.rabbitmq.com/")
88-
};
76+
/**
77+
* Retrieve a copy of the default table of client properties that
78+
* will be sent to the server during connection startup. This
79+
* method is called when each new ConnectionFactory instance is
80+
* constructed.
81+
* @return a map of client properties
82+
* @see Connection.getClientProperties()
83+
*/
84+
public static Map<String, Object> defaultClientProperties() {
85+
return Frame.buildTable(new Object[] {
86+
"product", LongStringHelper.asLongString("RabbitMQ"),
87+
"version", LongStringHelper.asLongString(ClientVersion.VERSION),
88+
"platform", LongStringHelper.asLongString("Java"),
89+
"copyright", LongStringHelper.asLongString(
90+
"Copyright (C) 2007-2008 LShift Ltd., " +
91+
"Cohesive Financial Technologies LLC., " +
92+
"and Rabbit Technologies Ltd."),
93+
"information", LongStringHelper.asLongString(
94+
"Licensed under the MPL. See http://www.rabbitmq.com/")
95+
});
96+
}
8997

9098
private static final Version clientVersion =
9199
new Version(AMQP.PROTOCOL.MAJOR, AMQP.PROTOCOL.MINOR);
@@ -218,8 +226,7 @@ public AMQConnection(ConnectionFactory factory,
218226
_requestedChannelMax = factory.getRequestedChannelMax();
219227
_requestedFrameMax = factory.getRequestedFrameMax();
220228
_requestedHeartbeat = factory.getRequestedHeartbeat();
221-
_clientProperties =
222-
buildClientPropertiesTable(factory.getClientProperties());
229+
_clientProperties = new HashMap<String, Object>(factory.getClientProperties());
223230

224231
this.factory = factory;
225232
_frameHandler = frameHandler;
@@ -414,14 +421,6 @@ public void writeFrame(Frame f) throws IOException {
414421
_lastActivityTime = System.nanoTime();
415422
}
416423

417-
private static Map<String, Object> buildClientPropertiesTable(
418-
Map<String, Object> extraClientProperties) {
419-
Map<String, Object> props =
420-
Frame.buildTable(DEFAULT_CLIENT_PROPERTIES_ARRAY);
421-
props.putAll(extraClientProperties);
422-
return props;
423-
}
424-
425424
private static int negotiatedMaxValue(int clientValue, int serverValue) {
426425
return (clientValue == 0 || serverValue == 0) ?
427426
Math.max(clientValue, serverValue) :

0 commit comments

Comments
 (0)