You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2013/04/25 18:54:02 UTC
git commit: Remove accidentally dependency on Guava's AtomicDouble
Updated Branches:
refs/heads/master 349ef6220 -> c33d445fb
Remove accidentally dependency on Guava's AtomicDouble
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/c33d445f
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/c33d445f
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/c33d445f
Branch: refs/heads/master
Commit: c33d445fb5f2bb3807bef3884e3888e3f27683ad
Parents: 349ef62
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Thu Apr 25 09:53:57 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Thu Apr 25 09:53:57 2013 -0700
----------------------------------------------------------------------
.../services/metrics/MetricCollectorImpl.java | 19 ++++++++++++--
1 files changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c33d445f/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/metrics/MetricCollectorImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/metrics/MetricCollectorImpl.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/metrics/MetricCollectorImpl.java
index 14ff478..4a5b5bf 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/metrics/MetricCollectorImpl.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/metrics/MetricCollectorImpl.java
@@ -14,7 +14,6 @@
package org.apache.tapestry5.ioc.internal.services.metrics;
-import com.google.common.util.concurrent.AtomicDouble;
import org.apache.tapestry5.func.F;
import org.apache.tapestry5.ioc.annotations.PostInjection;
import org.apache.tapestry5.ioc.annotations.PreventServiceDecoration;
@@ -39,6 +38,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
@PreventServiceDecoration
public class MetricCollectorImpl extends LockSupport implements MetricCollector, Runnable
@@ -75,7 +75,7 @@ public class MetricCollectorImpl extends LockSupport implements MetricCollector,
// TODO: May want to initialize this from stored data for Type.TOTAL
- private final AtomicDouble accumulator = new AtomicDouble();
+ private final AtomicReference<Double> accumulator = new AtomicReference<Double>(0d);
MetricImpl(MetricImpl parent, String name, Type type, Units units)
{
@@ -207,7 +207,20 @@ public class MetricCollectorImpl extends LockSupport implements MetricCollector,
public void accumulate(double value)
{
- accumulator.addAndGet(value);
+ while (true)
+ {
+ Double current = accumulator.get();
+ Double updated = current + value;
+
+ // This is where an Atomic is better than a simple volatile, we can detect
+ // when a race condition would have caused the loss of data by overlapping
+ // read-and-increment operations. Still miss Clojure's approach, of course.
+
+ if (accumulator.compareAndSet(current, updated))
+ {
+ break;
+ }
+ }
if (parent != null)
{