Example usage for java.util.concurrent.atomic AtomicInteger get

List of usage examples for java.util.concurrent.atomic AtomicInteger get

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicInteger get.

Prototype

public final int get() 

Source Link

Document

Returns the current value, with memory effects as specified by VarHandle#getVolatile .

Usage

From source file:AtomicUtils.java

public static boolean tryIncrementIfLessThan(final AtomicInteger capacity, final int atmost) {
    int capa;/*from w ww  . j av  a  2 s.  co m*/
    do {
        capa = capacity.get();
        if (capa >= atmost) {
            return false;
        }
    } while (!capacity.compareAndSet(capa, capa + 1));
    return true;
}

From source file:AtomicUtils.java

public static int tryDecrementAndGetIfGreaterThan(final AtomicInteger capacity, final int least) {
    for (;;) {//from   w w  w.  j a v  a 2  s.  c om
        final int current = capacity.get();
        if (current <= least) {
            return current;
        }
        final int next = current - 1;
        if (capacity.compareAndSet(current, next)) {
            return next;
        }
    }
}

From source file:AtomicUtils.java

public static int tryIncrementAndGetIfLessThan(final AtomicInteger capacity, final int upperbound) {
    for (;;) {/*  www  .  ja v  a2 s .  co m*/
        final int current = capacity.get();
        if (current >= upperbound) {
            return upperbound;
        }
        final int next = current + 1;
        if (capacity.compareAndSet(current, next)) {
            return next;
        }
    }
}

From source file:com.brienwheeler.lib.svc.impl.ServiceBaseTestUtil.java

public static void verifyRefCount(StartableServiceBase service, int refCount) {
    AtomicInteger svcRefCount = (AtomicInteger) ReflectionTestUtils.getField(service, "refCount");
    Assert.assertEquals(refCount, svcRefCount.get());
}

From source file:org.eclipse.swt.snippets.Snippet366.java

private static void makeAlignGroup() {
    Group alignGroup = new Group(shell, SWT.None);
    alignGroup.setLayout(new RowLayout());
    alignGroup.setText("Alignment group");

    final AtomicInteger prevDir = new AtomicInteger(0);
    final Button alignmentButton = new Button(alignGroup, SWT.ARROW | SWT.UP);
    alignmentButton.addListener(SWT.MouseDown, event -> {
        switch (prevDir.get()) {
        case 0:/*from ww w.  j  a v a 2s  .c o  m*/
            alignmentButton.setAlignment(SWT.RIGHT);
            prevDir.set(1);
            break;
        case 1:
            alignmentButton.setAlignment(SWT.DOWN);
            prevDir.set(2);
            break;
        case 2:
            alignmentButton.setAlignment(SWT.LEFT);
            prevDir.set(3);
            break;
        case 3:
            alignmentButton.setAlignment(SWT.UP);
            prevDir.set(0);
        default:
            break;
        }
    });
}

From source file:org.eclipse.swt.snippets.Snippet366.java

private static void makeOrientationGroup() {
    Group orientationGroup = new Group(shell, SWT.None);
    orientationGroup.setLayout(new RowLayout());
    orientationGroup.setText("Orientation group");

    final AtomicInteger prevDir = new AtomicInteger(0);
    final Button alignmentButton = new Button(orientationGroup, SWT.ARROW | SWT.RIGHT);
    alignmentButton.addListener(SWT.MouseDown, event -> {
        switch (prevDir.get()) {
        case 0://from   w  w w  .j av a2s .  co  m
            alignmentButton.setOrientation(SWT.LEFT_TO_RIGHT);
            prevDir.set(1);
            break;
        case 1:
            alignmentButton.setOrientation(SWT.RIGHT_TO_LEFT);
            prevDir.set(0);
            break;
        default:
            break;
        }
    });
}

From source file:org.apache.hadoop.hbase.client.AbstractTestAsyncTableRegionReplicasRead.java

protected static int getPrimaryGetCount() {
    AtomicInteger primaryGetCount = REPLICA_ID_TO_COUNT.get(RegionReplicaUtil.DEFAULT_REPLICA_ID);
    return primaryGetCount != null ? primaryGetCount.get() : 0;
}

From source file:com.icloud.framework.core.util.FBUtilities.java

public static void atomicSetMax(AtomicInteger atomic, int i) {
    while (true) {
        int j = atomic.get();
        if (j >= i || atomic.compareAndSet(j, i))
            break;
    }//from   ww w. ja  v a 2s .  com
}

From source file:com.msd.gin.halyard.tools.HalyardExportTest.java

private static int getTriplesCount(String uri, String compression, RDFFormat format) throws Exception {
    InputStream in = FileSystem.get(URI.create(uri), HBaseServerTestInstance.getInstanceConfig())
            .open(new Path(uri));
    try {//from  www.  j  ava2s .co m
        if (compression != null) {
            in = new CompressorStreamFactory().createCompressorInputStream(compression, in);
        }
        RDFParser parser = Rio.createParser(format);
        final AtomicInteger i = new AtomicInteger();
        parser.setRDFHandler(new AbstractRDFHandler() {
            @Override
            public void handleStatement(Statement st) throws RDFHandlerException {
                i.incrementAndGet();
            }
        });
        parser.parse(in, uri);
        return i.get();
    } finally {
        in.close();
    }
}

From source file:Main.java

public static int ThrsafeIncrementIntUpToLimit(AtomicInteger storagePointer, int limitValue) {
    //       unsigned int resultValue;
    //       while (true) {
    //           resultValue = *storagePointer;
    //           if (resultValue == limitValue) {
    //               break;
    //           }
    //           if (ThrsafeCompareExchange((volatile atomicord32 *)storagePointer, (atomicord32)resultValue, (atomicord32)(resultValue + 1))) {
    //               break;
    //           }
    //       }//from   w  w  w  . j ava  2 s.  c  om
    //       return resultValue;
    int resultValue;
    while (true) {
        resultValue = storagePointer.get();
        if (resultValue == limitValue) {
            break;
        }
        if (ThrsafeCompareExchange(storagePointer, resultValue, resultValue + 1)) {
            break;
        }
    }
    return resultValue;
}