use of java.util.concurrent.atomic.LongAdder in project aries by apache.
the class AbstractPushStreamImpl method forEachEvent.
@Override
public Promise<Long> forEachEvent(PushEventConsumer<? super T> action) {
Deferred<Long> d = new Deferred<>();
LongAdder la = new LongAdder();
updateNext((event) -> {
try {
switch(event.getType()) {
case DATA:
long value = action.accept(event);
la.add(value);
return value;
case CLOSE:
try {
action.accept(event);
} finally {
d.resolve(Long.valueOf(la.sum()));
}
break;
case ERROR:
try {
action.accept(event);
} finally {
d.fail(event.getFailure());
}
break;
}
return ABORT;
} catch (Exception e) {
close(PushEvent.error(e));
return ABORT;
}
});
begin();
return d.getPromise();
}
use of java.util.concurrent.atomic.LongAdder in project aries by apache.
the class AbstractPushStreamImpl method count.
@Override
public Promise<Long> count() {
Deferred<Long> d = new Deferred<>();
LongAdder counter = new LongAdder();
updateNext((event) -> {
try {
switch(event.getType()) {
case DATA:
counter.add(1);
return CONTINUE;
case CLOSE:
d.resolve(Long.valueOf(counter.sum()));
break;
case ERROR:
d.fail(event.getFailure());
break;
}
close(event.nodata());
return ABORT;
} catch (Exception e) {
close(PushEvent.error(e));
return ABORT;
}
});
begin();
return d.getPromise();
}
use of java.util.concurrent.atomic.LongAdder in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testUnsizedIntsCountSeq.
/**
* A sequential unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCountSeq() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.ints().limit(size).forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java.util.concurrent.atomic.LongAdder in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testUnsizedDoublesCount.
/**
* A parallel unsized stream of doubles generates at least 100 values
*/
public void testUnsizedDoublesCount() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.doubles().limit(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java.util.concurrent.atomic.LongAdder in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testUnsizedIntsCount.
/**
* A parallel unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCount() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.ints().limit(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
Aggregations