* MessageEvent.getRemoteAddress() does not return null anymore

* Improved the String representation of MessageEvent implementations
This commit is contained in:
Trustin Lee 2009-07-18 07:38:39 +00:00
parent 17bbe5d3ee
commit 7be842be05
2 changed files with 10 additions and 4 deletions

View File

@ -87,7 +87,7 @@ public class DownstreamMessageEvent implements MessageEvent {
StringUtil.stripControlCharacters(getMessage()); StringUtil.stripControlCharacters(getMessage());
} else { } else {
return getChannel().toString() + " WRITE: " + return getChannel().toString() + " WRITE: " +
StringUtil.stripControlCharacters(getMessage()) + ", " + StringUtil.stripControlCharacters(getMessage()) + " to " +
getRemoteAddress(); getRemoteAddress();
} }
} }

View File

@ -57,7 +57,12 @@ public class UpstreamMessageEvent implements MessageEvent {
} }
this.channel = channel; this.channel = channel;
this.message = message; this.message = message;
this.remoteAddress = remoteAddress;
if (remoteAddress != null) {
this.remoteAddress = remoteAddress;
} else {
this.remoteAddress = channel.getRemoteAddress();
}
} }
public Channel getChannel() { public Channel getChannel() {
@ -78,12 +83,13 @@ public class UpstreamMessageEvent implements MessageEvent {
@Override @Override
public String toString() { public String toString() {
if (getRemoteAddress() == null) { // It's safe to use identity comparison in this case.
if (getRemoteAddress() == getChannel().getRemoteAddress()) {
return getChannel().toString() + " RECEIVED: " + return getChannel().toString() + " RECEIVED: " +
StringUtil.stripControlCharacters(getMessage()); StringUtil.stripControlCharacters(getMessage());
} else { } else {
return getChannel().toString() + " RECEIVED: " + return getChannel().toString() + " RECEIVED: " +
StringUtil.stripControlCharacters(getMessage()) + ", " + StringUtil.stripControlCharacters(getMessage()) + " from " +
getRemoteAddress(); getRemoteAddress();
} }
} }