/** Sets the stopped. */ public void setStopped( boolean stopped ) { status.updateAndGet( v -> stopped ? v | BitMaskStatus.STOPPED.mask : ( BitMaskStatus.BIT_STATUS_SUM ^ BitMaskStatus.STOPPED.mask ) & v ); }
/** * Sets whether the transformation is running. * * @param running true if the transformation is running, false otherwise */ public void setRunning( boolean running ) { status.updateAndGet( v -> running ? v | RUNNING.mask : ( BIT_STATUS_SUM ^ RUNNING.mask ) & v ); }
/** * Sets whether the transformation is preparing for execution. * * @param preparing true if the transformation is preparing for execution, false otherwise */ public void setPreparing( boolean preparing ) { status.updateAndGet( v -> preparing ? v | PREPARING.mask : ( BIT_STATUS_SUM ^ PREPARING.mask ) & v ); }
public void setFinished( boolean finished ) { status.updateAndGet( v -> finished ? v | BitMaskStatus.FINISHED.mask : ( BitMaskStatus.BIT_STATUS_SUM ^ BitMaskStatus.FINISHED.mask ) & v ); }
/** * Sets whether the transformation is initializing. * * @param initializing true if the transformation is initializing, false otherwise */ public void setInitializing( boolean initializing ) { status.updateAndGet( v -> initializing ? v | INITIALIZING.mask : ( BIT_STATUS_SUM ^ INITIALIZING.mask ) & v ); }
protected void setInitialized( boolean initialized ) { status.updateAndGet( v -> initialized ? v | BitMaskStatus.INITIALIZED.mask : ( BitMaskStatus.BIT_STATUS_SUM ^ BitMaskStatus.INITIALIZED.mask ) & v ); }
public void setPaused( boolean paused ) { status.updateAndGet( v -> paused ? v | PAUSED.mask : ( BIT_STATUS_SUM ^ PAUSED.mask ) & v ); }
public void setStopped( boolean stopped ) { status.updateAndGet( v -> stopped ? v | STOPPED.mask : ( BIT_STATUS_SUM ^ STOPPED.mask ) & v ); }
protected void setActive( boolean active ) { status.updateAndGet( v -> active ? v | BitMaskStatus.ACTIVE.mask : ( BitMaskStatus.BIT_STATUS_SUM ^ BitMaskStatus.ACTIVE.mask ) & v ); }
protected void setFinished( boolean finished ) { status.updateAndGet( v -> finished ? v | FINISHED.mask : ( BIT_STATUS_SUM ^ FINISHED.mask ) & v ); }
/** * Sets the record in a particular position in the dataset, WITHOUT updating * the internal meta-info and returns the previous value (null if not existed). * This method is similar to set() and it allows quick updates * on the dataset. Nevertheless it is not advised to use this method because * unless you explicitly call the recalculateMeta() method, the meta data * will be corrupted. If you do use this method, MAKE sure you perform the * recalculation after you are done with the updates. * * @param rId * @param r * @return */ public Record _unsafe_set(Integer rId, Record r) { //move ahead the next id data.atomicNextAvailableRecordId.updateAndGet(x -> (x<rId)?Math.max(x+1,rId+1):x); return data.records.put(rId, r); }
@Override public void lengthen() { int factor = prolongationFactor.updateAndGet((i) -> { if (i > 0) { return ++i; } else { return 1; } }); Duration candidate = lengthenFunction.apply(delay, factor); delay = max.compareTo(candidate) > 0 ? candidate : max; }
@Override public void shorten() { int factor = prolongationFactor.updateAndGet((i) -> { if (i < 0) { return --i; } else { return -1; } }); Duration candidate = shortenFunction.apply(delay, -factor); delay = min.compareTo(candidate) > 0 ? min : candidate; }
private static void testUpdate() { atomicInt.set(0); ExecutorService executor = Executors.newFixedThreadPool(2); IntStream.range(0, NUM_INCREMENTS) .forEach(i -> { Runnable task = () -> atomicInt.updateAndGet(n -> n + 2); executor.submit(task); }); ConcurrentUtils.stop(executor); System.out.format("Update: %d\n", atomicInt.get()); }
private ManagedSelector chooseSelector() { return _selectors[_selectorIndex.updateAndGet(_selectorIndexUpdate)]; }
@Nonnull @Override public E previous() { return this.objects.get(this.cursor.updateAndGet(i -> { if (i == 0) { return this.size - 1; } return i - 1; })); }
@Nonnull @Override public E next() { return this.objects.get(this.cursor.updateAndGet(i -> { int n = i + 1; if (n >= this.size) { return 0; } return n; })); }
@Override public void shorten() { int factor = prolongationFactor.updateAndGet((i) -> { if (i < 0) { return --i; } else { return -1; } }); Duration candidate = shortenFunction.apply(delay, -factor); delay = min.compareTo(candidate) > 0 ? min : candidate; }
void increment(int incValue, AtomicInteger i) { // The lambda is closed over incValue. Because of this the created IntUnaryOperator // will have a field which contains incValue. Because of this a new instance must // be allocated on every call to the increment method. i.updateAndGet(value -> incValue + value); // The lambda is not closed over anything. The same IntBinaryOperator instance // can be used on every call to the increment method, nothing need to be allocated. i.accumulateAndGet(incValue, (incValueParam, value) -> incValueParam + value); }
public static void main6(String[] args) { AtomicInteger atomic = new AtomicInteger(); int cur; do { cur = atomic.get(); } while (!atomic.compareAndSet(cur, cur * 2)); atomic.updateAndGet(x -> x * 2); }