Skip to content

Commit 4f3f0ca

Browse files
author
Alexandru Scvortov
committed
merge bug23895 into default (Clients supplying numeric hostnames should not require DNS)
2 parents 2986a27 + 31764f0 commit 4f3f0ca

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

src/com/rabbitmq/client/Connection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.rabbitmq.client;
1818

1919
import java.io.IOException;
20+
import java.net.InetAddress;
2021
import java.util.Map;
2122

2223
/**
@@ -46,7 +47,7 @@ public interface Connection extends ShutdownNotifier { // rename to AMQPConnecti
4647
* Retrieve the host.
4748
* @return the hostname of the peer we're connected to.
4849
*/
49-
String getHost();
50+
InetAddress getAddress();
5051

5152
/**
5253
* Retrieve the port number.

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.EOFException;
2121
import java.io.IOException;
22+
import java.net.InetAddress;
2223
import java.net.SocketException;
2324
import java.util.HashMap;
2425
import java.util.Map;
@@ -151,8 +152,8 @@ public void ensureIsOpen()
151152
public Map<String, Object> _serverProperties;
152153

153154
/** {@inheritDoc} */
154-
public String getHost() {
155-
return _frameHandler.getHost();
155+
public InetAddress getAddress() {
156+
return _frameHandler.getAddress();
156157
}
157158

158159
/** {@inheritDoc} */
@@ -241,7 +242,7 @@ public void start()
241242

242243
// start the main loop going
243244
Thread ml = new MainLoop();
244-
ml.setName("AMQP Connection " + getHost() + ":" + getPort());
245+
ml.setName("AMQP Connection " + getHostAddress() + ":" + getPort());
245246
ml.start();
246247

247248
AMQP.Connection.Start connStart = null;
@@ -559,7 +560,7 @@ public void handleConnectionClose(Command closeCommand) {
559560
_brokerInitiatedShutdown = true;
560561
Thread scw = new SocketCloseWait(sse);
561562
scw.setName("AMQP Connection Closing Monitor " +
562-
getHost() + ":" + getPort());
563+
getHostAddress() + ":" + getPort());
563564
scw.start();
564565
}
565566

@@ -726,6 +727,10 @@ public void close(int closeCode,
726727
}
727728

728729
@Override public String toString() {
729-
return "amqp://" + _factory.getUsername() + "@" + getHost() + ":" + getPort() + _virtualHost;
730+
return "amqp://" + _factory.getUsername() + "@" + getHostAddress() + ":" + getPort() + _virtualHost;
731+
}
732+
733+
private String getHostAddress() {
734+
return getAddress() == null ? null : getAddress().getHostAddress();
730735
}
731736
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.rabbitmq.client.impl;
1818

1919
import java.io.IOException;
20+
import java.net.InetAddress;
2021
import java.net.SocketException;
2122
import java.net.SocketTimeoutException;
2223

@@ -25,8 +26,8 @@
2526
*/
2627

2728
public interface FrameHandler {
28-
/** Retrieve hostname of peer. */
29-
public String getHost();
29+
/** Retrieve address of peer. */
30+
public InetAddress getAddress();
3031

3132
/** Retrieve port number of peer. */
3233
public int getPort();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.DataInputStream;
2222
import java.io.DataOutputStream;
2323
import java.io.IOException;
24+
import java.net.InetAddress;
2425
import java.net.Socket;
2526
import java.net.SocketException;
2627

@@ -55,8 +56,8 @@ public SocketFrameHandler(Socket socket) throws IOException {
5556
_outputStream = new DataOutputStream(new BufferedOutputStream(_socket.getOutputStream()));
5657
}
5758

58-
public String getHost() {
59-
return _socket.getInetAddress().getHostName();
59+
public InetAddress getAddress() {
60+
return _socket.getInetAddress();
6061
}
6162

6263
public int getPort() {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.rabbitmq.client.test;
1818

1919
import java.io.IOException;
20+
import java.net.InetAddress;
2021
import java.net.SocketException;
2122
import java.net.SocketTimeoutException;
2223
import java.util.ArrayList;
@@ -159,8 +160,8 @@ public int getTimeout() throws SocketException {
159160
return 0;
160161
}
161162

162-
public String getHost() {
163-
return "MockFrameHandler";
163+
public InetAddress getAddress() {
164+
return null;
164165
}
165166

166167
public int getPort() {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.rabbitmq.client.test;
1919

2020
import java.io.IOException;
21+
import java.net.InetAddress;
2122
import java.net.SocketException;
2223
import java.util.ArrayList;
2324
import java.util.Iterator;
@@ -145,8 +146,8 @@ public int getTimeout() throws SocketException {
145146
return 0;
146147
}
147148

148-
public String getHost() {
149-
return "MyFrameHandler";
149+
public InetAddress getAddress() {
150+
return null;
150151
}
151152

152153
public int getPort() {

0 commit comments

Comments
 (0)