From 49f2616972bde8231c447a403654d6eab6357b7d Mon Sep 17 00:00:00 2001 From: norman Date: Thu, 1 Dec 2011 09:41:57 +0100 Subject: [PATCH] Remove the usage of AtomicLong as this only confuse users. The Handler is not suited for re-use anyway. See #93 --- .../jboss/netty/example/discard/DiscardClientHandler.java | 7 +++---- .../jboss/netty/example/discard/DiscardServerHandler.java | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jboss/netty/example/discard/DiscardClientHandler.java b/src/main/java/org/jboss/netty/example/discard/DiscardClientHandler.java index e9ced61d75..3cf1aa7bcb 100644 --- a/src/main/java/org/jboss/netty/example/discard/DiscardClientHandler.java +++ b/src/main/java/org/jboss/netty/example/discard/DiscardClientHandler.java @@ -15,7 +15,6 @@ */ package org.jboss.netty.example.discard; -import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Level; import java.util.logging.Logger; @@ -44,7 +43,7 @@ public class DiscardClientHandler extends SimpleChannelUpstreamHandler { private static final Logger logger = Logger.getLogger( DiscardClientHandler.class.getName()); - private final AtomicLong transferredBytes = new AtomicLong(); + private long transferredBytes = 0; private final byte[] content; public DiscardClientHandler(int messageSize) { @@ -56,7 +55,7 @@ public class DiscardClientHandler extends SimpleChannelUpstreamHandler { } public long getTransferredBytes() { - return transferredBytes.get(); + return transferredBytes; } @Override @@ -90,7 +89,7 @@ public class DiscardClientHandler extends SimpleChannelUpstreamHandler { @Override public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) { - transferredBytes.addAndGet(e.getWrittenAmount()); + transferredBytes =+e.getWrittenAmount(); } @Override diff --git a/src/main/java/org/jboss/netty/example/discard/DiscardServerHandler.java b/src/main/java/org/jboss/netty/example/discard/DiscardServerHandler.java index 1f7f3ca3da..f982212294 100644 --- a/src/main/java/org/jboss/netty/example/discard/DiscardServerHandler.java +++ b/src/main/java/org/jboss/netty/example/discard/DiscardServerHandler.java @@ -15,7 +15,6 @@ */ package org.jboss.netty.example.discard; -import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Level; import java.util.logging.Logger; @@ -40,10 +39,10 @@ public class DiscardServerHandler extends SimpleChannelUpstreamHandler { private static final Logger logger = Logger.getLogger( DiscardServerHandler.class.getName()); - private final AtomicLong transferredBytes = new AtomicLong(); + private long transferredBytes = 0; public long getTransferredBytes() { - return transferredBytes.get(); + return transferredBytes; } @Override @@ -59,7 +58,7 @@ public class DiscardServerHandler extends SimpleChannelUpstreamHandler { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { // Discard received data silently by doing nothing. - transferredBytes.addAndGet(((ChannelBuffer) e.getMessage()).readableBytes()); + transferredBytes += (((ChannelBuffer) e.getMessage()).readableBytes()); } @Override