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();
StringBuilder buf = new StringBuilder(channelString.length() + 32);
buf.append(channelString);
buf.append(" - (childId: ");
buf.append(getChildChannel().getId().toString());
buf.append(", childState: ");
buf.append(getChildChannel().isOpen()? "OPEN" : "CLOSED");
buf.append(" - (");
buf.append(getChildChannel().isOpen()? "CHILD_OPEN" : "CHILD_CLOSED");
buf.append(": ");
buf.append(getChildChannel().getId());
buf.append(')');
return buf.toString();
}

View File

@ -69,6 +69,6 @@ public final class DefaultExceptionEvent implements ExceptionEvent {
@Override
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
public String toString() {
String parentString = super.toString();
StringBuilder buf = new StringBuilder(parentString.length() + 32);
buf.append(parentString);
buf.append(" - (writtenAmount: ");
buf.append(getWrittenAmount());
buf.append(')');
String channelString = getChannel().toString();
StringBuilder buf = new StringBuilder(channelString.length() + 32);
buf.append(channelString);
buf.append(" - (WROTE: ");
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();
}
}

View File

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

View File

@ -85,9 +85,9 @@ public final class DownstreamMessageEvent implements MessageEvent {
@Override
public String toString() {
if (remoteAddress == null) {
return super.toString() + " - (write: " + message + ')';
return getChannel().toString() + " - (WRITE: " + message + ')';
} 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();
StringBuilder buf = new StringBuilder(channelString.length() + 64);
buf.append(channelString);
buf.append(" - (state: ");
buf.append(" - (");
switch (getState()) {
case OPEN:
if (Boolean.TRUE.equals(getValue())) {
@ -89,14 +89,16 @@ public final class UpstreamChannelStateEvent implements ChannelStateEvent {
break;
case BOUND:
if (getValue() != null) {
buf.append("BOUND");
buf.append("BOUND: ");
buf.append(getValue());
} else {
buf.append("UNBOUND");
}
break;
case CONNECTED:
if (getValue() != null) {
buf.append("CONNECTED");
buf.append("CONNECTED: ");
buf.append(getValue());
} else {
buf.append("DISCONNECTED");
}

View File

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