Remove the usage of AtomicLong as this only confuse users. The Handler

is not suited for re-use anyway. See #93
This commit is contained in:
norman 2011-12-01 09:41:57 +01:00
parent 9ac5b8be83
commit 49f2616972
2 changed files with 6 additions and 8 deletions

View File

@ -15,7 +15,6 @@
*/ */
package org.jboss.netty.example.discard; package org.jboss.netty.example.discard;
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;
@ -44,7 +43,7 @@ public class DiscardClientHandler extends SimpleChannelUpstreamHandler {
private static final Logger logger = Logger.getLogger( private static final Logger logger = Logger.getLogger(
DiscardClientHandler.class.getName()); DiscardClientHandler.class.getName());
private final AtomicLong transferredBytes = new AtomicLong(); private long transferredBytes = 0;
private final byte[] content; private final byte[] content;
public DiscardClientHandler(int messageSize) { public DiscardClientHandler(int messageSize) {
@ -56,7 +55,7 @@ public class DiscardClientHandler extends SimpleChannelUpstreamHandler {
} }
public long getTransferredBytes() { public long getTransferredBytes() {
return transferredBytes.get(); return transferredBytes;
} }
@Override @Override
@ -90,7 +89,7 @@ public class DiscardClientHandler extends SimpleChannelUpstreamHandler {
@Override @Override
public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) { public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) {
transferredBytes.addAndGet(e.getWrittenAmount()); transferredBytes =+e.getWrittenAmount();
} }
@Override @Override

View File

@ -15,7 +15,6 @@
*/ */
package org.jboss.netty.example.discard; package org.jboss.netty.example.discard;
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;
@ -40,10 +39,10 @@ public class DiscardServerHandler extends SimpleChannelUpstreamHandler {
private static final Logger logger = Logger.getLogger( private static final Logger logger = Logger.getLogger(
DiscardServerHandler.class.getName()); DiscardServerHandler.class.getName());
private final AtomicLong transferredBytes = new AtomicLong(); private long transferredBytes = 0;
public long getTransferredBytes() { public long getTransferredBytes() {
return transferredBytes.get(); return transferredBytes;
} }
@Override @Override
@ -59,7 +58,7 @@ public class DiscardServerHandler extends SimpleChannelUpstreamHandler {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
// Discard received data silently by doing nothing. // Discard received data silently by doing nothing.
transferredBytes.addAndGet(((ChannelBuffer) e.getMessage()).readableBytes()); transferredBytes += (((ChannelBuffer) e.getMessage()).readableBytes());
} }
@Override @Override