use of java.util.concurrent.atomic.LongAdder in project cxf by apache.
the class NioBookStore method uploadBookStream.
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public void uploadBookStream(@Suspended AsyncResponse response) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final byte[] buffer = new byte[4096];
final LongAdder adder = new LongAdder();
new NioReadEntity(// read handler
in -> {
final int n = in.read(buffer);
if (n > 0) {
adder.add(n);
out.write(buffer, 0, n);
}
}, // completion handler
() -> {
closeOutputStream(out);
response.resume("Book Store uploaded: " + adder.longValue() + " bytes");
});
}
use of java.util.concurrent.atomic.LongAdder in project drools by kiegroup.
the class CompositeAgendaTest method testCreateHaltDisposeAgenda.
@Test
@Ignore
public void testCreateHaltDisposeAgenda() {
final String drl = " import org.drools.compiler.integrationtests.facts.*;\n" + " declare A @role( event ) end\n" + " global java.util.concurrent.atomic.LongAdder firings;\n" + " rule R0 when\n" + " A( value > 0,$Aid: id )\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R1 when\n" + " A(value > 1)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R2 when\n" + " A(value > 2)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R3 when\n" + " A(value > 3)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R4 when\n" + " A(value > 4)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R5 when\n" + " A(value > 5)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R6 when\n" + " A(value > 6)\n" + " then\n" + " firings.add(1);\n" + " end\n" + " rule R7 when\n" + " A(value > 7)\n" + " then\n" + " firings.add(1);\n" + " end";
final KieBaseConfiguration kieBaseConfiguration = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kieBaseConfiguration.setOption(MultithreadEvaluationOption.YES);
kieBaseConfiguration.setOption(EventProcessingOption.STREAM);
final KieBase kieBase = new KieHelper().addContent(drl, ResourceType.DRL).build(kieBaseConfiguration);
final KieSession kieSession = kieBase.newKieSession();
final LongAdder firingCounter = new LongAdder();
kieSession.setGlobal("firings", firingCounter);
final ExecutorService executor = Executors.newFixedThreadPool(2);
executor.submit(() -> kieSession.fireUntilHalt());
final EventInsertThread eventInsertThread = new EventInsertThread(kieSession);
executor.submit(eventInsertThread);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
kieSession.halt();
eventInsertThread.setActive(false);
kieSession.dispose();
executor.shutdown();
try {
if (!executor.awaitTermination(10, TimeUnit.MILLISECONDS)) {
executor.shutdownNow();
}
} catch (InterruptedException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of java.util.concurrent.atomic.LongAdder in project mapdb by jankotek.
the class ConcurrentHashMap8Test method testMappedForEachEntrySequentially.
/**
* Mapped forEachEntrySequentially traverses the given
* transformations of all entries
*/
public void testMappedForEachEntrySequentially() {
LongAdder adder = new LongAdder();
ConcurrentHashMap<Long, Long> m = longMap();
m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long, Long> e) -> Long.valueOf(e.getKey().longValue() + e.getValue().longValue()), (Long x) -> adder.add(x.longValue()));
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
use of java.util.concurrent.atomic.LongAdder in project mapdb by jankotek.
the class ConcurrentHashMap8Test method testMappedForEachInParallel.
/**
* Mapped forEachInParallel traverses the given
* transformations of all mappings
*/
public void testMappedForEachInParallel() {
LongAdder adder = new LongAdder();
ConcurrentHashMap<Long, Long> m = longMap();
m.forEach(1L, (Long x, Long y) -> Long.valueOf(x.longValue() + y.longValue()), (Long x) -> adder.add(x.longValue()));
assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
use of java.util.concurrent.atomic.LongAdder in project mapdb by jankotek.
the class ConcurrentHashMap8Test method testKeySetSpliterator.
/**
* KeySetView.spliterator returns spliterator over the elements in this set
*/
public void testKeySetSpliterator() {
LongAdder adder = new LongAdder();
ConcurrentHashMap map = map5();
Set set = map.keySet();
Spliterator<Integer> sp = set.spliterator();
checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL);
assertEquals(sp.estimateSize(), map.size());
Spliterator<Integer> sp2 = sp.trySplit();
sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
long v = adder.sumThenReset();
sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
long v2 = adder.sum();
assertEquals(v + v2, 15);
}
Aggregations