Example usage for java.util.concurrent.atomic AtomicReferenceFieldUpdater set

List of usage examples for java.util.concurrent.atomic AtomicReferenceFieldUpdater set

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicReferenceFieldUpdater set.

Prototype

public abstract void set(T obj, V newValue);

Source Link

Document

Sets the field of the given object managed by this updater to the given updated value.

Usage

From source file:org.apache.distributedlog.BKLogSegmentWriter.java

void scheduleFlushWithDelayIfNeeded(final Callable<?> callable,
        final AtomicReferenceFieldUpdater<BKLogSegmentWriter, ScheduledFuture> scheduledFutureRefUpdater) {
    final long delayMs = Math.max(0,
            minDelayBetweenImmediateFlushMs - lastTransmit.elapsed(TimeUnit.MILLISECONDS));
    final ScheduledFuture scheduledFuture = scheduledFutureRefUpdater.get(this);
    if ((null == scheduledFuture) || scheduledFuture.isDone()) {
        scheduledFutureRefUpdater.set(this, scheduler.schedule(new Runnable() {
            @Override//from   w ww .  j av  a  2s  .com
            public void run() {
                synchronized (this) {
                    scheduledFutureRefUpdater.set(BKLogSegmentWriter.this, null);
                    try {
                        callable.call();

                        // Flush was successful or wasn't needed, the exception should be unset.
                        scheduledFlushExceptionUpdater.set(BKLogSegmentWriter.this, null);
                    } catch (Exception exc) {
                        scheduledFlushExceptionUpdater.set(BKLogSegmentWriter.this, exc);
                        LOG.error("Delayed flush failed", exc);
                    }
                }
            }
        }, delayMs, TimeUnit.MILLISECONDS));
    }
}