Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.infinispan.commons.api;
  
  import java.util.Map;
  
AsyncCache. This interface is implemented by caches which support asynchronous variants of the various put/get/remove/clear/replace/putAll methods Note that these methods only really make sense if you are using a clustered cache. I.e., when used in LOCAL mode, these "async" operations offer no benefit whatsoever. These methods, such as putAsync(java.lang.Object,java.lang.Object) offer the best of both worlds between a fully synchronous and a fully asynchronous cache in that a org.infinispan.commons.util.concurrent.NotifyingFuture is returned. The NotifyingFuture can then be ignored or thrown away for typical asynchronous behaviour, or queried for synchronous behaviour, which would block until any remote calls complete. Note that all remote calls are, as far as the transport is concerned, synchronous. This allows you the guarantees that remote calls succeed, while not blocking your application thread unnecessarily. For example, usage such as the following could benefit from the async operations:
   NotifyingFuture f1 = cache.putAsync("key1", "value1");
   NotifyingFuture f2 = cache.putAsync("key2", "value2");
   NotifyingFuture f3 = cache.putAsync("key3", "value3");
   f1.get();
   f2.get();
   f3.get();
 
The net result is behavior similar to synchronous RPC calls in that at the end, you have guarantees that all calls completed successfully, but you have the added benefit that the three calls could happen in parallel. This is especially advantageous if the cache uses distribution and the three keys map to different cache instances in the cluster.

Also, the use of async operations when within a transaction return your local value only, as expected. A NotifyingFuture is still returned though for API consistency.

Author(s):
Mircea Markus
Manik Surtani
Galder ZamarreƱo
Tristan Tarrant
Since:
6.0
 
 public interface AsyncCache<K, V> {
   
Asynchronous version of put(java.lang.Object,java.lang.Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over put(java.lang.Object,java.lang.Object) if used in LOCAL mode.

Parameters:
key key to use
value value to store
Returns:
a future containing the old value replaced.
 
    NotifyingFuture<V> putAsync(K key, V value);

   
Asynchronous version of put(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit) . This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over put(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit) if used in LOCAL mode.

Parameters:
key key to use
value value to store
lifespan lifespan of entry
unit time unit for lifespan
Returns:
a future containing the old value replaced
 
    NotifyingFuture<V> putAsync(K key, V valuelong lifespanTimeUnit unit);

   
Asynchronous version of put(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit,long,java.util.concurrent.TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over put(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit,long,java.util.concurrent.TimeUnit) if used in LOCAL mode.

Parameters:
key key to use
value value to store
lifespan lifespan of entry
lifespanUnit time unit for lifespan
maxIdle the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit time unit for max idle time
Returns:
a future containing the old value replaced
 
    NotifyingFuture<V> putAsync(K key, V valuelong lifespanTimeUnit lifespanUnitlong maxIdleTimeUnit maxIdleUnit);

   
Asynchronous version of putAll(java.util.Map). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over putAll(java.util.Map) if used in LOCAL mode.

Parameters:
data to store
Returns:
a future containing a void return type
 
    NotifyingFuture<VoidputAllAsync(Map<? extends K, ? extends V> data);

   
Asynchronous version of putAll(java.util.Map,long,java.util.concurrent.TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over putAll(java.util.Map,long,java.util.concurrent.TimeUnit) if used in LOCAL mode.

Parameters:
data to store
lifespan lifespan of entry
unit time unit for lifespan
Returns:
a future containing a void return type
   NotifyingFuture<VoidputAllAsync(Map<? extends K, ? extends V> datalong lifespanTimeUnit unit);

   
Asynchronous version of putAll(java.util.Map,long,java.util.concurrent.TimeUnit,long,java.util.concurrent.TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over putAll(java.util.Map,long,java.util.concurrent.TimeUnit,long,java.util.concurrent.TimeUnit) if used in LOCAL mode.

Parameters:
data to store
lifespan lifespan of entry
lifespanUnit time unit for lifespan
maxIdle the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit time unit for max idle time
Returns:
a future containing a void return type
   NotifyingFuture<VoidputAllAsync(Map<? extends K, ? extends V> datalong lifespanTimeUnit lifespanUnitlong maxIdleTimeUnit maxIdleUnit);

   
Asynchronous version of clear(). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over clear() if used in LOCAL mode.

Returns:
a future containing a void return type
Asynchronous version of putIfAbsent(java.lang.Object,java.lang.Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over putIfAbsent(java.lang.Object,java.lang.Object) if used in LOCAL mode.

Parameters:
key key to use
value value to store
Returns:
a future containing the old value replaced.
   NotifyingFuture<V> putIfAbsentAsync(K key, V value);

   
Asynchronous version of putIfAbsent(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit) . This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over putIfAbsent(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit) if used in LOCAL mode.

Parameters:
key key to use
value value to store
lifespan lifespan of entry
unit time unit for lifespan
Returns:
a future containing the old value replaced
   NotifyingFuture<V> putIfAbsentAsync(K key, V valuelong lifespanTimeUnit unit);

   
Asynchronous version of putIfAbsent(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit,long,java.util.concurrent.TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over putIfAbsent(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit,long,java.util.concurrent.TimeUnit) if used in LOCAL mode.

Parameters:
key key to use
value value to store
lifespan lifespan of entry
lifespanUnit time unit for lifespan
maxIdle the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit time unit for max idle time
Returns:
a future containing the old value replaced
   NotifyingFuture<V> putIfAbsentAsync(K key, V valuelong lifespanTimeUnit lifespanUnitlong maxIdleTimeUnit maxIdleUnit);

   
Asynchronous version of remove(java.lang.Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over remove(java.lang.Object) if used in LOCAL mode.

Parameters:
key key to remove
Returns:
a future containing the value removed
   NotifyingFuture<V> removeAsync(Object key);

   
Asynchronous version of remove(java.lang.Object,java.lang.Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over remove(java.lang.Object,java.lang.Object) if used in LOCAL mode.

Parameters:
key key to remove
value value to match on
Returns:
a future containing a boolean, indicating whether the entry was removed or not
   NotifyingFuture<BooleanremoveAsync(Object keyObject value);

   
Asynchronous version of replace(java.lang.Object,java.lang.Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over replace(java.lang.Object,java.lang.Object) if used in LOCAL mode.

Parameters:
key key to remove
value value to store
Returns:
a future containing the previous value overwritten
   NotifyingFuture<V> replaceAsync(K key, V value);

   
Asynchronous version of replace(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over replace(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit) if used in LOCAL mode.

Parameters:
key key to remove
value value to store
lifespan lifespan of entry
unit time unit for lifespan
Returns:
a future containing the previous value overwritten
   NotifyingFuture<V> replaceAsync(K key, V valuelong lifespanTimeUnit unit);

   
Asynchronous version of replace(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit,long,java.util.concurrent.TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over replace(java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit,long,java.util.concurrent.TimeUnit) if used in LOCAL mode.

Parameters:
key key to remove
value value to store
lifespan lifespan of entry
lifespanUnit time unit for lifespan
maxIdle the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit time unit for max idle time
Returns:
a future containing the previous value overwritten
   NotifyingFuture<V> replaceAsync(K key, V valuelong lifespanTimeUnit lifespanUnitlong maxIdleTimeUnit maxIdleUnit);

   
Asynchronous version of replace(java.lang.Object,java.lang.Object,java.lang.Object). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over replace(java.lang.Object,java.lang.Object,java.lang.Object) if used in LOCAL mode.

Parameters:
key key to remove
oldValue value to overwrite
newValue value to store
Returns:
a future containing a boolean, indicating whether the entry was replaced or not
   NotifyingFuture<BooleanreplaceAsync(K key, V oldValue, V newValue);

   
Asynchronous version of replace(java.lang.Object,java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over replace(java.lang.Object,java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit) if used in LOCAL mode.

Parameters:
key key to remove
oldValue value to overwrite
newValue value to store
lifespan lifespan of entry
unit time unit for lifespan
Returns:
a future containing a boolean, indicating whether the entry was replaced or not
   NotifyingFuture<BooleanreplaceAsync(K key, V oldValue, V newValuelong lifespanTimeUnit unit);

   
Asynchronous version of replace(java.lang.Object,java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit,long,java.util.concurrent.TimeUnit). This method does not block on remote calls, even if your cache mode is synchronous. Has no benefit over replace(java.lang.Object,java.lang.Object,java.lang.Object,long,java.util.concurrent.TimeUnit,long,java.util.concurrent.TimeUnit) if used in LOCAL mode.

Parameters:
key key to remove
oldValue value to overwrite
newValue value to store
lifespan lifespan of entry
lifespanUnit time unit for lifespan
maxIdle the maximum amount of time this key is allowed to be idle for before it is considered as expired
maxIdleUnit time unit for max idle time
Returns:
a future containing a boolean, indicating whether the entry was replaced or not
   NotifyingFuture<BooleanreplaceAsync(K key, V oldValue, V newValuelong lifespanTimeUnit lifespanUnitlong maxIdleTimeUnit maxIdleUnit);

   
Asynchronous version of get(java.lang.Object) that allows user code to retrieve the value associated with a key at a later stage, hence allowing multiple parallel get requests to be sent. Normally, when this method detects that the value is likely to be retrieved from from a remote entity, it will span a different thread in order to allow the asynchronous get call to return immediately. If the call will definitely resolve locally, for example when the cache is configured with LOCAL mode and no stores are configured, the get asynchronous call will act sequentially and will have no different to get(java.lang.Object).

Parameters:
key key to retrieve
Returns:
a future that can be used to retrieve value associated with the key when this is available. The actual value returned by the future follows the same rules as get(java.lang.Object)
   NotifyingFuture<V> getAsync(K key);
New to GrepCode? Check out our FAQ X