Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2009 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in org.testifyproject.testifyprojectpliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org.testifyproject/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.cache;
import static org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.base.Preconditions.checkNotNull;
import static org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.base.Preconditions.checkState;
import static org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.cache.CacheBuilder.NULL_TICKER;
import static org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.cache.CacheBuilder.UNSET_INT;
import static org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.util.concurrent.MoreExecutors.directExecutor;
import static org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.util.concurrent.Uninterruptibles.getUninterruptibly;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.annotations.GwtCompatible;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.annotations.GwtIncompatible;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.annotations.VisibleForTesting;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.base.Equivalence;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.base.Function;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.base.Stopwatch;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.base.Ticker;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.cache.AbstractCache.SimpleStatsCounter;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.cache.AbstractCache.StatsCounter;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.cache.CacheBuilder.NullListener;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.cache.CacheBuilder.OneWeigher;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.cache.CacheLoader.InvalidCacheLoadException;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.cache.CacheLoader.UnsupportedLoadingOperationException;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.AbstractSequentialIterator;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.ImmutableMap;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.ImmutableSet;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.Iterators;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.Maps;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.Sets;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.primitives.Ints;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.util.concurrent.ExecutionError;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.util.concurrent.Futures;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.util.concurrent.ListenableFuture;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.util.concurrent.SettableFuture;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.util.concurrent.UncheckedExecutionException;
import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.util.concurrent.Uninterruptibles;
import org.testifyproject.testifyproject.google.j2objc.annotations.Weak;
import org.testifyproject.testifyproject.google.j2objc.annotations.WeakOuter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.AbstractCollection;
import java.util.AbstractMap;
import java.util.AbstractQueue;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
/**
* The concurrent hash map implementation built by {@link CacheBuilder}.
*
*
This implementation is heavily derived from revision 1.96 of
* ConcurrentHashMap.java.
*
* @author Charles Fry
* @author Bob Lee ({@code org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect.MapMaker})
* @author Doug Lea ({@code ConcurrentHashMap})
*/
@GwtCompatible(emulated = true)
class LocalCache extends AbstractMap implements ConcurrentMap {
/*
* The basic strategy is to subdivide the table among Segments, each of which itself is a
* concurrently readable hash table. The map supports non-blocking reads and concurrent writes
* across different segments.
*
* If a maximum size is specified, a best-effort bounding is performed per segment, using a
* page-replacement algorithm to determine which entries to evict when the capacity has been
* exceeded.
*
* The page replacement algorithm's data structures are kept casually consistent with the map. The
* ordering of writes to a segment is sequentially consistent. An update to the map and recording
* of reads may not be immediately reflected on the algorithm's data structures. These structures
* are guarded by a lock and operations are applied in batches to avoid lock contention. The
* penalty of applying the batches is spread across threads so that the amortized cost is slightly
* higher than performing just the operation without enforcing the capacity constraint.
*
* This implementation uses a per-segment queue to record a memento of the additions, removals,
* and accesses that were performed on the map. The queue is drained on writes and when it exceeds
* its capacity threshold.
*
* The Least Recently Used page replacement algorithm was chosen due to its simplicity, high hit
* rate, and ability to be implemented with O(1) time org.testifyproject.testifyprojectplexity. The initial LRU implementation
* operates per-segment rather than globally for increased implementation simplicity. We expect
* the cache hit rate to be similar to that of a global LRU algorithm.
*/
// Constants
/**
* The maximum capacity, used if a higher value is implicitly specified by either of the
* constructors with arguments. MUST be a power of two <= 1<<30 to ensure that entries are
* indexable using ints.
*/
static final int MAXIMUM_CAPACITY = 1 << 30;
/** The maximum number of segments to allow; used to bound constructor arguments. */
static final int MAX_SEGMENTS = 1 << 16; // slightly conservative
/** Number of (unsynchronized) retries in the containsValue method. */
static final int CONTAINS_VALUE_RETRIES = 3;
/**
* Number of cache access operations that can be buffered per segment before the cache's recency
* ordering information is updated. This is used to avoid lock contention by recording a memento
* of reads and delaying a lock acquisition until the threshold is crossed or a mutation occurs.
*
*
This must be a (2^n)-1 as it is used as a mask.
*/
static final int DRAIN_THRESHOLD = 0x3F;
/**
* Maximum number of entries to be drained in a single cleanup run. This applies independently to
* the cleanup queue and both reference queues.
*/
// TODO(fry): empirically optimize this
static final int DRAIN_MAX = 16;
// Fields
static final Logger logger = Logger.getLogger(LocalCache.class.getName());
/**
* Mask value for indexing into segments. The upper bits of a key's hash code are used to choose
* the segment.
*/
final int segmentMask;
/**
* Shift value for indexing within segments. Helps prevent entries that end up in the same segment
* from also ending up in the same bucket.
*/
final int segmentShift;
/** The segments, each of which is a specialized hash table. */
final Segment[] segments;
/** The concurrency level. */
final int concurrencyLevel;
/** Strategy for org.testifyproject.testifyprojectparing keys. */
final Equivalence