Code cleanup

This commit is contained in:
Trustin Lee 2008-11-28 05:38:34 +00:00
parent 70b87f84df
commit 38943f3d23

View File

@ -22,7 +22,6 @@
*/ */
package org.jboss.netty.example.discard; package org.jboss.netty.example.discard;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -33,6 +32,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelEvent; import org.jboss.netty.channel.ChannelEvent;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipelineCoverage; import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ChannelState;
import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.MessageEvent;
@ -52,8 +52,6 @@ public class DiscardClientHandler extends SimpleChannelHandler {
private static final Logger logger = Logger.getLogger( private static final Logger logger = Logger.getLogger(
DiscardClientHandler.class.getName()); DiscardClientHandler.class.getName());
private final Random random = new Random();
private final int messageSize;
private final AtomicLong transferredBytes = new AtomicLong(); private final AtomicLong transferredBytes = new AtomicLong();
private final byte[] content; private final byte[] content;
@ -62,7 +60,6 @@ public class DiscardClientHandler extends SimpleChannelHandler {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"messageSize: " + messageSize); "messageSize: " + messageSize);
} }
this.messageSize = messageSize;
content = new byte[messageSize]; content = new byte[messageSize];
} }
@ -73,7 +70,9 @@ public class DiscardClientHandler extends SimpleChannelHandler {
@Override @Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception { public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
if (e instanceof ChannelStateEvent) { if (e instanceof ChannelStateEvent) {
//logger.info(e.toString()); if (((ChannelStateEvent) e).getState() != ChannelState.INTEREST_OPS) {
logger.info(e.toString());
}
} }
// Let SimpleChannelHandler call actual event handler methods below. // Let SimpleChannelHandler call actual event handler methods below.
@ -114,35 +113,16 @@ public class DiscardClientHandler extends SimpleChannelHandler {
// If you keep writing messages ignoring this property, // If you keep writing messages ignoring this property,
// you will end up with an OutOfMemoryError. // you will end up with an OutOfMemoryError.
Channel channel = e.getChannel(); Channel channel = e.getChannel();
int cnt = 0;
while (channel.isWritable()) { while (channel.isWritable()) {
ChannelBuffer m = nextMessage(); ChannelBuffer m = nextMessage();
if (m == null) { if (m == null) {
break; break;
} }
channel.write(m); channel.write(m);
cnt ++;
if (cnt % 100000 == 0) {
System.out.println(cnt);
}
} }
// System.out.println("* " + cnt);
// if (cnt > 0) {
// for (int i = 0; i < 10; i ++) {
// ChannelBuffer m = nextMessage();
// if (m == null) {
// break;
// }
// channel.write(m);
// }
// }
} }
private ChannelBuffer nextMessage() { private ChannelBuffer nextMessage() {
//byte[] content = new byte[messageSize];
//random.nextBytes(content);
return ChannelBuffers.wrappedBuffer(content); return ChannelBuffers.wrappedBuffer(content);
} }
} }