@Override protected FIELD getActualValue(OBJECT obj) { return actual.get(obj); } }
void cancelInner() { FilterWhenInner a = CURRENT.get(this); if (a != INNER_CANCELLED) { a = CURRENT.getAndSet(this, INNER_CANCELLED); if (a != null && a != INNER_CANCELLED) { a.cancel(); } } }
public TimeoutsHolder getTimeoutsHolder() { return TIMEOUTS_HOLDER_FIELD.get(this); }
@Override public boolean isDisposed() { Composite o = PARENT.get(this); return o == DISPOSED || o == DONE; }
public Map<K, V> getReadOnly(final C subregistry) { final Map<K, V> snapshot = updater.get(subregistry); return snapshot instanceof FastCopyHashMap ? Collections.unmodifiableMap(snapshot) : snapshot; } }
@SuppressWarnings({ "rawtypes", "unchecked" }) private void addOnComplete(Object action) { for (;;) { Object[] existing = ONCOMPLETE.get(this); Object[] updated = new Object[existing.length + 1]; System.arraycopy(existing, 0, updated, 0, existing.length); updated[existing.length] = action; if (ONCOMPLETE.compareAndSet(this, existing, updated)) { return; } } }
static <T> void addSequence(final T holder, final AtomicReferenceFieldUpdater<T, Sequence[]> updater, final Sequence sequence) { Sequence[] updatedSequences; Sequence[] currentSequences; do { currentSequences = updater.get(holder); updatedSequences = copyOf(currentSequences, currentSequences.length + 1); updatedSequences[currentSequences.length] = sequence; } while (!updater.compareAndSet(holder, currentSequences, updatedSequences)); }
/** * Throws an exception if the managed ledger has been previously fenced. * * @throws ManagedLedgerException */ private void checkFenced() throws ManagedLedgerException { if (STATE_UPDATER.get(this) == State.Fenced) { log.error("[{}] Attempted to use a fenced managed ledger", name); throw new ManagedLedgerFencedException(); } }
private void checkManagedLedgerIsOpen() throws ManagedLedgerException { if (STATE_UPDATER.get(this) == State.Closed) { throw new ManagedLedgerException("ManagedLedger " + name + " has already been closed"); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) private CompletionStage<List<T>> publicStage() { CompletionStage stage = UPDATER.get(this); if (stage == null) { stage = createPublicStage(this.executions); UPDATER.compareAndSet(this, null, stage); } return stage; }
@Override public void shutdown() { stopped = true; PauseDetectorWrapper pauseDetectorWrapper = PAUSE_DETECTOR_UPDATER.get(this); if (pauseDetectorWrapper != null && PAUSE_DETECTOR_UPDATER.compareAndSet(this, pauseDetectorWrapper, null)) { pauseDetectorWrapper.release(); } Map<CommandLatencyId, Latencies> latenciesMap = latencyMetricsRef.get(); if (latencyMetricsRef.compareAndSet(latenciesMap, Collections.emptyMap())) { latenciesMap.values().forEach(Latencies::stop); } }
@Override public boolean isDisposed() { return Disposables.isDisposed(INNER.get(this)); } }
boolean setCurrent(ExpandDepthSubscriber<T> inner) { for (;;) { Object o = CURRENT.get(this); if (o == this) { inner.dispose(); return false; } if (CURRENT.compareAndSet(this, o, inner)) { return true; } } }
public String getState() { return STATE_UPDATER.get(this).toString(); }
void decrementPendingMarkDeleteCount() { if (PENDING_MARK_DELETED_SUBMITTED_COUNT_UPDATER.decrementAndGet(this) == 0) { final State state = STATE_UPDATER.get(this); if (state == State.SwitchingLedger) { // A metadata ledger switch was pending and now we can do it since we don't have any more // outstanding mark-delete requests createNewMetadataLedger(); } } }
/** * Notifies local transaction context that server is resumed, and restarts deployment controller. */ @Override public void resume() { this.suspended = false; localTransactionContextInjectedValue.getValue().resumeRequests(); ServerActivityCallback listener = listenerUpdater.get(this); if (listener != null) { listenerUpdater.compareAndSet(this, listener, null); } deploymentRepositoryInjectedValue.getValue().resume(); }
boolean shouldCloseLedger(LedgerHandle lh) { long now = clock.millis(); if ((lh.getLastAddConfirmed() >= config.getMetadataMaxEntriesPerLedger() || lastLedgerSwitchTimestamp < (now - config.getLedgerRolloverTimeout() * 1000)) && STATE_UPDATER.get(this) != State.Closed) { // It's safe to modify the timestamp since this method will be only called from a callback, implying that // calls will be serialized on one single thread lastLedgerSwitchTimestamp = now; return true; } else { return false; } }
@Override public void asyncReadEntries(final int numberOfEntriesToRead, final ReadEntriesCallback callback, final Object ctx) { checkArgument(numberOfEntriesToRead > 0); if (STATE_UPDATER.get(this) == State.Closed) { callback.readEntriesFailed(new ManagedLedgerException("Cursor was already closed"), ctx); return; } PENDING_READ_OPS_UPDATER.incrementAndGet(this); OpReadEntry op = OpReadEntry.create(this, PositionImpl.get(readPosition), numberOfEntriesToRead, callback, ctx); ledger.asyncReadEntries(op); }
@Test public void syncDisposeIdempotent() { final WorkerTask run = new WorkerTask(() -> {}, null); WorkerTask.THREAD.set(run, Thread.currentThread()); run.dispose(); assertThat((Future<?>) WorkerTask.FUTURE.get(run)).isEqualTo(WorkerTask.SYNC_CANCELLED); run.dispose(); assertThat((Future<?>) WorkerTask.FUTURE.get(run)).isEqualTo(WorkerTask.SYNC_CANCELLED); run.run(); assertThat((Future<?>) WorkerTask.FUTURE.get(run)).isEqualTo(WorkerTask.SYNC_CANCELLED); }