Skip to content

Commit b147716

Browse files
committed
Merge bug21949 into default
2 parents e76d8a2 + 0b68373 commit b147716

File tree

3 files changed

+71
-26
lines changed

3 files changed

+71
-26
lines changed

src/com/rabbitmq/client/Connection.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ public interface Connection extends ShutdownNotifier { // rename to AMQPConnecti
9090
*/
9191
int getHeartbeat();
9292

93+
/**
94+
* Get a copy of the map of client properties sent to the server
95+
*
96+
* @return a copy of the map of client properties
97+
*/
98+
Map<String, Object> getClientProperties();
99+
93100
/**
94101
* Retrieve the known hosts.
95102
* @return an array of addresses for all hosts that came back in the initial {@link com.rabbitmq.client.AMQP.Connection.OpenOk} open-ok method

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ public class ConnectionFactory implements Cloneable {
9090
*/
9191
public static final String DEFAULT_SSL_PROTOCOL = "SSLv3";
9292

93-
private String username = DEFAULT_USER;
94-
private String password = DEFAULT_PASS;
95-
private String virtualHost = DEFAULT_VHOST;
96-
private String host = DEFAULT_HOST;
97-
private int port = USE_DEFAULT_PORT;
98-
private int requestedChannelMax = DEFAULT_CHANNEL_MAX;
99-
private int requestedFrameMax = DEFAULT_FRAME_MAX;
100-
private int requestedHeartbeat = DEFAULT_HEARTBEAT;
101-
private SocketFactory factory = SocketFactory.getDefault();
93+
private String username = DEFAULT_USER;
94+
private String password = DEFAULT_PASS;
95+
private String virtualHost = DEFAULT_VHOST;
96+
private String host = DEFAULT_HOST;
97+
private int port = USE_DEFAULT_PORT;
98+
private int requestedChannelMax = DEFAULT_CHANNEL_MAX;
99+
private int requestedFrameMax = DEFAULT_FRAME_MAX;
100+
private int requestedHeartbeat = DEFAULT_HEARTBEAT;
101+
private Map<String, Object> _clientProperties = AMQConnection.defaultClientProperties();
102+
private SocketFactory factory = SocketFactory.getDefault();
102103

103104
/**
104105
* Instantiate a ConnectionFactory with a default set of parameters.
@@ -236,6 +237,29 @@ public void setRequestedHeartbeat(int requestedHeartbeat) {
236237
this.requestedHeartbeat = requestedHeartbeat;
237238
}
238239

240+
/**
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()
248+
*/
249+
public Map<String, Object> getClientProperties() {
250+
return _clientProperties;
251+
}
252+
253+
/**
254+
* Replace the table of client properties that will be sent to the
255+
* server during subsequent connection startups.
256+
* @param clientProperties the map of extra client properties
257+
* @see getClientProperties()
258+
*/
259+
public void setClientProperties(Map<String, Object> clientProperties) {
260+
_clientProperties = clientProperties;
261+
}
262+
239263
/**
240264
* Retrieve the socket factory used to make connections with.
241265
*/

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

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.IOException;
3636
import java.net.SocketException;
3737
import java.util.Map;
38+
import java.util.HashMap;
3839
import java.util.concurrent.TimeoutException;
3940

4041
import com.rabbitmq.client.AMQP;
@@ -72,6 +73,28 @@ public class AMQConnection extends ShutdownNotifierComponent implements Connecti
7273
/** Timeout used while waiting for a connection.close-ok (milliseconds) */
7374
public static final int CONNECTION_CLOSING_TIMEOUT = 10000;
7475

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+
}
97+
7598
private static final Version clientVersion =
7699
new Version(AMQP.PROTOCOL.MAJOR, AMQP.PROTOCOL.MINOR);
77100

@@ -146,6 +169,7 @@ public void ensureIsOpen()
146169

147170
private final String _username, _password, _virtualHost;
148171
private final int _requestedChannelMax, _requestedFrameMax, _requestedHeartbeat;
172+
private final Map<String, Object> _clientProperties;
149173

150174
/** Saved server properties field from connection.start */
151175
public Map<String, Object> _serverProperties;
@@ -202,6 +226,7 @@ public AMQConnection(ConnectionFactory factory,
202226
_requestedChannelMax = factory.getRequestedChannelMax();
203227
_requestedFrameMax = factory.getRequestedFrameMax();
204228
_requestedHeartbeat = factory.getRequestedHeartbeat();
229+
_clientProperties = new HashMap<String, Object>(factory.getClientProperties());
205230

206231
this.factory = factory;
207232
_frameHandler = frameHandler;
@@ -271,10 +296,8 @@ public void start(boolean insist)
271296
LongString saslResponse = LongStringHelper.asLongString("\0" + _username +
272297
"\0" + _password);
273298
AMQImpl.Connection.StartOk startOk =
274-
new AMQImpl.Connection.StartOk(buildClientPropertiesTable(),
275-
"PLAIN",
276-
saslResponse,
277-
"en_US");
299+
new AMQImpl.Connection.StartOk(_clientProperties, "PLAIN",
300+
saslResponse, "en_US");
278301

279302
AMQP.Connection.Tune connTune =
280303
(AMQP.Connection.Tune) _channel0.exnWrappingRpc(startOk).getMethod();
@@ -359,6 +382,10 @@ public void setHeartbeat(int heartbeat) {
359382
}
360383
}
361384

385+
public Map<String, Object> getClientProperties() {
386+
return new HashMap<String, Object>(_clientProperties);
387+
}
388+
362389
/**
363390
* Protected API - retrieve the current ExceptionHandler
364391
*/
@@ -394,19 +421,6 @@ public void writeFrame(Frame f) throws IOException {
394421
_lastActivityTime = System.nanoTime();
395422
}
396423

397-
public Map<String, Object> buildClientPropertiesTable() {
398-
return Frame.buildTable(new Object[] {
399-
"product", LongStringHelper.asLongString("RabbitMQ"),
400-
"version", LongStringHelper.asLongString(ClientVersion.VERSION),
401-
"platform", LongStringHelper.asLongString("Java"),
402-
"copyright", LongStringHelper.asLongString("Copyright (C) 2007-2008 LShift Ltd., " +
403-
"Cohesive Financial Technologies LLC., " +
404-
"and Rabbit Technologies Ltd."),
405-
"information", LongStringHelper.asLongString("Licensed under the MPL. " +
406-
"See http://www.rabbitmq.com/")
407-
});
408-
}
409-
410424
private static int negotiatedMaxValue(int clientValue, int serverValue) {
411425
return (clientValue == 0 || serverValue == 0) ?
412426
Math.max(clientValue, serverValue) :

0 commit comments

Comments
 (0)