本文整理汇总了Java中javax.annotation.concurrent.GuardedBy类的典型用法代码示例。如果您正苦于以下问题:Java GuardedBy类的具体用法?Java GuardedBy怎么用?Java GuardedBy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GuardedBy类属于javax.annotation.concurrent包,在下文中一共展示了GuardedBy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateFileCacheSizeLimit
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
/**
* Helper method that sets the cache size limit to be either a high, or a low limit.
* If there is not enough free space to satisfy the high limit, it is set to the low limit.
*/
@GuardedBy("mLock")
private void updateFileCacheSizeLimit() {
// Test if mCacheSizeLimit can be set to the high limit
boolean isAvailableSpaceLowerThanHighLimit;
StatFsHelper.StorageType storageType =
mStorage.isExternal()
? StatFsHelper.StorageType.EXTERNAL
: StatFsHelper.StorageType.INTERNAL;
isAvailableSpaceLowerThanHighLimit =
mStatFsHelper.testLowDiskSpace(
storageType,
mDefaultCacheSizeLimit - mCacheStats.getSize());
if (isAvailableSpaceLowerThanHighLimit) {
mCacheSizeLimit = mLowDiskSpaceCacheSizeLimit;
} else {
mCacheSizeLimit = mDefaultCacheSizeLimit;
}
}
示例2: removeFromChain
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
/**
* Removes an entry from within a table. All entries following the removed node can stay, but
* all preceding ones need to be cloned.
*
* <p>This method does not decrement count for the removed entry, but does decrement count for
* all partially collected entries which are skipped. As such callers which are modifying count
* must re-read it after calling removeFromChain.
*
* @param first the first entry of the table
* @param entry the entry being removed from the table
* @return the new first entry for the table
*/
@GuardedBy("this")
E removeFromChain(E first, E entry) {
int newCount = count;
E newFirst = entry.getNext();
for (E e = first; e != entry; e = e.getNext()) {
E next = copyEntry(e, newFirst);
if (next != null) {
newFirst = next;
} else {
newCount--;
}
}
this.count = newCount;
return newFirst;
}
示例3: createHistoryProxy
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
/**
* Create a new history proxy for a given shard.
*
* @throws InversibleLockException if the shard is being reconnected
*/
@GuardedBy("lock")
private ProxyHistory createHistoryProxy(final Long shard) {
final AbstractClientConnection<ShardBackendInfo> connection = client.getConnection(shard);
final LocalHistoryIdentifier proxyId = new LocalHistoryIdentifier(identifier.getClientId(),
identifier.getHistoryId(), shard);
LOG.debug("Created proxyId {} for history {} shard {}", proxyId, identifier, shard);
final ProxyHistory ret = createHistoryProxy(proxyId, connection);
// Request creation of the history, if it is not the single history
if (ret.getIdentifier().getHistoryId() != 0) {
connection.sendRequest(new CreateLocalHistoryRequest(ret.getIdentifier(), connection.localActor()),
this::createHistoryCallback);
}
return ret;
}
示例4: recordWrite
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
/**
* Updates eviction metadata that {@code entry} was just written. This currently amounts to
* adding {@code entry} to relevant eviction lists.
*/
@GuardedBy("this")
void recordWrite(ReferenceEntry<K, V> entry, int weight, long now) {
// we are already under lock, so drain the recency queue immediately
drainRecencyQueue();
totalWeight += weight;
if (map.recordsAccess()) {
entry.setAccessTime(now);
}
if (map.recordsWrite()) {
entry.setWriteTime(now);
}
accessQueue.add(entry);
writeQueue.add(entry);
}
示例5: processTransaction
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
/**
* Process a ready transaction. The caller needs to ensure that
* each transaction is seen only once by this method.
*
* @param tx Transaction which needs processing.
*/
@GuardedBy("this")
private void processTransaction(@Nonnull final PingPongTransaction tx) {
if (failed) {
LOG.debug("Cancelling transaction {}", tx);
tx.getTransaction().cancel();
return;
}
LOG.debug("Submitting transaction {}", tx);
if (!INFLIGHT_UPDATER.compareAndSet(this, null, tx)) {
LOG.warn("Submitting transaction {} while {} is still running", tx, inflightTx);
}
Futures.addCallback(tx.getTransaction().submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
transactionSuccessful(tx, result);
}
@Override
public void onFailure(final Throwable t) {
transactionFailed(tx, t);
}
}, MoreExecutors.directExecutor());
}
示例6: evictEntries
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
/**
* Performs eviction if the segment is over capacity. Avoids flushing the entire cache if the
* newest entry exceeds the maximum weight all on its own.
*
* @param newest the most recently added entry
*/
@GuardedBy("this")
void evictEntries(ReferenceEntry<K, V> newest) {
if (!map.evictsBySize()) {
return;
}
drainRecencyQueue();
// If the newest entry by itself is too heavy for the segment, don't bother evicting
// anything else, just that
if (newest.getValueReference().getWeight() > maxSegmentWeight) {
if (!removeEntry(newest, newest.getHash(), RemovalCause.SIZE)) {
throw new AssertionError();
}
}
while (totalWeight > maxSegmentWeight) {
ReferenceEntry<K, V> e = getNextEvictable();
if (!removeEntry(e, e.getHash(), RemovalCause.SIZE)) {
throw new AssertionError();
}
}
}
示例7: removeValueFromChain
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
@GuardedBy("this")
@Nullable
ReferenceEntry<K, V> removeValueFromChain(
ReferenceEntry<K, V> first,
ReferenceEntry<K, V> entry,
@Nullable K key,
int hash,
V value,
ValueReference<K, V> valueReference,
RemovalCause cause) {
enqueueNotification(key, hash, value, valueReference.getWeight(), cause);
writeQueue.remove(entry);
accessQueue.remove(entry);
if (valueReference.isLoading()) {
valueReference.notifyNewValue(null);
return first;
} else {
return removeEntryFromChain(first, entry);
}
}
示例8: endWaitingFor
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
/**
* Records that the current thread is no longer waiting on the specified guard.
*/
@GuardedBy("lock")
private void endWaitingFor(Guard guard) {
int waiters = --guard.waiterCount;
if (waiters == 0) {
// unlink guard from activeGuards
for (Guard p = activeGuards, pred = null; ; pred = p, p = p.next) {
if (p == guard) {
if (pred == null) {
activeGuards = p.next;
} else {
pred.next = p.next;
}
p.next = null; // help GC
break;
}
}
}
}
示例9: awaitNanos
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
/**
* Caller should check before calling that guard is not satisfied.
*/
@GuardedBy("lock")
private boolean awaitNanos(Guard guard, long nanos, boolean signalBeforeWaiting)
throws InterruptedException {
boolean firstTime = true;
try {
do {
if (nanos <= 0L) {
return false;
}
if (firstTime) {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
firstTime = false;
}
nanos = guard.condition.awaitNanos(nanos);
} while (!guard.isSatisfied());
return true;
} finally {
if (!firstTime) {
endWaitingFor(guard);
}
}
}
示例10: removeEntryForTesting
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
@GuardedBy("this")
boolean removeEntryForTesting(E entry) {
int hash = entry.getHash();
int newCount = this.count - 1;
AtomicReferenceArray<E> table = this.table;
int index = hash & (table.length() - 1);
E first = table.get(index);
for (E e = first; e != null; e = e.getNext()) {
if (e == entry) {
++modCount;
E newFirst = removeFromChain(first, e);
newCount = this.count - 1;
table.set(index, newFirst);
this.count = newCount; // write-volatile
return true;
}
}
return false;
}
示例11: copyEntry
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
/**
* Copies {@code original} into a new entry chained to {@code newNext}. Returns the new entry,
* or {@code null} if {@code original} was already garbage collected.
*/
@GuardedBy("this")
ReferenceEntry<K, V> copyEntry(ReferenceEntry<K, V> original, ReferenceEntry<K, V> newNext) {
if (original.getKey() == null) {
// key collected
return null;
}
ValueReference<K, V> valueReference = original.getValueReference();
V value = valueReference.get();
if ((value == null) && valueReference.isActive()) {
// value collected
return null;
}
ReferenceEntry<K, V> newEntry = map.entryFactory.copyEntry(this, original, newNext);
newEntry.setValueReference(valueReference.copyFor(this.valueReferenceQueue, value, newEntry));
return newEntry;
}
示例12: scheduleTimer
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
/**
* Schedule a timer to fire on the actor thread after a delay.
*
* @param delay Delay, in nanoseconds
*/
@GuardedBy("lock")
private void scheduleTimer(final long delay) {
if (haveTimer) {
LOG.debug("{}: timer already scheduled on {}", context.persistenceId(), this);
return;
}
if (queue.hasSuccessor()) {
LOG.debug("{}: connection {} has a successor, not scheduling timer", context.persistenceId(), this);
return;
}
// If the delay is negative, we need to schedule an action immediately. While the caller could have checked
// for that condition and take appropriate action, but this is more convenient and less error-prone.
final long normalized = delay <= 0 ? 0 : Math.min(delay, context.config().getBackendAlivenessTimerInterval());
final FiniteDuration dur = FiniteDuration.fromNanos(normalized);
LOG.debug("{}: connection {} scheduling timeout in {}", context.persistenceId(), this, dur);
context.executeInActor(this::runTimer, dur);
haveTimer = true;
}
示例13: expireEntries
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
@GuardedBy("this")
void expireEntries(long now) {
drainRecencyQueue();
ReferenceEntry<K, V> e;
while ((e = writeQueue.peek()) != null && map.isExpired(e, now)) {
if (!removeEntry(e, e.getHash(), RemovalCause.EXPIRED)) {
throw new AssertionError();
}
}
while ((e = accessQueue.peek()) != null && map.isExpired(e, now)) {
if (!removeEntry(e, e.getHash(), RemovalCause.EXPIRED)) {
throw new AssertionError();
}
}
}
示例14: removeEntryFromChain
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
@GuardedBy("this")
@Nullable
ReferenceEntry<K, V> removeEntryFromChain(
ReferenceEntry<K, V> first, ReferenceEntry<K, V> entry) {
int newCount = count;
ReferenceEntry<K, V> newFirst = entry.getNext();
for (ReferenceEntry<K, V> e = first; e != entry; e = e.getNext()) {
ReferenceEntry<K, V> next = copyEntry(e, newFirst);
if (next != null) {
newFirst = next;
} else {
removeCollectedEntry(e);
newCount--;
}
}
this.count = newCount;
return newFirst;
}
示例15: terminated
import javax.annotation.concurrent.GuardedBy; //导入依赖的package包/类
@GuardedBy("monitor")
private void terminated(final State from) {
switch (from) {
case NEW:
TERMINATED_FROM_NEW_CALLBACK.enqueueOn(listeners);
break;
case RUNNING:
TERMINATED_FROM_RUNNING_CALLBACK.enqueueOn(listeners);
break;
case STOPPING:
TERMINATED_FROM_STOPPING_CALLBACK.enqueueOn(listeners);
break;
case STARTING:
case TERMINATED:
case FAILED:
default:
throw new AssertionError();
}
}