Search in sources :

Example 41 with AtomicIntegerArray

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);
    }
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 42 with AtomicIntegerArray

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);
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) HttpURLConnection(java.net.HttpURLConnection) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) URL(java.net.URL) Assume.assumeFalse(org.junit.Assume.assumeFalse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) TitleListener(org.eclipse.swt.browser.TitleListener) VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Point(org.eclipse.swt.graphics.Point) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) TestName(org.junit.rules.TestName) LocationListener.changedAdapter(org.eclipse.swt.browser.LocationListener.changedAdapter) VisibilityWindowListener.showAdapter(org.eclipse.swt.browser.VisibilityWindowListener.showAdapter) WindowEvent(org.eclipse.swt.browser.WindowEvent) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressListener.completedAdapter(org.eclipse.swt.browser.ProgressListener.completedAdapter) Assert.fail(org.junit.Assert.fail) SWTException(org.eclipse.swt.SWTException) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) FillLayout(org.eclipse.swt.layout.FillLayout) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Before(org.junit.Before) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) MalformedURLException(java.net.MalformedURLException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) LocationListener.changingAdapter(org.eclipse.swt.browser.LocationListener.changingAdapter) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) LocationEvent(org.eclipse.swt.browser.LocationEvent) Assume.assumeTrue(org.junit.Assume.assumeTrue) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 43 with AtomicIntegerArray

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;
        }
    }
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 44 with AtomicIntegerArray

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)));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 45 with AtomicIntegerArray

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;
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Aggregations

AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)85 Test (org.junit.Test)24 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 Test (org.junit.jupiter.api.Test)11 CountDownLatch (java.util.concurrent.CountDownLatch)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 List (java.util.List)6 AtomicLongArray (java.util.concurrent.atomic.AtomicLongArray)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 JSONArray (com.alibaba.fastjson.JSONArray)3 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 CacheException (javax.cache.CacheException)3 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 GridRandom (org.apache.ignite.internal.util.GridRandom)3 CAX (org.apache.ignite.internal.util.typedef.CAX)3