Skip to content

Commit 1835085

Browse files
Naming, docs, cosmetics
1 parent f04af95 commit 1835085

File tree

6 files changed

+72
-50
lines changed

6 files changed

+72
-50
lines changed

src/com/rabbitmq/client/Connection.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.net.InetAddress;
2121
import java.util.Map;
22+
import java.util.concurrent.ExecutorService;
2223

2324
/**
2425
* Public API: Interface to an AMQ connection. See the see the <a href="http://www.amqp.org/">spec</a> for details.
@@ -94,11 +95,17 @@ public interface Connection extends ShutdownNotifier { // rename to AMQPConnecti
9495
Map<String, Object> getClientProperties();
9596

9697
/**
97-
* Get connection name client property value
98+
* Returns client-provided connection name, if any. Note that the value
99+
* returned does not uniquely identify a connection and cannot be used
100+
* as a connection identifier in HTTP API requests.
98101
*
99-
* @return string connection name from client properties, or null if there is not such property.
102+
*
103+
*
104+
* @return client-provided connection name, if any
105+
* @see ConnectionFactory#newConnection(Address[], String)
106+
* @see ConnectionFactory#newConnection(ExecutorService, Address[], String)
100107
*/
101-
String getConnectionName();
108+
String getClientProvidedName();
102109

103110
/**
104111
* Retrieve the server properties.

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -650,20 +650,24 @@ public Connection newConnection(Address[] addrs) throws IOException, TimeoutExce
650650

651651

652652
/**
653-
* Create a new broker connection, picking the first available address from
653+
* Create a new broker connection with a client-provided name, picking the first available address from
654654
* the list.
655655
*
656656
* If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
657657
* is enabled, the connection returned by this method will be {@link Recoverable}. Future
658658
* reconnection attempts will pick a random accessible address from the provided list.
659659
*
660660
* @param addrs an array of known broker addresses (hostname/port pairs) to try in order
661-
* @param connectionName arbitrary sring for connection name client property
661+
* @param clientProvidedName application-specific connection name, will be displayed
662+
* in the management UI if RabbitMQ server supports it.
663+
* This value doesn't have to be unique and cannot be used
664+
* as a connection identifier e.g. in HTTP API requests.
665+
* This value is supposed to be human-readable.
662666
* @return an interface to the connection
663667
* @throws IOException if it encounters a problem
664668
*/
665-
public Connection newConnection(Address[] addrs, String connectionName) throws IOException, TimeoutException {
666-
return newConnection(this.sharedExecutor, Arrays.asList(addrs), connectionName);
669+
public Connection newConnection(Address[] addrs, String clientProvidedName) throws IOException, TimeoutException {
670+
return newConnection(this.sharedExecutor, Arrays.asList(addrs), clientProvidedName);
667671
}
668672

669673
/**
@@ -683,20 +687,24 @@ public Connection newConnection(List<Address> addrs) throws IOException, Timeout
683687
}
684688

685689
/**
686-
* Create a new broker connection, picking the first available address from
690+
* Create a new broker connection with a client-provided name, picking the first available address from
687691
* the list.
688692
*
689693
* If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
690694
* is enabled, the connection returned by this method will be {@link Recoverable}. Future
691695
* reconnection attempts will pick a random accessible address from the provided list.
692696
*
693697
* @param addrs a List of known broker addresses (hostname/port pairs) to try in order
694-
* @param connectionName arbitrary sring for connection name client property
698+
* @param clientProvidedName application-specific connection name, will be displayed
699+
* in the management UI if RabbitMQ server supports it.
700+
* This value doesn't have to be unique and cannot be used
701+
* as a connection identifier e.g. in HTTP API requests.
702+
* This value is supposed to be human-readable.
695703
* @return an interface to the connection
696704
* @throws IOException if it encounters a problem
697705
*/
698-
public Connection newConnection(List<Address> addrs, String connectionName) throws IOException, TimeoutException {
699-
return newConnection(this.sharedExecutor, addrs, connectionName);
706+
public Connection newConnection(List<Address> addrs, String clientProvidedName) throws IOException, TimeoutException {
707+
return newConnection(this.sharedExecutor, addrs, clientProvidedName);
700708
}
701709

702710
/**
@@ -719,7 +727,7 @@ public Connection newConnection(ExecutorService executor, Address[] addrs) throw
719727

720728

721729
/**
722-
* Create a new broker connection, picking the first available address from
730+
* Create a new broker connection with a client-provided name, picking the first available address from
723731
* the list.
724732
*
725733
* If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
@@ -728,13 +736,17 @@ public Connection newConnection(ExecutorService executor, Address[] addrs) throw
728736
*
729737
* @param executor thread execution service for consumers on the connection
730738
* @param addrs an array of known broker addresses (hostname/port pairs) to try in order
731-
* @param connectionName arbitrary sring for connection name client property
739+
* @param clientProvidedName application-specific connection name, will be displayed
740+
* in the management UI if RabbitMQ server supports it.
741+
* This value doesn't have to be unique and cannot be used
742+
* as a connection identifier e.g. in HTTP API requests.
743+
* This value is supposed to be human-readable.
732744
* @return an interface to the connection
733745
* @throws java.io.IOException if it encounters a problem
734746
* @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
735747
*/
736-
public Connection newConnection(ExecutorService executor, Address[] addrs, String connectionName) throws IOException, TimeoutException {
737-
return newConnection(executor, Arrays.asList(addrs), connectionName);
748+
public Connection newConnection(ExecutorService executor, Address[] addrs, String clientProvidedName) throws IOException, TimeoutException {
749+
return newConnection(executor, Arrays.asList(addrs), clientProvidedName);
738750
}
739751

740752
/**
@@ -756,7 +768,7 @@ public Connection newConnection(ExecutorService executor, List<Address> addrs) t
756768
}
757769

758770
/**
759-
* Create a new broker connection, picking the first available address from
771+
* Create a new broker connection with a client-provided name, picking the first available address from
760772
* the list.
761773
*
762774
* If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
@@ -765,20 +777,24 @@ public Connection newConnection(ExecutorService executor, List<Address> addrs) t
765777
*
766778
* @param executor thread execution service for consumers on the connection
767779
* @param addrs a List of known broker addrs (hostname/port pairs) to try in order
768-
* @param connectionName arbitrary sring for connection name client property
780+
* @param clientProvidedName application-specific connection name, will be displayed
781+
* in the management UI if RabbitMQ server supports it.
782+
* This value doesn't have to be unique and cannot be used
783+
* as a connection identifier e.g. in HTTP API requests.
784+
* This value is supposed to be human-readable.
769785
* @return an interface to the connection
770786
* @throws java.io.IOException if it encounters a problem
771787
* @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
772788
*/
773-
public Connection newConnection(ExecutorService executor, List<Address> addrs, String connectionName)
789+
public Connection newConnection(ExecutorService executor, List<Address> addrs, String clientProvidedName)
774790
throws IOException, TimeoutException {
775791
// make sure we respect the provided thread factory
776792
FrameHandlerFactory fhFactory = createFrameHandlerFactory();
777793
ConnectionParams params = params(executor);
778-
// set connection name client property
779-
if (connectionName != null) {
794+
// set client-provided via a client property
795+
if (clientProvidedName != null) {
780796
Map<String, Object> properties = new HashMap<String, Object>(params.getClientProperties());
781-
properties.put("connection_name", connectionName);
797+
properties.put("connection_name", clientProvidedName);
782798
params.setClientProperties(properties);
783799
}
784800

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,8 @@ public Map<String, Object> getClientProperties() {
470470
return new HashMap<String, Object>(_clientProperties);
471471
}
472472

473-
public String getConnectionName() {
474-
Object connectionName = _clientProperties.get("connection_name");
475-
if (connectionName == null){
476-
return null;
477-
} else {
478-
return connectionName.toString();
479-
}
473+
public String getClientProvidedName() {
474+
return (String) _clientProperties.get("connection_name");
480475
}
481476

482477
/**

src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.rabbitmq.client.BlockedListener;
66
import com.rabbitmq.client.Channel;
77
import com.rabbitmq.client.Connection;
8+
import com.rabbitmq.client.ConnectionFactory;
89
import com.rabbitmq.client.MissedHeartbeatException;
910
import com.rabbitmq.client.Recoverable;
1011
import com.rabbitmq.client.RecoveryListener;
@@ -27,6 +28,7 @@
2728
import java.util.Map;
2829
import java.util.Set;
2930
import java.util.concurrent.ConcurrentHashMap;
31+
import java.util.concurrent.ExecutorService;
3032
import java.util.concurrent.TimeoutException;
3133

3234
/**
@@ -157,10 +159,12 @@ public Map<String, Object> getClientProperties() {
157159
}
158160

159161
/**
160-
* @see com.rabbitmq.client.Connection#getConnectionName()
162+
* @see com.rabbitmq.client.Connection#getClientProvidedName()
163+
* @see ConnectionFactory#newConnection(Address[], String)
164+
* @see ConnectionFactory#newConnection(ExecutorService, Address[], String)
161165
*/
162-
public String getConnectionName() {
163-
return delegate.getConnectionName();
166+
public String getClientProvidedName() {
167+
return delegate.getClientProvidedName();
164168
}
165169

166170
/**

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,33 +177,33 @@ public void testConnectionHangInNegotiation() {
177177
assertEquals("Wrong type of exception returned.", SocketTimeoutException.class, exceptionList.get(0).getClass());
178178
}
179179

180-
public void testConnectionName() throws IOException, TimeoutException {
181-
String connectionName = "custom name";
182-
Connection connection = factory.newConnection(connectionName);
183-
assertEquals(connectionName, connection.getConnectionName());
180+
public void testClientProvidedConnectionName() throws IOException, TimeoutException {
181+
String providedName = "event consumers connection";
182+
Connection connection = factory.newConnection(providedName);
183+
assertEquals(providedName, connection.getClientProvidedName());
184184
connection.close();
185185

186-
List<Address> addresses_list = Arrays.asList(new Address("127.0.0.1"), new Address("127.0.0.1", 5672));
187-
connection = factory.newConnection(addresses_list, connectionName);
188-
assertEquals(connectionName, connection.getConnectionName());
186+
List<Address> addrs1 = Arrays.asList(new Address("127.0.0.1"), new Address("127.0.0.1", 5672));
187+
connection = factory.newConnection(addrs1, providedName);
188+
assertEquals(providedName, connection.getClientProvidedName());
189189
connection.close();
190190

191-
Address[] addresses_arr = {new Address("127.0.0.1"), new Address("127.0.0.1", 5672)};
192-
connection = factory.newConnection(addresses_arr, connectionName);
193-
assertEquals(connectionName, connection.getConnectionName());
191+
Address[] addrs2 = {new Address("127.0.0.1"), new Address("127.0.0.1", 5672)};
192+
connection = factory.newConnection(addrs2, providedName);
193+
assertEquals(providedName, connection.getClientProvidedName());
194194
connection.close();
195195

196-
ExecutorService executor = Executors.newSingleThreadExecutor();
197-
connection = factory.newConnection(executor, connectionName);
198-
assertEquals(connectionName, connection.getConnectionName());
196+
ExecutorService xs = Executors.newSingleThreadExecutor();
197+
connection = factory.newConnection(xs, providedName);
198+
assertEquals(providedName, connection.getClientProvidedName());
199199
connection.close();
200200

201-
connection = factory.newConnection(executor, addresses_list, connectionName);
202-
assertEquals(connectionName, connection.getConnectionName());
201+
connection = factory.newConnection(xs, addrs1, providedName);
202+
assertEquals(providedName, connection.getClientProvidedName());
203203
connection.close();
204204

205-
connection = factory.newConnection(executor, addresses_arr, connectionName);
206-
assertEquals(connectionName, connection.getConnectionName());
205+
connection = factory.newConnection(xs, addrs2, providedName);
206+
assertEquals(providedName, connection.getClientProvidedName());
207207
connection.close();
208208
}
209209

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public void testNamedConnectionRecovery()
3636
AutorecoveringConnection c = newRecoveringConnection(connectionName);
3737
try {
3838
assertTrue(c.isOpen());
39-
assertEquals(connectionName, c.getConnectionName());
39+
assertEquals(connectionName, c.getClientProvidedName());
4040
closeAndWaitForRecovery(c);
4141
assertTrue(c.isOpen());
42-
assertEquals(connectionName, c.getConnectionName());
42+
assertEquals(connectionName, c.getClientProvidedName());
4343
} finally {
4444
c.abort();
4545
}

0 commit comments

Comments
 (0)