diff --git a/src/main/java/org/jboss/netty/channel/DownstreamMessageEvent.java b/src/main/java/org/jboss/netty/channel/DownstreamMessageEvent.java index ac63b6f183..77ae6774b3 100644 --- a/src/main/java/org/jboss/netty/channel/DownstreamMessageEvent.java +++ b/src/main/java/org/jboss/netty/channel/DownstreamMessageEvent.java @@ -77,7 +77,11 @@ public class DownstreamMessageEvent implements MessageEvent { } public SocketAddress getRemoteAddress() { - return remoteAddress; + if (remoteAddress != null) { + return remoteAddress; + } else { + return getChannel().getRemoteAddress(); + } } @Override diff --git a/src/main/java/org/jboss/netty/channel/MessageEvent.java b/src/main/java/org/jboss/netty/channel/MessageEvent.java index e49bcdfd5f..63a3e54134 100644 --- a/src/main/java/org/jboss/netty/channel/MessageEvent.java +++ b/src/main/java/org/jboss/netty/channel/MessageEvent.java @@ -45,10 +45,7 @@ public interface MessageEvent extends ChannelEvent { Object getMessage(); /** - * Returns the remote address. - * - * @return the remote address. {@code null} if the remote address is - * same with the default remote address returned by {@link Channel#getRemoteAddress()}. + * Returns the remote address of the message. */ SocketAddress getRemoteAddress(); } diff --git a/src/main/java/org/jboss/netty/channel/UpstreamMessageEvent.java b/src/main/java/org/jboss/netty/channel/UpstreamMessageEvent.java index 6fbaeedeef..d0b6b4cb7c 100644 --- a/src/main/java/org/jboss/netty/channel/UpstreamMessageEvent.java +++ b/src/main/java/org/jboss/netty/channel/UpstreamMessageEvent.java @@ -57,12 +57,7 @@ public class UpstreamMessageEvent implements MessageEvent { } this.channel = channel; this.message = message; - - if (remoteAddress != null) { - this.remoteAddress = remoteAddress; - } else { - this.remoteAddress = channel.getRemoteAddress(); - } + this.remoteAddress = remoteAddress; } public Channel getChannel() { @@ -78,13 +73,16 @@ public class UpstreamMessageEvent implements MessageEvent { } public SocketAddress getRemoteAddress() { - return remoteAddress; + if (remoteAddress != null) { + return remoteAddress; + } else { + return getChannel().getRemoteAddress(); + } } @Override public String toString() { - // It's safe to use identity comparison in this case. - if (getRemoteAddress() == getChannel().getRemoteAddress()) { + if (getRemoteAddress() == null) { return getChannel().toString() + " RECEIVED: " + StringUtil.stripControlCharacters(getMessage()); } else {