* Updated the Javadoc of MessageEvent

* Improved how getRemoteAddress() works in DownstreamMessageEvent and UpstreamMessageEvent
This commit is contained in:
Trustin Lee 2009-07-18 07:43:13 +00:00
parent 7be842be05
commit 3610fa9608
3 changed files with 13 additions and 14 deletions

View File

@ -77,7 +77,11 @@ public class DownstreamMessageEvent implements MessageEvent {
} }
public SocketAddress getRemoteAddress() { public SocketAddress getRemoteAddress() {
return remoteAddress; if (remoteAddress != null) {
return remoteAddress;
} else {
return getChannel().getRemoteAddress();
}
} }
@Override @Override

View File

@ -45,10 +45,7 @@ public interface MessageEvent extends ChannelEvent {
Object getMessage(); Object getMessage();
/** /**
* Returns the remote address. * Returns the remote address of the message.
*
* @return the remote address. {@code null} if the remote address is
* same with the default remote address returned by {@link Channel#getRemoteAddress()}.
*/ */
SocketAddress getRemoteAddress(); SocketAddress getRemoteAddress();
} }

View File

@ -57,12 +57,7 @@ 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,13 +73,16 @@ public class UpstreamMessageEvent implements MessageEvent {
} }
public SocketAddress getRemoteAddress() { public SocketAddress getRemoteAddress() {
return remoteAddress; if (remoteAddress != null) {
return remoteAddress;
} else {
return getChannel().getRemoteAddress();
}
} }
@Override @Override
public String toString() { public String toString() {
// It's safe to use identity comparison in this case. if (getRemoteAddress() == null) {
if (getRemoteAddress() == getChannel().getRemoteAddress()) {
return getChannel().toString() + " RECEIVED: " + return getChannel().toString() + " RECEIVED: " +
StringUtil.stripControlCharacters(getMessage()); StringUtil.stripControlCharacters(getMessage());
} else { } else {