Class GridNearCacheAdapter<K,​V>

    • Constructor Detail

      • GridNearCacheAdapter

        protected GridNearCacheAdapter()
        Empty constructor required for Externalizable.
      • GridNearCacheAdapter

        protected GridNearCacheAdapter​(GridCacheContext<K,​V> ctx)
        Parameters:
        ctx - Context.
    • Method Detail

      • isNear

        public boolean isNear()
        Overrides:
        isNear in class GridCacheAdapter<K,​V>
        Returns:
        True if this is near cache.
      • isLocked

        public boolean isLocked​(K key)
        Checks if any node owns a lock for this key.

        This is a local in-VM operation and does not involve any network trips or access to persistent storage in any way.

        Specified by:
        isLocked in interface IgniteInternalCache<K,​V>
        Overrides:
        isLocked in class GridCacheAdapter<K,​V>
        Parameters:
        key - Key to check.
        Returns:
        True if lock is owned by some node.
      • isLockedNearOnly

        public boolean isLockedNearOnly​(K key)
        Parameters:
        key - Key.
        Returns:
        If near entry is locked.
      • isAllLockedNearOnly

        public boolean isAllLockedNearOnly​(Iterable<? extends K> keys)
        Parameters:
        keys - Keys.
        Returns:
        If near entries for given keys are locked.
      • loadAsync

        public IgniteInternalFuture<Map<K,​V>> loadAsync​(@Nullable
                                                              @Nullable IgniteInternalTx tx,
                                                              @Nullable
                                                              @Nullable Collection<KeyCacheObject> keys,
                                                              boolean forcePrimary,
                                                              String taskName,
                                                              boolean deserializeBinary,
                                                              boolean recovery,
                                                              @Nullable
                                                              @Nullable javax.cache.expiry.ExpiryPolicy expiryPlc,
                                                              boolean skipVal,
                                                              boolean skipStore,
                                                              boolean needVer)
        Parameters:
        tx - Transaction.
        keys - Keys to load.
        forcePrimary - Force primary flag.
        taskName - Task name.
        deserializeBinary - Deserialize binary flag.
        expiryPlc - Expiry policy.
        skipVal - Skip value flag.
        skipStore - Skip store flag.
        needVer - Need version.
        Returns:
        Loaded values.
      • localLoadCache

        public void localLoadCache​(IgniteBiPredicate<K,​V> p,
                                   Object[] args)
                            throws IgniteCheckedException
        Delegates to CacheStore.loadCache(IgniteBiInClosure, Object...) method to load state from the underlying persistent storage. The loaded values will then be given to the optionally passed in predicate, and, if the predicate returns true, will be stored in cache. If predicate is null, then all loaded values will be stored in cache.

        Note that this method does not receive keys as a parameter, so it is up to CacheStore implementation to provide all the data to be loaded.

        This method is not transactional and may end up loading a stale value into cache if another thread has updated the value immediately after it has been loaded. It is mostly useful when pre-loading the cache from underlying data store before start, or for read-only caches.

        Specified by:
        localLoadCache in interface IgniteInternalCache<K,​V>
        Overrides:
        localLoadCache in class GridCacheAdapter<K,​V>
        Parameters:
        p - Optional predicate (may be null). If provided, will be used to filter values to be put into cache.
        args - Optional user arguments to be passed into CacheStore.loadCache(IgniteBiInClosure, Object...) method.
        Throws:
        IgniteCheckedException - If loading failed.
      • localLoadCacheAsync

        public IgniteInternalFuture<?> localLoadCacheAsync​(IgniteBiPredicate<K,​V> p,
                                                           Object[] args)
        Asynchronously delegates to CacheStore.loadCache(IgniteBiInClosure, Object...) method to reload state from the underlying persistent storage. The reloaded values will then be given to the optionally passed in predicate, and if the predicate returns true, will be stored in cache. If predicate is null, then all reloaded values will be stored in cache.

        Note that this method does not receive keys as a parameter, so it is up to CacheStore implementation to provide all the data to be loaded.

        This method is not transactional and may end up loading a stale value into cache if another thread has updated the value immediately after it has been loaded. It is mostly useful when pre-loading the cache from underlying data store before start, or for read-only caches.

        Specified by:
        localLoadCacheAsync in interface IgniteInternalCache<K,​V>
        Overrides:
        localLoadCacheAsync in class GridCacheAdapter<K,​V>
        Parameters:
        p - Optional predicate (may be null). If provided, will be used to filter values to be put into cache.
        args - Optional user arguments to be passed into CacheStore.loadCache(IgniteBiInClosure, Object...) method.
        Returns:
        Future to be completed whenever loading completes.
      • processGetResponse

        protected void processGetResponse​(UUID nodeId,
                                          GridNearGetResponse res)
        Parameters:
        nodeId - Sender ID.
        res - Response.
      • size

        public int size()
        Gets the number of all entries cached on this node. This method will return the count of all cache entries and has O(1) complexity on base IgniteInternalCache. It is essentially the size of cache key set and is semantically identical to {Cache.keySet().size().

        NOTE: this operation is not distributed and returns only the number of entries cached on this node.

        Specified by:
        size in interface IgniteInternalCache<K,​V>
        Overrides:
        size in class GridCacheAdapter<K,​V>
        Returns:
        Size of cache on this node.
      • sizeLong

        public long sizeLong()
        Gets the number of all entries cached on this node as a long value. This method will return the count of all cache entries and has O(1) complexity on base IgniteInternalCache. It is essentially the size of cache key set and is semantically identical to {Cache.keySet().size().

        NOTE: this operation is not distributed and returns only the number of entries cached on this node.

        Specified by:
        sizeLong in interface IgniteInternalCache<K,​V>
        Overrides:
        sizeLong in class GridCacheAdapter<K,​V>
        Returns:
        Size of cache on this node.
      • primarySize

        public int primarySize()
        Gets the number of all primary entries cached on this node.

        For CacheMode.PARTITIONED and CacheMode.REPLICATED modes, this method will return number of primary entries cached on this node (excluding any backups). The complexity of this method is O(P), where P is the total number of partitions.

        NOTE: this operation is not distributed and returns only the number of primary entries cached on this node.

        Specified by:
        primarySize in interface IgniteInternalCache<K,​V>
        Overrides:
        primarySize in class GridCacheAdapter<K,​V>
        Returns:
        Number of primary entries in cache.
      • primarySizeLong

        public long primarySizeLong()
        Gets the number of all primary entries cached on this node as a long value.

        For CacheMode.PARTITIONED and CacheMode.REPLICATED modes, this method will return number of primary entries cached on this node (excluding any backups). The complexity of this method is O(P), where P is the total number of partitions.

        NOTE: this operation is not distributed and returns only the number of primary entries cached on this node.

        Specified by:
        primarySizeLong in interface IgniteInternalCache<K,​V>
        Overrides:
        primarySizeLong in class GridCacheAdapter<K,​V>
        Returns:
        Number of primary entries in cache.
      • nearSize

        public int nearSize()
        Gets size of near cache key set. This method will return count of all entries in near cache and has O(1) complexity on base cache projection.

        Note that for LOCAL non-distributed caches this method will always return 0

        Specified by:
        nearSize in interface IgniteInternalCache<K,​V>
        Overrides:
        nearSize in class GridCacheAdapter<K,​V>
        Returns:
        Size of near cache key set or 0 if cache is not CacheMode.PARTITIONED.
      • nearEntries

        public Set<javax.cache.Cache.Entry<K,​V>> nearEntries()
        Returns:
        Near entries.
      • evict

        public boolean evict​(K key)
        Evicts entry associated with given key from cache. Note, that entry will be evicted only if it's not used (not participating in any locks or transactions).
        Specified by:
        evict in interface IgniteInternalCache<K,​V>
        Overrides:
        evict in class GridCacheAdapter<K,​V>
        Parameters:
        key - Key to evict from cache.
        Returns:
        True if entry could be evicted, false otherwise.
      • evictAll

        public void evictAll​(Collection<? extends K> keys)
        Attempts to evict all entries associated with keys. Note, that entry will be evicted only if it's not used (not participating in any locks or transactions).
        Specified by:
        evictAll in interface IgniteInternalCache<K,​V>
        Overrides:
        evictAll in class GridCacheAdapter<K,​V>
        Parameters:
        keys - Keys to evict.
      • clearLocally

        public boolean clearLocally​(K key)
        Clears an entry from this cache and swap storage only if the entry is not currently locked, and is not participating in a transaction.

        Note that this operation is local as it merely clears an entry from local cache. It does not remove entries from remote caches or from underlying persistent storage.

        Specified by:
        clearLocally in interface IgniteInternalCache<K,​V>
        Overrides:
        clearLocally in class GridCacheAdapter<K,​V>
        Parameters:
        key - Key to clearLocally.
        Returns:
        True if entry was successfully cleared from cache, false if entry was in use at the time of this method invocation and could not be cleared.
      • clearLocallyAll

        public void clearLocallyAll​(Set<? extends K> keys,
                                    boolean srv,
                                    boolean near,
                                    boolean readers)
        Clears entries from this cache and swap storage only if the entry is not currently locked, and is not participating in a transaction.

        Note that this operation is local as it merely clears an entry from local cache. It does not remove entries from remote caches or from underlying persistent storage.

        Specified by:
        clearLocallyAll in interface IgniteInternalCache<K,​V>
        Overrides:
        clearLocallyAll in class GridCacheAdapter<K,​V>
        Parameters:
        keys - Keys to clearLocally.
        srv - Whether to clear server cache.
        near - Whether to clear near cache.
        readers - Whether to clear readers.
      • splitClearLocally

        public List<GridCacheClearAllRunnable<K,​V>> splitClearLocally​(boolean srv,
                                                                            boolean near,
                                                                            boolean readers)
        Split clearLocally all task into multiple runnables.
        Overrides:
        splitClearLocally in class GridCacheAdapter<K,​V>
        Parameters:
        srv - Whether to clear server cache.
        near - Whether to clear near cache.
        readers - Whether to clear readers.
        Returns:
        Split runnables.