com.atlassian.cache.hazelcast
Class HazelcastCache<K,V>

java.lang.Object
  extended by com.atlassian.cache.hazelcast.ManagedCacheSupport
      extended by com.atlassian.cache.hazelcast.HazelcastCache<K,V>
All Implemented Interfaces:
Cache<K,V>, ManagedCache

public class HazelcastCache<K,V>
extends ManagedCacheSupport
implements Cache<K,V>

Hazelcast implementation of the Cache and ManagedCache interfaces

Since:
2.4.0

Constructor Summary
HazelcastCache(String name, com.hazelcast.core.IMap<K,com.atlassian.hazelcast.serialization.OsgiSafe<V>> map, com.hazelcast.config.MapConfig config, CacheLoader<K,V> cacheLoader, CacheSettings settings)
           
 
Method Summary
 void addListener(CacheEntryListener<K,V> listener, boolean includeValues)
          Adds a CacheEntryListener
 void clear()
          Clear the cache.
 boolean containsKey(K k)
          Returns whether an entry exists in the cache under the specified key.
 V get(K key)
          Retrieve an object from this cache.
 V get(K key, Supplier<? extends V> valueSupplier)
          Retrieve an object from this cache.
 Collection<K> getKeys()
          Gets the keys of all objects currently stored in the cache.
 void put(K key, V value)
          Put an object into the cache.
 V putIfAbsent(K key, V value)
          Atomically associates the specified key with the given value if it is not already associated with a value.
 void remove(K key)
          Remove the object identified by the key from the cache.
 boolean remove(K key, V value)
          Atomically removes the entry for a key only if currently mapped to a given value.
 void removeAll()
          Remove all of the objects from this cache.
 void removeListener(CacheEntryListener<K,V> listener)
          Removes a CacheEntryListener
 boolean replace(K key, V oldValue, V newValue)
          Atomically replaces the entry for a key only if currently mapped to a given value.
 
Methods inherited from class com.atlassian.cache.hazelcast.ManagedCacheSupport
currentExpireAfterAccessMillis, currentExpireAfterWriteMillis, currentMaxEntries, getName, getStatistics, isFlushable, isLocal, isReplicateAsynchronously, isReplicateViaCopy, updateExpireAfterAccess, updateExpireAfterWrite, updateMaxEntries
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.atlassian.cache.Cache
getName
 

Constructor Detail

HazelcastCache

public HazelcastCache(String name,
                      com.hazelcast.core.IMap<K,com.atlassian.hazelcast.serialization.OsgiSafe<V>> map,
                      com.hazelcast.config.MapConfig config,
                      CacheLoader<K,V> cacheLoader,
                      CacheSettings settings)
Method Detail

clear

public void clear()
Description copied from interface: ManagedCache
Clear the cache.

Specified by:
clear in interface ManagedCache

containsKey

public boolean containsKey(@Nonnull
                           K k)
Description copied from interface: Cache
Returns whether an entry exists in the cache under the specified key.

Note that:

Specified by:
containsKey in interface Cache<K,V>
Parameters:
k - the key for the entry to check for containment
Returns:
true iff the cache already contains an entry under the specified key

get

public V get(@Nonnull
             K key)
Description copied from interface: Cache
Retrieve an object from this cache.

Specified by:
get in interface Cache<K,V>
Parameters:
key - the key uniquely identifying the object to be retrieved
Returns:
the object from the cache, or null if the object is not found

get

@Nonnull
public V get(@Nonnull
                     K key,
                     @Nonnull
                     Supplier<? extends V> valueSupplier)
Description copied from interface: Cache
Retrieve an object from this cache.

If no value is present in the cache, the valueSupplier will be used to populate the entry and be counted as a cache miss.

Specified by:
get in interface Cache<K,V>
Parameters:
key - the key uniquely identifying the object to be retrieved
valueSupplier - the supplier to call if no value is stored in the cache. the value supplied by the supplier cannot be null
Returns:
the object from the cache, or the newly created value from the supplier

getKeys

@Nonnull
public Collection<K> getKeys()
Description copied from interface: Cache
Gets the keys of all objects currently stored in the cache. This will return the keys in a new collection.

Specified by:
getKeys in interface Cache<K,V>
Returns:
a collection of Objects keys

put

public void put(@Nonnull
                K key,
                @Nonnull
                V value)
Description copied from interface: Cache
Put an object into the cache. If the specified key already exists within the cache, it will be replaced by the new object.

NOTE: Users of caches that wish to be well behaved in a clustered environment should use the CacheLoader semantics and supply a CacheLoader when getting the Cache.

Specified by:
put in interface Cache<K,V>
Parameters:
key - the key uniquely identifying the object to be added into the cache
value - the non-null value to be cached

putIfAbsent

public V putIfAbsent(@Nonnull
                     K key,
                     @Nonnull
                     V value)
Description copied from interface: Cache
Atomically associates the specified key with the given value if it is not already associated with a value.

Specified by:
putIfAbsent in interface Cache<K,V>
Parameters:
key - the key with which the specified value is associated
value - the non-null value to be cached
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key

remove

public void remove(@Nonnull
                   K key)
Description copied from interface: Cache
Remove the object identified by the key from the cache. If no object can be found associated with this key then no action is taken.

Specified by:
remove in interface Cache<K,V>
Parameters:
key - the key that uniquely identifies the object to be removed

remove

public boolean remove(@Nonnull
                      K key,
                      @Nonnull
                      V value)
Description copied from interface: Cache
Atomically removes the entry for a key only if currently mapped to a given value.

Specified by:
remove in interface Cache<K,V>
Parameters:
key - the key with which the specified value is associated
value - the value expected to be associated with the specified key
Returns:
true if the value was removed, false otherwise

removeAll

public void removeAll()
Description copied from interface: Cache
Remove all of the objects from this cache.

Specified by:
removeAll in interface Cache<K,V>

replace

public boolean replace(@Nonnull
                       K key,
                       @Nonnull
                       V oldValue,
                       @Nonnull
                       V newValue)
Description copied from interface: Cache
Atomically replaces the entry for a key only if currently mapped to a given value.

Specified by:
replace in interface Cache<K,V>
Parameters:
key - the key with which the specified value is associated
oldValue - the value expected to be associated with the specified key
newValue - the value to be associated with the specified key
Returns:
true if the value was replaced, false otherwise

addListener

public void addListener(@Nonnull
                        CacheEntryListener<K,V> listener,
                        boolean includeValues)
Description copied from interface: Cache
Adds a CacheEntryListener

Specified by:
addListener in interface Cache<K,V>
Parameters:
listener - the listener
includeValues - if the events sent to this listener will include old/new value. This is can be used in cases when the cost of finding these values is big (network sync) but the listener is not interested in the concrete values for events its getting. The support for this parameter is optional and implementation dependant

removeListener

public void removeListener(@Nonnull
                           CacheEntryListener<K,V> listener)
Description copied from interface: Cache
Removes a CacheEntryListener

Specified by:
removeListener in interface Cache<K,V>
Parameters:
listener - the listener


Copyright © 2015 Atlassian. All rights reserved.