use of java.util.concurrent.atomic.AtomicIntegerArray in project athenz by yahoo.
the class ZpeMetric method increment.
// to increment a metric counter by 1
public void increment(String metricName, String domainName) {
if (statsEnabled) {
if (!counter.containsKey(domainName)) {
counter.putIfAbsent(domainName, new AtomicIntegerArray(DomainMetricType.LOAD_DOMAIN_GOOD.ordinal() + 1));
}
Integer index = com.yahoo.athenz.zts.DomainMetricType.valueOf(metricName).ordinal();
counter.get(domainName).incrementAndGet(index);
}
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_evaluate_array_numbers.
/**
* Test the evaluate() api that returns an array of numbers. Functionality based on Snippet308.
* Only wait till success. Otherwise timeout after 3 seconds.
*/
@Test
public void test_evaluate_array_numbers() {
// Bug 509411
assumeFalse(webkit1SkipMsg(), isWebkit1);
// Small note:
// evaluate() returns 'Double' type. Java doesn't have AtomicDouble
// for convienience we simply convert double to int as we're dealing with integers anyway.
final AtomicIntegerArray atomicIntArray = new AtomicIntegerArray(3);
atomicIntArray.set(0, -1);
browser.addProgressListener(completedAdapter(event -> {
Object[] evalResult = (Object[]) browser.evaluate("return new Array(1,2,3)");
atomicIntArray.set(0, ((Double) evalResult[0]).intValue());
atomicIntArray.set(1, ((Double) evalResult[1]).intValue());
atomicIntArray.set(2, ((Double) evalResult[2]).intValue());
if (debug_verbose_output)
System.out.println("Node value: " + evalResult);
}));
browser.setText("<html><body><p id='myid'>HelloWorld</p></body></html>");
shell.open();
AtomicReference<String> additionalErrorInfo = new AtomicReference<>("");
boolean passed = waitForPassCondition(() -> {
if (atomicIntArray.get(0) != -1) {
if (atomicIntArray.get(0) == 1 && atomicIntArray.get(1) == 2 && atomicIntArray.get(2) == 3) {
return true;
} else {
additionalErrorInfo.set("Resulting numbers in the array are not as expected");
}
}
return false;
});
String message = "".equals(additionalErrorInfo.get()) ? "Javascript did not call java" : "Javasscript called java, but passed wrong values: " + additionalErrorInfo.get();
assertTrue(message, passed);
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project ffx by mjschnie.
the class SharedIntegerMatrix method reduce.
/**
* Combine this matrix reduction variable at the given row and column with
* the given value using the given operation. (This matrix <TT>[r,c]</TT>)
* is set to (this matrix <TT>[r,c]</TT>) <I>op</I> (<TT>value</TT>), then
* (this matrix <TT>[r,c]</TT>) is returned.
*
* @param r Row index.
* @param c Column index.
* @param value Value.
* @param op Binary operation.
* @return (This matrix <TT>[r,c]</TT>) <I>op</I> (<TT>value</TT>).
*/
public int reduce(int r, int c, int value, IntegerOp op) {
AtomicIntegerArray myMatrix_r = myMatrix[r];
for (; ; ) {
int oldvalue = myMatrix_r.get(c);
int newvalue = op.op(oldvalue, value);
if (myMatrix_r.compareAndSet(c, oldvalue, newvalue)) {
return newvalue;
}
}
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project MyPerf4J by ThinkpadNC5.
the class RecordMemSaveTest method main.
public static void main(String[] args) {
Map<Integer, AtomicInteger> timingMap = initMap();
AtomicIntegerArray timingArr = initArr();
int idx = 0;
int[] sortedArr = new int[getEffectiveRecordCount(timingMap, timingArr) * 2];
for (int i = 0; i < timingArr.length(); ++i) {
int count = timingArr.get(i);
if (count > 0) {
sortedArr[idx++] = i;
sortedArr[idx++] = count;
}
}
System.out.println(Arrays.toString(fillMapRecord(timingMap, sortedArr, idx)));
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project MyPerf4J by ThinkpadNC5.
the class RecordMemSaveTest method initArr.
private static AtomicIntegerArray initArr() {
AtomicIntegerArray arr = new AtomicIntegerArray(7);
arr.set(0, 10);
arr.set(1, 11);
arr.set(2, 12);
arr.set(3, 13);
arr.set(4, 14);
arr.set(5, 0);
arr.set(6, 0);
return arr;
}
Aggregations