Skip to content

Commit 96f7828

Browse files
author
Simon MacMullen
committed
Actually, don't have the SocketFrameHandler know the hostname, just return the IP address.
1 parent d12604b commit 96f7828

File tree

12 files changed

+33
-31
lines changed

12 files changed

+33
-31
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/ConnectionFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ protected FrameHandler createFrameHandler(Address addr)
360360
Socket socket = factory.createSocket();
361361
configureSocket(socket);
362362
socket.connect(new InetSocketAddress(hostName, portNumber), connectionTimeout);
363-
return createFrameHandler(socket, hostName);
363+
return createFrameHandler(socket);
364364
}
365365

366-
protected FrameHandler createFrameHandler(Socket sock, String host)
366+
protected FrameHandler createFrameHandler(Socket sock)
367367
throws IOException
368368
{
369-
return new SocketFrameHandler(sock, host);
369+
return new SocketFrameHandler(sock);
370370
}
371371

372372
/**

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

Lines changed: 6 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 " + getAddress().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+
getAddress().getHostAddress() + ":" + getPort());
563564
scw.start();
564565
}
565566

@@ -726,6 +727,6 @@ 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() + "@" + getAddress().getHostAddress() + ":" + getPort() + _virtualHost;
730731
}
731732
}

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: 4 additions & 7 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

@@ -33,9 +34,6 @@
3334
*/
3435

3536
public class SocketFrameHandler implements FrameHandler {
36-
/** Host we connect to */
37-
public final String _host;
38-
3937
/** The underlying socket */
4038
public final Socket _socket;
4139

@@ -51,16 +49,15 @@ public class SocketFrameHandler implements FrameHandler {
5149
/**
5250
* @param socket the socket to use
5351
*/
54-
public SocketFrameHandler(Socket socket, String host) throws IOException {
52+
public SocketFrameHandler(Socket socket) throws IOException {
5553
_socket = socket;
56-
_host = host;
5754

5855
_inputStream = new DataInputStream(new BufferedInputStream(_socket.getInputStream()));
5956
_outputStream = new DataOutputStream(new BufferedOutputStream(_socket.getOutputStream()));
6057
}
6158

62-
public String getHost() {
63-
return _host;
59+
public InetAddress getAddress() {
60+
return _socket.getInetAddress();
6461
}
6562

6663
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() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public boolean hadValidShutdown(){
3636
public SpecialConnection() throws Exception{
3737
super(
3838
new ConnectionFactory(),
39-
new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", 5672), "localhost"),
39+
new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", 5672)),
4040
new DefaultExceptionHandler(){
4141
@Override public void handleConsumerException(Channel channel,
4242
Throwable exception,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
public class ConnectionOpen extends TestCase {
3737
public void testCorrectProtocolHeader() throws IOException {
3838
ConnectionFactory factory = new ConnectionFactory();
39-
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT), "localhost");
39+
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT));
4040
fh.sendHeader();
4141
AMQCommand.Assembler a = AMQCommand.newAssembler();
4242
AMQCommand command = null;
@@ -56,7 +56,7 @@ public void testCorrectProtocolHeader() throws IOException {
5656

5757
public void testCrazyProtocolHeader() throws IOException {
5858
ConnectionFactory factory = new ConnectionFactory();
59-
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT), "localhost");
59+
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT));
6060
fh.sendHeader(100, 3); // major, minor
6161
DataInputStream in = fh._inputStream;
6262
// we should get a valid protocol header back

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static class MyFrameHandler extends SocketFrameHandler {
8383
public MyFrameHandler(Socket socket)
8484
throws IOException
8585
{
86-
super(socket, "localhost");
86+
super(socket);
8787
}
8888

8989
public Frame readFrame() throws IOException {

0 commit comments

Comments
 (0)