|
35 | 35 | import java.io.IOException; |
36 | 36 | import java.net.SocketException; |
37 | 37 | import java.util.Map; |
| 38 | +import java.util.HashMap; |
38 | 39 | import java.util.concurrent.TimeoutException; |
39 | 40 |
|
40 | 41 | import com.rabbitmq.client.AMQP; |
@@ -72,6 +73,28 @@ public class AMQConnection extends ShutdownNotifierComponent implements Connecti |
72 | 73 | /** Timeout used while waiting for a connection.close-ok (milliseconds) */ |
73 | 74 | public static final int CONNECTION_CLOSING_TIMEOUT = 10000; |
74 | 75 |
|
| 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 | + |
75 | 98 | private static final Version clientVersion = |
76 | 99 | new Version(AMQP.PROTOCOL.MAJOR, AMQP.PROTOCOL.MINOR); |
77 | 100 |
|
@@ -146,6 +169,7 @@ public void ensureIsOpen() |
146 | 169 |
|
147 | 170 | private final String _username, _password, _virtualHost; |
148 | 171 | private final int _requestedChannelMax, _requestedFrameMax, _requestedHeartbeat; |
| 172 | + private final Map<String, Object> _clientProperties; |
149 | 173 |
|
150 | 174 | /** Saved server properties field from connection.start */ |
151 | 175 | public Map<String, Object> _serverProperties; |
@@ -202,6 +226,7 @@ public AMQConnection(ConnectionFactory factory, |
202 | 226 | _requestedChannelMax = factory.getRequestedChannelMax(); |
203 | 227 | _requestedFrameMax = factory.getRequestedFrameMax(); |
204 | 228 | _requestedHeartbeat = factory.getRequestedHeartbeat(); |
| 229 | + _clientProperties = new HashMap<String, Object>(factory.getClientProperties()); |
205 | 230 |
|
206 | 231 | this.factory = factory; |
207 | 232 | _frameHandler = frameHandler; |
@@ -271,10 +296,8 @@ public void start(boolean insist) |
271 | 296 | LongString saslResponse = LongStringHelper.asLongString("\0" + _username + |
272 | 297 | "\0" + _password); |
273 | 298 | 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"); |
278 | 301 |
|
279 | 302 | AMQP.Connection.Tune connTune = |
280 | 303 | (AMQP.Connection.Tune) _channel0.exnWrappingRpc(startOk).getMethod(); |
@@ -359,6 +382,10 @@ public void setHeartbeat(int heartbeat) { |
359 | 382 | } |
360 | 383 | } |
361 | 384 |
|
| 385 | + public Map<String, Object> getClientProperties() { |
| 386 | + return new HashMap<String, Object>(_clientProperties); |
| 387 | + } |
| 388 | + |
362 | 389 | /** |
363 | 390 | * Protected API - retrieve the current ExceptionHandler |
364 | 391 | */ |
@@ -394,19 +421,6 @@ public void writeFrame(Frame f) throws IOException { |
394 | 421 | _lastActivityTime = System.nanoTime(); |
395 | 422 | } |
396 | 423 |
|
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 | | - |
410 | 424 | private static int negotiatedMaxValue(int clientValue, int serverValue) { |
411 | 425 | return (clientValue == 0 || serverValue == 0) ? |
412 | 426 | Math.max(clientValue, serverValue) : |
|
0 commit comments