Skip to content

Breaking change: using LongAdder instead of AtomicLong #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,63 +26,63 @@ public DelegatingStatisticsCollector(StatisticsCollector delegateCollector) {
}

@Override
public <K> long incrementLoadCount(IncrementLoadCountStatisticsContext<K> context) {
public <K> void incrementLoadCount(IncrementLoadCountStatisticsContext<K> context) {
delegateCollector.incrementLoadCount(context);
return collector.incrementLoadCount(context);
collector.incrementLoadCount(context);
}

@Deprecated
@Override
public long incrementLoadCount() {
return incrementLoadCount(null);
public void incrementLoadCount() {
incrementLoadCount(null);
}

@Override
public <K> long incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext<K> context) {
public <K> void incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext<K> context) {
delegateCollector.incrementLoadErrorCount(context);
return collector.incrementLoadErrorCount(context);
collector.incrementLoadErrorCount(context);
}

@Deprecated
@Override
public long incrementLoadErrorCount() {
return incrementLoadErrorCount(null);
public void incrementLoadErrorCount() {
incrementLoadErrorCount(null);
}

@Override
public <K> long incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountByStatisticsContext<K> context) {
public <K> void incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountByStatisticsContext<K> context) {
delegateCollector.incrementBatchLoadCountBy(delta, context);
return collector.incrementBatchLoadCountBy(delta, context);
collector.incrementBatchLoadCountBy(delta, context);
}

@Deprecated
@Override
public long incrementBatchLoadCountBy(long delta) {
return incrementBatchLoadCountBy(delta, null);
public void incrementBatchLoadCountBy(long delta) {
incrementBatchLoadCountBy(delta, null);
}

@Override
public <K> long incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext<K> context) {
public <K> void incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext<K> context) {
delegateCollector.incrementBatchLoadExceptionCount(context);
return collector.incrementBatchLoadExceptionCount(context);
collector.incrementBatchLoadExceptionCount(context);
}

@Deprecated
@Override
public long incrementBatchLoadExceptionCount() {
return incrementBatchLoadExceptionCount(null);
public void incrementBatchLoadExceptionCount() {
incrementBatchLoadExceptionCount(null);
}

@Override
public <K> long incrementCacheHitCount(IncrementCacheHitCountStatisticsContext<K> context) {
public <K> void incrementCacheHitCount(IncrementCacheHitCountStatisticsContext<K> context) {
delegateCollector.incrementCacheHitCount(context);
return collector.incrementCacheHitCount(context);
collector.incrementCacheHitCount(context);
}

@Deprecated
@Override
public long incrementCacheHitCount() {
return incrementCacheHitCount(null);
public void incrementCacheHitCount() {
incrementCacheHitCount(null);
}

/**
Expand Down
36 changes: 16 additions & 20 deletions src/main/java/org/dataloader/stats/NoOpStatisticsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,54 @@ public class NoOpStatisticsCollector implements StatisticsCollector {
private static final Statistics ZERO_STATS = new Statistics();

@Override
public <K> long incrementLoadCount(IncrementLoadCountStatisticsContext<K> context) {
return 0;
public <K> void incrementLoadCount(IncrementLoadCountStatisticsContext<K> context) {
}

@Deprecated
@Override
public long incrementLoadCount() {
return incrementLoadCount(null);
public void incrementLoadCount() {
incrementLoadCount(null);
}

@Override
public <K> long incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext<K> context) {
return 0;
public <K> void incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext<K> context) {
}

@Deprecated
@Override
public long incrementLoadErrorCount() {
return incrementLoadErrorCount(null);
public void incrementLoadErrorCount() {
incrementLoadErrorCount(null);
}

@Override
public <K> long incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountByStatisticsContext<K> context) {
return 0;
public <K> void incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountByStatisticsContext<K> context) {
}

@Deprecated
@Override
public long incrementBatchLoadCountBy(long delta) {
return incrementBatchLoadCountBy(delta, null);
public void incrementBatchLoadCountBy(long delta) {
incrementBatchLoadCountBy(delta, null);
}

@Override
public <K> long incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext<K> context) {
return 0;
public <K> void incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext<K> context) {

}

@Deprecated
@Override
public long incrementBatchLoadExceptionCount() {
return incrementBatchLoadExceptionCount(null);
public void incrementBatchLoadExceptionCount() {
incrementBatchLoadExceptionCount(null);
}

@Override
public <K> long incrementCacheHitCount(IncrementCacheHitCountStatisticsContext<K> context) {
return 0;
public <K> void incrementCacheHitCount(IncrementCacheHitCountStatisticsContext<K> context) {
}

@Deprecated
@Override
public long incrementCacheHitCount() {
return incrementCacheHitCount(null);
public void incrementCacheHitCount() {
incrementCacheHitCount(null);
}

@Override
Expand Down
59 changes: 30 additions & 29 deletions src/main/java/org/dataloader/stats/SimpleStatisticsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.dataloader.stats.context.IncrementLoadCountStatisticsContext;
import org.dataloader.stats.context.IncrementLoadErrorCountStatisticsContext;

import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;

/**
* This simple collector uses {@link java.util.concurrent.atomic.AtomicLong}s to collect
Expand All @@ -15,72 +15,73 @@
* @see org.dataloader.stats.StatisticsCollector
*/
public class SimpleStatisticsCollector implements StatisticsCollector {
private final AtomicLong loadCount = new AtomicLong();
private final AtomicLong batchInvokeCount = new AtomicLong();
private final AtomicLong batchLoadCount = new AtomicLong();
private final AtomicLong cacheHitCount = new AtomicLong();
private final AtomicLong batchLoadExceptionCount = new AtomicLong();
private final AtomicLong loadErrorCount = new AtomicLong();

private final LongAdder loadCount = new LongAdder();
private final LongAdder batchInvokeCount = new LongAdder();
private final LongAdder batchLoadCount = new LongAdder();
private final LongAdder cacheHitCount = new LongAdder();
private final LongAdder batchLoadExceptionCount = new LongAdder();
private final LongAdder loadErrorCount = new LongAdder();

@Override
public <K> long incrementLoadCount(IncrementLoadCountStatisticsContext<K> context) {
return loadCount.incrementAndGet();
public <K> void incrementLoadCount(IncrementLoadCountStatisticsContext<K> context) {
loadCount.increment();
}

@Deprecated
@Override
public long incrementLoadCount() {
return incrementLoadCount(null);
public void incrementLoadCount() {
incrementLoadCount(null);
}

@Override
public <K> long incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext<K> context) {
return loadErrorCount.incrementAndGet();
public <K> void incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext<K> context) {
loadErrorCount.increment();
}

@Deprecated
@Override
public long incrementLoadErrorCount() {
return incrementLoadErrorCount(null);
public void incrementLoadErrorCount() {
incrementLoadErrorCount(null);
}

@Override
public <K> long incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountByStatisticsContext<K> context) {
batchInvokeCount.incrementAndGet();
return batchLoadCount.addAndGet(delta);
public <K> void incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountByStatisticsContext<K> context) {
batchInvokeCount.increment();
batchLoadCount.add(delta);
}

@Deprecated
@Override
public long incrementBatchLoadCountBy(long delta) {
return incrementBatchLoadCountBy(delta, null);
public void incrementBatchLoadCountBy(long delta) {
incrementBatchLoadCountBy(delta, null);
}

@Override
public <K> long incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext<K> context) {
return batchLoadExceptionCount.incrementAndGet();
public <K> void incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext<K> context) {
batchLoadExceptionCount.increment();
}

@Deprecated
@Override
public long incrementBatchLoadExceptionCount() {
return incrementBatchLoadExceptionCount(null);
public void incrementBatchLoadExceptionCount() {
incrementBatchLoadExceptionCount(null);
}

@Override
public <K> long incrementCacheHitCount(IncrementCacheHitCountStatisticsContext<K> context) {
return cacheHitCount.incrementAndGet();
public <K> void incrementCacheHitCount(IncrementCacheHitCountStatisticsContext<K> context) {
cacheHitCount.increment();
}

@Deprecated
@Override
public long incrementCacheHitCount() {
return incrementCacheHitCount(null);
public void incrementCacheHitCount() {
incrementCacheHitCount(null);
}

@Override
public Statistics getStatistics() {
return new Statistics(loadCount.get(), loadErrorCount.get(), batchInvokeCount.get(), batchLoadCount.get(), batchLoadExceptionCount.get(), cacheHitCount.get());
return new Statistics(loadCount.sum(), loadErrorCount.sum(), batchInvokeCount.sum(), batchLoadCount.sum(), batchLoadExceptionCount.sum(), cacheHitCount.sum());
}

@Override
Expand Down
44 changes: 15 additions & 29 deletions src/main/java/org/dataloader/stats/StatisticsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,47 @@ public interface StatisticsCollector {
*
* @param <K> the class of the key in the data loader
* @param context the context containing metadata of the data loader invocation
*
* @return the current value after increment
*/
default <K> long incrementLoadCount(IncrementLoadCountStatisticsContext<K> context) {
return incrementLoadCount();
default <K> void incrementLoadCount(IncrementLoadCountStatisticsContext<K> context) {
incrementLoadCount();
}

/**
* Called to increment the number of loads
*
* @deprecated use {@link #incrementLoadCount(IncrementLoadCountStatisticsContext)}
* @return the current value after increment
*/
@Deprecated
long incrementLoadCount();
void incrementLoadCount();

/**
* Called to increment the number of loads that resulted in an object deemed in error
*
* @param <K> the class of the key in the data loader
* @param context the context containing metadata of the data loader invocation
*
* @return the current value after increment
*/
default <K> long incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext<K> context) {
return incrementLoadErrorCount();
default <K> void incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext<K> context) {
incrementLoadErrorCount();
}

/**
* Called to increment the number of loads that resulted in an object deemed in error
*
* @deprecated use {@link #incrementLoadErrorCount(IncrementLoadErrorCountStatisticsContext)}
* @return the current value after increment
*/
@Deprecated
long incrementLoadErrorCount();
void incrementLoadErrorCount();

/**
* Called to increment the number of batch loads
*
* @param <K> the class of the key in the data loader
* @param delta how much to add to the count
* @param context the context containing metadata of the data loader invocation
*
* @return the current value after increment
*/
default <K> long incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountByStatisticsContext<K> context) {
return incrementBatchLoadCountBy(delta);
default <K> void incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountByStatisticsContext<K> context) {
incrementBatchLoadCountBy(delta);
}

/**
Expand All @@ -74,52 +67,45 @@ default <K> long incrementBatchLoadCountBy(long delta, IncrementBatchLoadCountBy
* @param delta how much to add to the count
*
* @deprecated use {@link #incrementBatchLoadCountBy(long, IncrementBatchLoadCountByStatisticsContext)}
* @return the current value after increment
*/
@Deprecated
long incrementBatchLoadCountBy(long delta);
void incrementBatchLoadCountBy(long delta);

/**
* Called to increment the number of batch loads exceptions
*
* @param <K> the class of the key in the data loader
* @param context the context containing metadata of the data loader invocation
*
* @return the current value after increment
*/
default <K> long incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext<K> context) {
return incrementBatchLoadExceptionCount();
default <K> void incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext<K> context) {
incrementBatchLoadExceptionCount();
}

/**
* Called to increment the number of batch loads exceptions
*
* @deprecated use {@link #incrementBatchLoadExceptionCount(IncrementBatchLoadExceptionCountStatisticsContext)}
* @return the current value after increment
*/
@Deprecated
long incrementBatchLoadExceptionCount();
void incrementBatchLoadExceptionCount();

/**
* Called to increment the number of cache hits
*
* @param <K> the class of the key in the data loader
* @param context the context containing metadata of the data loader invocation
*
* @return the current value after increment
*/
default <K> long incrementCacheHitCount(IncrementCacheHitCountStatisticsContext<K> context) {
return incrementCacheHitCount();
default <K> void incrementCacheHitCount(IncrementCacheHitCountStatisticsContext<K> context) {
incrementCacheHitCount();
}

/**
* Called to increment the number of cache hits
*
* @deprecated use {@link #incrementCacheHitCount(IncrementCacheHitCountStatisticsContext)}
* @return the current value after increment
*/
@Deprecated
long incrementCacheHitCount();
void incrementCacheHitCount();

/**
* @return the statistics that have been gathered to this point in time
Expand Down
Loading