Prettier string representation of ChannelEvent implementations

This commit is contained in:
Trustin Lee 2009-02-08 16:12:18 +00:00
parent fff170b71e
commit 52e4288964
7 changed files with 39 additions and 22 deletions

View File

@ -69,10 +69,10 @@ public final class DefaultChildChannelStateEvent implements ChildChannelStateEve
String channelString = getChannel().toString(); String channelString = getChannel().toString();
StringBuilder buf = new StringBuilder(channelString.length() + 32); StringBuilder buf = new StringBuilder(channelString.length() + 32);
buf.append(channelString); buf.append(channelString);
buf.append(" - (childId: "); buf.append(" - (");
buf.append(getChildChannel().getId().toString()); buf.append(getChildChannel().isOpen()? "CHILD_OPEN" : "CHILD_CLOSED");
buf.append(", childState: "); buf.append(": ");
buf.append(getChildChannel().isOpen()? "OPEN" : "CLOSED"); buf.append(getChildChannel().getId());
buf.append(')'); buf.append(')');
return buf.toString(); return buf.toString();
} }

View File

@ -69,6 +69,6 @@ public final class DefaultExceptionEvent implements ExceptionEvent {
@Override @Override
public String toString() { public String toString() {
return getChannel().toString() + " - (cause: " + cause.getClass().getSimpleName() + ')'; return getChannel().toString() + " - (EXCEPTION: " + cause + ')';
} }
} }

View File

@ -67,12 +67,24 @@ public final class DefaultWriteCompletionEvent implements WriteCompletionEvent {
@Override @Override
public String toString() { public String toString() {
String parentString = super.toString(); String channelString = getChannel().toString();
StringBuilder buf = new StringBuilder(parentString.length() + 32); StringBuilder buf = new StringBuilder(channelString.length() + 32);
buf.append(parentString); buf.append(channelString);
buf.append(" - (writtenAmount: "); buf.append(" - (WROTE: ");
buf.append(getWrittenAmount());
buf.append(')'); int amount = getWrittenAmount();
switch (amount) {
case 0:
buf.append("0 byte");
break;
case 1:
buf.append("1 byte");
break;
default:
buf.append(amount);
buf.append(" bytes");
}
buf.append(")");
return buf.toString(); return buf.toString();
} }
} }

View File

@ -81,7 +81,7 @@ public final class DownstreamChannelStateEvent implements ChannelStateEvent {
String channelString = getChannel().toString(); String channelString = getChannel().toString();
StringBuilder buf = new StringBuilder(channelString.length() + 64); StringBuilder buf = new StringBuilder(channelString.length() + 64);
buf.append(channelString); buf.append(channelString);
buf.append(" - (request: "); buf.append(" - (");
switch (getState()) { switch (getState()) {
case OPEN: case OPEN:
if (Boolean.TRUE.equals(getValue())) { if (Boolean.TRUE.equals(getValue())) {
@ -92,20 +92,23 @@ public final class DownstreamChannelStateEvent implements ChannelStateEvent {
break; break;
case BOUND: case BOUND:
if (getValue() != null) { if (getValue() != null) {
buf.append("BIND"); buf.append("BIND: ");
buf.append(getValue());
} else { } else {
buf.append("UNBIND"); buf.append("UNBIND");
} }
break; break;
case CONNECTED: case CONNECTED:
if (getValue() != null) { if (getValue() != null) {
buf.append("CONNECT"); buf.append("CONNECT: ");
buf.append(getValue());
} else { } else {
buf.append("DISCONNECT"); buf.append("DISCONNECT");
} }
break; break;
case INTEREST_OPS: case INTEREST_OPS:
buf.append("CHANGE_INTEREST"); buf.append("CHANGE_INTEREST: ");
buf.append(getValue());
break; break;
default: default:
buf.append(getState().name()); buf.append(getState().name());

View File

@ -85,9 +85,9 @@ public final class DownstreamMessageEvent implements MessageEvent {
@Override @Override
public String toString() { public String toString() {
if (remoteAddress == null) { if (remoteAddress == null) {
return super.toString() + " - (write: " + message + ')'; return getChannel().toString() + " - (WRITE: " + message + ')';
} else { } else {
return super.toString() + " - (write: " + message + ", " + remoteAddress + ')'; return getChannel().toString() + " - (WRITE: " + message + ", " + remoteAddress + ')';
} }
} }
} }

View File

@ -78,7 +78,7 @@ public final class UpstreamChannelStateEvent implements ChannelStateEvent {
String channelString = getChannel().toString(); String channelString = getChannel().toString();
StringBuilder buf = new StringBuilder(channelString.length() + 64); StringBuilder buf = new StringBuilder(channelString.length() + 64);
buf.append(channelString); buf.append(channelString);
buf.append(" - (state: "); buf.append(" - (");
switch (getState()) { switch (getState()) {
case OPEN: case OPEN:
if (Boolean.TRUE.equals(getValue())) { if (Boolean.TRUE.equals(getValue())) {
@ -89,14 +89,16 @@ public final class UpstreamChannelStateEvent implements ChannelStateEvent {
break; break;
case BOUND: case BOUND:
if (getValue() != null) { if (getValue() != null) {
buf.append("BOUND"); buf.append("BOUND: ");
buf.append(getValue());
} else { } else {
buf.append("UNBOUND"); buf.append("UNBOUND");
} }
break; break;
case CONNECTED: case CONNECTED:
if (getValue() != null) { if (getValue() != null) {
buf.append("CONNECTED"); buf.append("CONNECTED: ");
buf.append(getValue());
} else { } else {
buf.append("DISCONNECTED"); buf.append("DISCONNECTED");
} }

View File

@ -81,9 +81,9 @@ public final class UpstreamMessageEvent implements MessageEvent {
@Override @Override
public String toString() { public String toString() {
if (remoteAddress == null) { if (remoteAddress == null) {
return super.toString() + " - (received: " + message + ')'; return getChannel().toString() + " - (RECEIVED: " + message + ')';
} else { } else {
return super.toString() + " - (received: " + message + ", " + remoteAddress + ')'; return getChannel().toString() + " - (RECEIVED: " + message + ", " + remoteAddress + ')';
} }
} }
} }