Fixed issue: NETTY-173 Do not use Class.isArray() in ReplayingDecoder and FrameDecoder

* Modified FrameDecoder and ReplayingDecoder not to use Class.isArray() anymore.
This commit is contained in:
Trustin Lee 2009-06-15 07:29:12 +00:00
parent 5ae0adbfaa
commit e410abed02
2 changed files with 3 additions and 15 deletions

View File

@ -22,7 +22,6 @@
*/
package org.jboss.netty.handler.codec.frame;
import java.lang.reflect.Array;
import java.net.SocketAddress;
import java.util.concurrent.atomic.AtomicReference;
@ -264,21 +263,16 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler {
"if it returned a frame.");
}
fireMessageReceived(context, remoteAddress, frame);
unfoldAndFireMessageReceived(context, remoteAddress, frame);
}
}
private void fireMessageReceived(ChannelHandlerContext context, SocketAddress remoteAddress, Object result) {
private void unfoldAndFireMessageReceived(ChannelHandlerContext context, SocketAddress remoteAddress, Object result) {
if (unfold) {
if (result instanceof Object[]) {
for (Object r: (Object[]) result) {
Channels.fireMessageReceived(context, r, remoteAddress);
}
} else if (result.getClass().isArray()){
int length = Array.getLength(result);
for (int i = 0; i < length; i ++) {
Channels.fireMessageReceived(context, Array.get(result, i), remoteAddress);
}
} else if (result instanceof Iterable<?>) {
for (Object r: (Iterable<?>) result) {
Channels.fireMessageReceived(context, r, remoteAddress);
@ -309,7 +303,7 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler {
// notify a user that the connection was closed explicitly.
Object partialFrame = decodeLast(ctx, ctx.getChannel(), cumulation);
if (partialFrame != null) {
fireMessageReceived(ctx, null, partialFrame);
unfoldAndFireMessageReceived(ctx, null, partialFrame);
}
} finally {
ctx.sendUpstream(e);

View File

@ -22,7 +22,6 @@
*/
package org.jboss.netty.handler.codec.replay;
import java.lang.reflect.Array;
import java.net.SocketAddress;
import java.util.concurrent.atomic.AtomicReference;
@ -452,11 +451,6 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
for (Object r: (Object[]) result) {
Channels.fireMessageReceived(context, r, remoteAddress);
}
} else if (result.getClass().isArray()){
int length = Array.getLength(result);
for (int i = 0; i < length; i ++) {
Channels.fireMessageReceived(context, Array.get(result, i), remoteAddress);
}
} else if (result instanceof Iterable<?>) {
for (Object r: (Iterable<?>) result) {
Channels.fireMessageReceived(context, r, remoteAddress);