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

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

Introduction

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

Prototype

public abstract V get(T obj);

Source Link

Document

Returns the current value held in the field of the given object managed by this updater.

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 w  w.  jav a2  s. 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));
    }
}