http://git-wip-us.apache.org/repos/asf/ignite/blob/cc1aa533/modules/platforms/dotnet/Apache.Ignite.Core/Cache/ICache.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/ICache.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/ICache.cs index 204c56c..48bc695 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/ICache.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/ICache.cs @@ -21,11 +21,11 @@ namespace Apache.Ignite.Core.Cache using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; + using System.Threading.Tasks; using Apache.Ignite.Core.Cache.Expiry; using Apache.Ignite.Core.Cache.Query; using Apache.Ignite.Core.Cache.Query.Continuous; using Apache.Ignite.Core.Cache.Store; - using Apache.Ignite.Core.Common; using Apache.Ignite.Core.Transactions; /// <summary> @@ -53,7 +53,7 @@ namespace Apache.Ignite.Core.Cache /// <typeparam name="TK">Key type.</typeparam> /// <typeparam name="TV">Value type.</typeparam> [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] - public interface ICache<TK, TV> : IAsyncSupport<ICache<TK, TV>>, IEnumerable<ICacheEntry<TK, TV>> + public interface ICache<TK, TV> : IEnumerable<ICacheEntry<TK, TV>> { /// <summary> /// Name of this cache (<c>null</c> for default cache). @@ -113,13 +113,23 @@ namespace Apache.Ignite.Core.Cache /// <param name="args"> /// Optional user arguments to be passed into <see cref="ICacheStore.LoadCache" />. /// </param> - [AsyncSupported] void LoadCache(ICacheEntryFilter<TK, TV> p, params object[] args); /// <summary> - /// Delegates to <see cref="ICacheStore.LoadCache" /> 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, + /// Executes <see cref="LocalLoadCache"/> on all cache nodes. + /// </summary> + /// <param name="p"> + /// Optional predicate. If provided, will be used to filter values to be put into cache. + /// </param> + /// <param name="args"> + /// Optional user arguments to be passed into <see cref="ICacheStore.LoadCache" />. + /// </param> + Task LoadCacheAsync(ICacheEntryFilter<TK, TV> p, params object[] args); + + /// <summary> + /// Delegates to <see cref="ICacheStore.LoadCache" /> 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. /// </summary> /// <param name="p"> @@ -128,26 +138,51 @@ namespace Apache.Ignite.Core.Cache /// <param name="args"> /// Optional user arguments to be passed into <see cref="ICacheStore.LoadCache" />. /// </param> - [AsyncSupported] void LocalLoadCache(ICacheEntryFilter<TK, TV> p, params object[] args); /// <summary> + /// Delegates to <see cref="ICacheStore.LoadCache" /> 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. + /// </summary> + /// <param name="p"> + /// Optional predicate. If provided, will be used to filter values to be put into cache. + /// </param> + /// <param name="args"> + /// Optional user arguments to be passed into <see cref="ICacheStore.LoadCache" />. + /// </param> + Task LocalLoadCacheAsync(ICacheEntryFilter<TK, TV> p, params object[] args); + + /// <summary> /// Check if cache contains mapping for this key. /// </summary> /// <param name="key">Key.</param> /// <returns>True if cache contains mapping for this key.</returns> - [AsyncSupported] bool ContainsKey(TK key); /// <summary> + /// Check if cache contains mapping for this key. + /// </summary> + /// <param name="key">Key.</param> + /// <returns>True if cache contains mapping for this key.</returns> + Task<bool> ContainsKeyAsync(TK key); + + /// <summary> /// Check if cache contains mapping for these keys. /// </summary> /// <param name="keys">Keys.</param> /// <returns>True if cache contains mapping for all these keys.</returns> - [AsyncSupported] bool ContainsKeys(IEnumerable<TK> keys); /// <summary> + /// Check if cache contains mapping for these keys. + /// </summary> + /// <param name="keys">Keys.</param> + /// <returns>True if cache contains mapping for all these keys.</returns> + Task<bool> ContainsKeysAsync(IEnumerable<TK> keys); + + /// <summary> /// Peeks at cached value using optional set of peek modes. This method will sequentially /// iterate over given peek modes, and try to peek at value using each peek mode. Once a /// non-null value is found, it will be immediately returned. @@ -168,8 +203,8 @@ namespace Apache.Ignite.Core.Cache /// value depending on the peek modes used. /// </summary> /// <param name="key">Key.</param> - /// <param name="value">When this method returns, the value associated with the specified key, - /// if the key is found; otherwise, the default value for the type of the value parameter. + /// <param name="value">When this method returns, the value associated with the specified key, + /// if the key is found; otherwise, the default value for the type of the value parameter. /// This parameter is passed uninitialized.</param> /// <param name="modes">Peek modes.</param> /// <returns> @@ -187,7 +222,7 @@ namespace Apache.Ignite.Core.Cache /// <summary> /// Retrieves value mapped to the specified key from cache. Throws an exception if t - /// + /// /// If the value is not present in cache, then it will be looked up from swap storage. If /// it's not present in swap, or if swap is disable, and if read-through is allowed, value /// will be loaded from persistent store. @@ -196,10 +231,22 @@ namespace Apache.Ignite.Core.Cache /// </summary> /// <param name="key">Key.</param> /// <returns>Value.</returns> - [AsyncSupported] TV Get(TK key); /// <summary> + /// Retrieves value mapped to the specified key from cache. Throws an exception if t + /// + /// If the value is not present in cache, then it will be looked up from swap storage. If + /// it's not present in swap, or if swap is disable, and if read-through is allowed, value + /// will be loaded from persistent store. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// If key is not present in cache, KeyNotFoundException will be thrown. + /// </summary> + /// <param name="key">Key.</param> + /// <returns>Value.</returns> + Task<TV> GetAsync(TK key); + + /// <summary> /// Retrieves value mapped to the specified key from cache. /// If the value is not present in cache, then it will be looked up from swap storage. If /// it's not present in swap, or if swap is disable, and if read-through is allowed, value @@ -207,8 +254,8 @@ namespace Apache.Ignite.Core.Cache /// This method is transactional and will enlist the entry into ongoing transaction if there is one. /// </summary> /// <param name="key">Key.</param> - /// <param name="value">When this method returns, the value associated with the specified key, - /// if the key is found; otherwise, the default value for the type of the value parameter. + /// <param name="value">When this method returns, the value associated with the specified key, + /// if the key is found; otherwise, the default value for the type of the value parameter. /// This parameter is passed uninitialized.</param> /// <returns> /// true if the cache contains an element with the specified key; otherwise, false. @@ -216,6 +263,19 @@ namespace Apache.Ignite.Core.Cache bool TryGet(TK key, out TV value); /// <summary> + /// Retrieves value mapped to the specified key from cache. + /// If the value is not present in cache, then it will be looked up from swap storage. If + /// it's not present in swap, or if swap is disable, and if read-through is allowed, value + /// will be loaded from persistent store. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// </summary> + /// <param name="key">Key.</param> + /// <returns> + /// <see cref="CacheResult{T}"/> containing a bool success flag and a value. + /// </returns> + Task<CacheResult<TV>> TryGetAsync(TK key); + + /// <summary> /// Retrieves values mapped to the specified keys from cache. /// If some value is not present in cache, then it will be looked up from swap storage. If /// it's not present in swap, or if swap is disabled, and if read-through is allowed, value @@ -224,21 +284,40 @@ namespace Apache.Ignite.Core.Cache /// </summary> /// <param name="keys">Keys.</param> /// <returns>Map of key-value pairs.</returns> - [AsyncSupported] IDictionary<TK, TV> GetAll(IEnumerable<TK> keys); /// <summary> + /// Retrieves values mapped to the specified keys from cache. + /// If some value is not present in cache, then it will be looked up from swap storage. If + /// it's not present in swap, or if swap is disabled, and if read-through is allowed, value + /// will be loaded from persistent store. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// </summary> + /// <param name="keys">Keys.</param> + /// <returns>Map of key-value pairs.</returns> + Task<IDictionary<TK, TV>> GetAllAsync(IEnumerable<TK> keys); + + /// <summary> /// Associates the specified value with the specified key in the cache. /// <para /> - /// If the cache previously contained a mapping for the key, + /// If the cache previously contained a mapping for the key, /// the old value is replaced by the specified value. /// </summary> /// <param name="key">Key with which the specified value is to be associated.</param> /// <param name="val">Value to be associated with the specified key.</param> - [AsyncSupported] void Put(TK key, TV val); /// <summary> + /// Associates the specified value with the specified key in the cache. + /// <para /> + /// If the cache previously contained a mapping for the key, + /// the old value is replaced by the specified value. + /// </summary> + /// <param name="key">Key with which the specified value is to be associated.</param> + /// <param name="val">Value to be associated with the specified key.</param> + Task PutAsync(TK key, TV val); + + /// <summary> /// Associates the specified value with the specified key in this cache, /// returning an existing value if one existed. /// </summary> @@ -247,9 +326,19 @@ namespace Apache.Ignite.Core.Cache /// <returns> /// The value associated with the key at the start of the operation. /// </returns> - [AsyncSupported] CacheResult<TV> GetAndPut(TK key, TV val); - + + /// <summary> + /// Associates the specified value with the specified key in this cache, + /// returning an existing value if one existed. + /// </summary> + /// <param name="key">Key with which the specified value is to be associated.</param> + /// <param name="val">Value to be associated with the specified key.</param> + /// <returns> + /// The value associated with the key at the start of the operation. + /// </returns> + Task<CacheResult<TV>> GetAndPutAsync(TK key, TV val); + /// <summary> /// Atomically replaces the value for a given key if and only if there is a value currently mapped by the key. /// </summary> @@ -258,27 +347,49 @@ namespace Apache.Ignite.Core.Cache /// <returns> /// The previous value associated with the specified key. /// </returns> - [AsyncSupported] CacheResult<TV> GetAndReplace(TK key, TV val); /// <summary> + /// Atomically replaces the value for a given key if and only if there is a value currently mapped by the key. + /// </summary> + /// <param name="key">Key with which the specified value is to be associated.</param> + /// <param name="val">Value to be associated with the specified key.</param> + /// <returns> + /// The previous value associated with the specified key. + /// </returns> + Task<CacheResult<TV>> GetAndReplaceAsync(TK key, TV val); + + /// <summary> /// Atomically removes the entry for a key only if currently mapped to some value. /// </summary> /// <param name="key">Key with which the specified value is associated.</param> /// <returns>The value if one existed.</returns> - [AsyncSupported] CacheResult<TV> GetAndRemove(TK key); /// <summary> + /// Atomically removes the entry for a key only if currently mapped to some value. + /// </summary> + /// <param name="key">Key with which the specified value is associated.</param> + /// <returns>The value if one existed.</returns> + Task<CacheResult<TV>> GetAndRemoveAsync(TK key); + + /// <summary> /// Atomically associates the specified key with the given value if it is not already associated with a value. /// </summary> /// <param name="key">Key with which the specified value is to be associated.</param> /// <param name="val">Value to be associated with the specified key.</param> /// <returns>True if a value was set.</returns> - [AsyncSupported] bool PutIfAbsent(TK key, TV val); /// <summary> + /// Atomically associates the specified key with the given value if it is not already associated with a value. + /// </summary> + /// <param name="key">Key with which the specified value is to be associated.</param> + /// <param name="val">Value to be associated with the specified key.</param> + /// <returns>True if a value was set.</returns> + Task<bool> PutIfAbsentAsync(TK key, TV val); + + /// <summary> /// Stores given key-value pair in cache only if cache had no previous mapping for it. /// If cache previously contained value for the given key, then this value is returned. /// In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, @@ -294,10 +405,27 @@ namespace Apache.Ignite.Core.Cache /// <returns> /// Previously contained value regardless of whether put happened or not. /// </returns> - [AsyncSupported] CacheResult<TV> GetAndPutIfAbsent(TK key, TV val); /// <summary> + /// Stores given key-value pair in cache only if cache had no previous mapping for it. + /// If cache previously contained value for the given key, then this value is returned. + /// In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, + /// which in its turn may load the value from the swap storage, and consecutively, if it's not + /// in swap, from the underlying persistent storage. + /// If the returned value is not needed, method putxIfAbsent() should be used instead of this one to + /// avoid the overhead associated with returning of the previous value. + /// If write-through is enabled, the stored value will be persisted to store. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// </summary> + /// <param name="key">Key to store in cache.</param> + /// <param name="val">Value to be associated with the given key.</param> + /// <returns> + /// Previously contained value regardless of whether put happened or not. + /// </returns> + Task<CacheResult<TV>> GetAndPutIfAbsentAsync(TK key, TV val); + + /// <summary> /// Stores given key-value pair in cache only if there is a previous mapping for it. /// If cache previously contained value for the given key, then this value is returned. /// In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, @@ -309,10 +437,23 @@ namespace Apache.Ignite.Core.Cache /// <param name="key">Key to store in cache.</param> /// <param name="val">Value to be associated with the given key.</param> /// <returns>True if the value was replaced.</returns> - [AsyncSupported] bool Replace(TK key, TV val); /// <summary> + /// Stores given key-value pair in cache only if there is a previous mapping for it. + /// If cache previously contained value for the given key, then this value is returned. + /// In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node, + /// which in its turn may load the value from the swap storage, and consecutively, if it's not + /// in swap, rom the underlying persistent storage. + /// If write-through is enabled, the stored value will be persisted to store. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// </summary> + /// <param name="key">Key to store in cache.</param> + /// <param name="val">Value to be associated with the given key.</param> + /// <returns>True if the value was replaced.</returns> + Task<bool> ReplaceAsync(TK key, TV val); + + /// <summary> /// Stores given key-value pair in cache only if only if the previous value is equal to the /// old value passed as argument. /// This method is transactional and will enlist the entry into ongoing transaction if there is one. @@ -321,20 +462,37 @@ namespace Apache.Ignite.Core.Cache /// <param name="oldVal">Old value to match.</param> /// <param name="newVal">Value to be associated with the given key.</param> /// <returns>True if replace happened, false otherwise.</returns> - [AsyncSupported] bool Replace(TK key, TV oldVal, TV newVal); /// <summary> + /// Stores given key-value pair in cache only if only if the previous value is equal to the + /// old value passed as argument. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// </summary> + /// <param name="key">Key to store in cache.</param> + /// <param name="oldVal">Old value to match.</param> + /// <param name="newVal">Value to be associated with the given key.</param> + /// <returns>True if replace happened, false otherwise.</returns> + Task<bool> ReplaceAsync(TK key, TV oldVal, TV newVal); + + /// <summary> /// Stores given key-value pairs in cache. /// If write-through is enabled, the stored values will be persisted to store. /// This method is transactional and will enlist the entry into ongoing transaction if there is one. /// </summary> /// <param name="vals">Key-value pairs to store in cache.</param> - [AsyncSupported] void PutAll(IDictionary<TK, TV> vals); /// <summary> - /// Attempts to evict all entries associated with keys. Note, that entry will be evicted only + /// Stores given key-value pairs in cache. + /// If write-through is enabled, the stored values will be persisted to store. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// </summary> + /// <param name="vals">Key-value pairs to store in cache.</param> + Task PutAllAsync(IDictionary<TK, TV> vals); + + /// <summary> + /// 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). /// </summary> /// <param name="keys">Keys to evict from cache.</param> @@ -343,26 +501,42 @@ namespace Apache.Ignite.Core.Cache /// <summary> /// Clears the contents of the cache, without notifying listeners or CacheWriters. /// </summary> - [AsyncSupported] void Clear(); /// <summary> + /// Clears the contents of the cache, without notifying listeners or CacheWriters. + /// </summary> + Task ClearAsync(); + + /// <summary> /// Clear entry from the cache and swap storage, without notifying listeners or CacheWriters. /// Entry is cleared only if it is not currently locked, and is not participating in a transaction. /// </summary> /// <param name="key">Key to clear.</param> - [AsyncSupported] void Clear(TK key); /// <summary> + /// Clear entry from the cache and swap storage, without notifying listeners or CacheWriters. + /// Entry is cleared only if it is not currently locked, and is not participating in a transaction. + /// </summary> + /// <param name="key">Key to clear.</param> + Task ClearAsync(TK key); + + /// <summary> /// Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. /// Entry is cleared only if it is not currently locked, and is not participating in a transaction. /// </summary> /// <param name="keys">Keys to clear.</param> - [AsyncSupported] void ClearAll(IEnumerable<TK> keys); /// <summary> + /// Clear entries from the cache and swap storage, without notifying listeners or CacheWriters. + /// Entry is cleared only if it is not currently locked, and is not participating in a transaction. + /// </summary> + /// <param name="keys">Keys to clear.</param> + Task ClearAllAsync(IEnumerable<TK> keys); + + /// <summary> /// Clear entry from the cache and swap storage, without notifying listeners or CacheWriters. /// Entry is cleared only if it is not currently locked, and is not participating in a transaction. /// <para /> @@ -394,10 +568,23 @@ namespace Apache.Ignite.Core.Cache /// </summary> /// <param name="key">Key whose mapping is to be removed from cache.</param> /// <returns>False if there was no matching key.</returns> - [AsyncSupported] bool Remove(TK key); /// <summary> + /// Removes given key mapping from cache. If cache previously contained value for the given key, + /// then this value is returned. In case of PARTITIONED or REPLICATED caches, the value will be + /// loaded from the primary node, which in its turn may load the value from the disk-based swap + /// storage, and consecutively, if it's not in swap, from the underlying persistent storage. + /// If the returned value is not needed, method removex() should always be used instead of this + /// one to avoid the overhead associated with returning of the previous value. + /// If write-through is enabled, the value will be removed from store. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// </summary> + /// <param name="key">Key whose mapping is to be removed from cache.</param> + /// <returns>False if there was no matching key.</returns> + Task<bool> RemoveAsync(TK key); + + /// <summary> /// Removes given key mapping from cache if one exists and value is equal to the passed in value. /// If write-through is enabled, the value will be removed from store. /// This method is transactional and will enlist the entry into ongoing transaction if there is one. @@ -405,27 +592,49 @@ namespace Apache.Ignite.Core.Cache /// <param name="key">Key whose mapping is to be removed from cache.</param> /// <param name="val">Value to match against currently cached value.</param> /// <returns>True if entry was removed, false otherwise.</returns> - [AsyncSupported] bool Remove(TK key, TV val); /// <summary> + /// Removes given key mapping from cache if one exists and value is equal to the passed in value. + /// If write-through is enabled, the value will be removed from store. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// </summary> + /// <param name="key">Key whose mapping is to be removed from cache.</param> + /// <param name="val">Value to match against currently cached value.</param> + /// <returns>True if entry was removed, false otherwise.</returns> + Task<bool> RemoveAsync(TK key, TV val); + + /// <summary> /// Removes given key mappings from cache. /// If write-through is enabled, the value will be removed from store. /// This method is transactional and will enlist the entry into ongoing transaction if there is one. /// </summary> /// <param name="keys">Keys whose mappings are to be removed from cache.</param> - [AsyncSupported] void RemoveAll(IEnumerable<TK> keys); /// <summary> + /// Removes given key mappings from cache. + /// If write-through is enabled, the value will be removed from store. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// </summary> + /// <param name="keys">Keys whose mappings are to be removed from cache.</param> + Task RemoveAllAsync(IEnumerable<TK> keys); + + /// <summary> /// Removes all mappings from cache. /// If write-through is enabled, the value will be removed from store. /// This method is transactional and will enlist the entry into ongoing transaction if there is one. /// </summary> - [AsyncSupported] void RemoveAll(); /// <summary> + /// Removes all mappings from cache. + /// If write-through is enabled, the value will be removed from store. + /// This method is transactional and will enlist the entry into ongoing transaction if there is one. + /// </summary> + Task RemoveAllAsync(); + + /// <summary> /// Gets the number of all entries cached on this node. /// </summary> /// <param name="modes">Optional peek modes. If not provided, then total cache size is returned.</param> @@ -439,15 +648,23 @@ namespace Apache.Ignite.Core.Cache /// </summary> /// <param name="modes">Optional peek modes. If not provided, then total cache size is returned.</param> /// <returns>Cache size across all nodes.</returns> - [AsyncSupported] int GetSize(params CachePeekMode[] modes); /// <summary> + /// Gets the number of all entries cached across all nodes. + /// <para /> + /// NOTE: this operation is distributed and will query all participating nodes for their cache sizes. + /// </summary> + /// <param name="modes">Optional peek modes. If not provided, then total cache size is returned.</param> + /// <returns>Cache size across all nodes.</returns> + Task<int> GetSizeAsync(params CachePeekMode[] modes); + + /// <summary> /// This method unswaps cache entries by given keys, if any, from swap storage into memory. /// </summary> /// <param name="keys">Keys to promote entries for.</param> void LocalPromote(IEnumerable<TK> keys); - + /// <summary> /// Queries cache. /// </summary> @@ -474,14 +691,14 @@ namespace Apache.Ignite.Core.Cache /// </summary> /// <param name="qry">Continuous query.</param> /// <param name="initialQry"> - /// The initial query. This query will be executed before continuous listener is registered which allows + /// The initial query. This query will be executed before continuous listener is registered which allows /// to iterate through entries which have already existed at the time continuous query is executed. /// </param> /// <returns> /// Handle to get initial query cursor or stop query execution. /// </returns> IContinuousQueryHandle<ICacheEntry<TK, TV>> QueryContinuous(ContinuousQuery<TK, TV> qry, QueryBase initialQry); - + /// <summary> /// Get local cache entries. /// </summary> @@ -490,9 +707,9 @@ namespace Apache.Ignite.Core.Cache IEnumerable<ICacheEntry<TK, TV>> GetLocalEntries(params CachePeekMode[] peekModes); /// <summary> - /// Invokes an <see cref="ICacheEntryProcessor{K, V, A, R}"/> against the - /// <see cref="IMutableCacheEntry{K, V}"/> specified by the provided key. - /// If an entry does not exist for the specified key, an attempt is made to load it (if a loader is configured) + /// Invokes an <see cref="ICacheEntryProcessor{K, V, A, R}"/> against the + /// <see cref="IMutableCacheEntry{K, V}"/> specified by the provided key. + /// If an entry does not exist for the specified key, an attempt is made to load it (if a loader is configured) /// or a surrogate entry, consisting of the key with a null value is used instead. /// </summary> /// <typeparam name="TArg">The type of the argument.</typeparam> @@ -502,17 +719,55 @@ namespace Apache.Ignite.Core.Cache /// <param name="arg">The argument.</param> /// <returns>Result of the processing.</returns> /// <exception cref="CacheEntryProcessorException">If an exception has occured during processing.</exception> - [AsyncSupported] TRes Invoke<TArg, TRes>(TK key, ICacheEntryProcessor<TK, TV, TArg, TRes> processor, TArg arg); /// <summary> + /// Invokes an <see cref="ICacheEntryProcessor{K, V, A, R}"/> against the + /// <see cref="IMutableCacheEntry{K, V}"/> specified by the provided key. + /// If an entry does not exist for the specified key, an attempt is made to load it (if a loader is configured) + /// or a surrogate entry, consisting of the key with a null value is used instead. + /// </summary> + /// <typeparam name="TArg">The type of the argument.</typeparam> + /// <typeparam name="TRes">The type of the result.</typeparam> + /// <param name="key">The key.</param> + /// <param name="processor">The processor.</param> + /// <param name="arg">The argument.</param> + /// <returns>Result of the processing.</returns> + /// <exception cref="CacheEntryProcessorException">If an exception has occured during processing.</exception> + Task<TRes> InvokeAsync<TArg, TRes>(TK key, ICacheEntryProcessor<TK, TV, TArg, TRes> processor, TArg arg); + + /// <summary> + /// Invokes an <see cref="ICacheEntryProcessor{K, V, A, R}"/> against a set of keys. + /// If an entry does not exist for the specified key, an attempt is made to load it (if a loader is configured) + /// or a surrogate entry, consisting of the key with a null value is used instead. + /// + /// The order that the entries for the keys are processed is undefined. + /// Implementations may choose to process the entries in any order, including concurrently. + /// Furthermore there is no guarantee implementations will use the same processor instance + /// to process each entry, as the case may be in a non-local cache topology. + /// </summary> + /// <typeparam name="TArg">The type of the argument.</typeparam> + /// <typeparam name="TRes">The type of the result.</typeparam> + /// <param name="keys">The keys.</param> + /// <param name="processor">The processor.</param> + /// <param name="arg">The argument.</param> + /// <returns> + /// Map of <see cref="ICacheEntryProcessorResult{R}" /> of the processing per key, if any, + /// defined by the <see cref="ICacheEntryProcessor{K,V,A,R}"/> implementation. + /// No mappings will be returned for processors that return a null value for a key. + /// </returns> + /// <exception cref="CacheEntryProcessorException">If an exception has occured during processing.</exception> + IDictionary<TK, ICacheEntryProcessorResult<TRes>> InvokeAll<TArg, TRes>(IEnumerable<TK> keys, + ICacheEntryProcessor<TK, TV, TArg, TRes> processor, TArg arg); + + /// <summary> /// Invokes an <see cref="ICacheEntryProcessor{K, V, A, R}"/> against a set of keys. - /// If an entry does not exist for the specified key, an attempt is made to load it (if a loader is configured) + /// If an entry does not exist for the specified key, an attempt is made to load it (if a loader is configured) /// or a surrogate entry, consisting of the key with a null value is used instead. - /// - /// The order that the entries for the keys are processed is undefined. + /// + /// The order that the entries for the keys are processed is undefined. /// Implementations may choose to process the entries in any order, including concurrently. - /// Furthermore there is no guarantee implementations will use the same processor instance + /// Furthermore there is no guarantee implementations will use the same processor instance /// to process each entry, as the case may be in a non-local cache topology. /// </summary> /// <typeparam name="TArg">The type of the argument.</typeparam> @@ -521,13 +776,12 @@ namespace Apache.Ignite.Core.Cache /// <param name="processor">The processor.</param> /// <param name="arg">The argument.</param> /// <returns> - /// Map of <see cref="ICacheEntryProcessorResult{R}" /> of the processing per key, if any, - /// defined by the <see cref="ICacheEntryProcessor{K,V,A,R}"/> implementation. + /// Map of <see cref="ICacheEntryProcessorResult{R}" /> of the processing per key, if any, + /// defined by the <see cref="ICacheEntryProcessor{K,V,A,R}"/> implementation. /// No mappings will be returned for processors that return a null value for a key. /// </returns> /// <exception cref="CacheEntryProcessorException">If an exception has occured during processing.</exception> - [AsyncSupported] - IDictionary<TK, ICacheEntryProcessorResult<TRes>> InvokeAll<TArg, TRes>(IEnumerable<TK> keys, + Task<IDictionary<TK, ICacheEntryProcessorResult<TRes>>> InvokeAllAsync<TArg, TRes>(IEnumerable<TK> keys, ICacheEntryProcessor<TK, TV, TArg, TRes> processor, TArg arg); /// <summary> @@ -554,7 +808,7 @@ namespace Apache.Ignite.Core.Cache /// </summary> /// <param name="key">Key to check.</param> /// <param name="byCurrentThread"> - /// If true, checks that current thread owns a lock on this key; + /// If true, checks that current thread owns a lock on this key; /// otherwise, checks that any thread on any node owns a lock on this key. /// </param> /// <returns>True if specified key is locked; otherwise, false.</returns> @@ -569,17 +823,17 @@ namespace Apache.Ignite.Core.Cache ICacheMetrics GetMetrics(); /// <summary> - /// Rebalances cache partitions. This method is usually used when rebalanceDelay configuration parameter - /// has non-zero value. When many nodes are started or stopped almost concurrently, - /// it is more efficient to delay rebalancing until the node topology is stable to make sure that no redundant + /// Rebalances cache partitions. This method is usually used when rebalanceDelay configuration parameter + /// has non-zero value. When many nodes are started or stopped almost concurrently, + /// it is more efficient to delay rebalancing until the node topology is stable to make sure that no redundant /// re-partitioning happens. /// <para /> - /// In case of partitioned caches, for better efficiency user should usually make sure that new nodes get + /// In case of partitioned caches, for better efficiency user should usually make sure that new nodes get /// placed on the same place of consistent hash ring as the left nodes, and that nodes are restarted before /// rebalanceDelay expires. /// </summary> - /// <returns>Future that will be completed when rebalancing is finished.</returns> - IFuture Rebalance(); + /// <returns>Task that will be completed when rebalancing is finished.</returns> + Task Rebalance(); /// <summary> /// Get another cache instance with no-retries behavior enabled.
http://git-wip-us.apache.org/repos/asf/ignite/blob/cc1aa533/modules/platforms/dotnet/Apache.Ignite.Core/Common/AsyncSupportedAttribute.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Common/AsyncSupportedAttribute.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Common/AsyncSupportedAttribute.cs deleted file mode 100644 index 094a93c..0000000 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Common/AsyncSupportedAttribute.cs +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/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. - */ - -namespace Apache.Ignite.Core.Common -{ - using System; - - /// <summary> - /// Attribute to indicate that method can be executed asynchronously if async mode is enabled. - /// To enable async mode, invoke <see cref="IAsyncSupport{TWithAsync}.WithAsync"/> method on the API. - /// The future for the async method can be retrieved via - /// <see cref="IFuture{T}"/> right after the execution of an asynchronous method. - /// </summary> - [AttributeUsage(AttributeTargets.Method)] - public sealed class AsyncSupportedAttribute : Attribute - { - // No-op. - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/cc1aa533/modules/platforms/dotnet/Apache.Ignite.Core/Common/IAsyncSupport.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Common/IAsyncSupport.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Common/IAsyncSupport.cs deleted file mode 100644 index ee98c5a..0000000 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Common/IAsyncSupport.cs +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/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. - */ - -namespace Apache.Ignite.Core.Common -{ - /// <summary> - /// Allows to enable asynchronous mode on Ignite APIs. - /// </summary> - /// <typeparam name="TWithAsync">Type of WithAsync method result.</typeparam> - public interface IAsyncSupport<out TWithAsync> where TWithAsync : IAsyncSupport<TWithAsync> - { - /// <summary> - /// Gets component with asynchronous mode enabled. - /// </summary> - /// <returns>Component with asynchronous mode enabled.</returns> - TWithAsync WithAsync(); - - /// <summary> - /// Gets a value indicating whether this instance is in asynchronous mode. - /// </summary> - /// <value> - /// <c>true</c> if asynchronous mode is enabled. - /// </value> - bool IsAsync { get; } - - /// <summary> - /// Gets and resets future for previous asynchronous operation. - /// </summary> - /// <returns>Future for previous asynchronous operation.</returns> - IFuture GetFuture(); - - /// <summary> - /// Gets and resets future for previous asynchronous operation. - /// </summary> - /// <returns>Future for previous asynchronous operation.</returns> - IFuture<TResult> GetFuture<TResult>(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/cc1aa533/modules/platforms/dotnet/Apache.Ignite.Core/Common/IFuture.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Common/IFuture.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Common/IFuture.cs deleted file mode 100644 index 2e94cd4..0000000 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Common/IFuture.cs +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/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. - */ - -namespace Apache.Ignite.Core.Common -{ - using System; - using System.Threading.Tasks; - - /// <summary> - /// Non-generic Future. Represents an asynchronous operation that can return a value. - /// <para/> - /// All members are thread-safe and may be used concurrently from multiple threads. - /// </summary> - public interface IFuture - { - /// <summary> - /// Gets a value indicating whether this instance is done. - /// </summary> - bool IsDone - { - get; - } - - /// <summary> - /// Gets the future result. - /// </summary> - /// <returns>Future result.</returns> - object Get(); - - /// <summary> - /// Gets the future result with a timeout. - /// </summary> - /// <param name="timeout">The timeout.</param> - /// <returns> - /// Future result, if it is obtained within specified timeout; otherwise, throws <see cref="TimeoutException"/> - /// </returns> - /// <exception cref="TimeoutException">Thrown if Get operation exceeded specified timeout.</exception> - object Get(TimeSpan timeout); - - /// <summary> - /// Listens this instance and invokes callback upon future completion. - /// </summary> - /// <param name="callback">The callback to execute upon future completion.</param> - void Listen(Action callback); - - /// <summary> - /// Listens this instance and invokes callback upon future completion. - /// </summary> - /// <param name="callback">The callback to execute upon future completion.</param> - void Listen(Action<IFuture> callback); - - /// <summary> - /// Gets an IAsyncResult indicating the state of this Future. - /// </summary> - /// <returns>Future state representation in form of IAsyncResult.</returns> - IAsyncResult ToAsyncResult(); - - /// <summary> - /// Gets a Task that returns the result of this Future. - /// </summary> - /// <returns>Task that completes when this future gets done and returns the result.</returns> - Task<object> ToTask(); - } - - /// <summary> - /// Generic Future. Represents an asynchronous operation that can return a value. - /// <para/> - /// All members are thread-safe and may be used concurrently from multiple threads. - /// </summary> - /// <typeparam name="T">Future result type.</typeparam> - public interface IFuture<T> : IFuture - { - /// <summary> - /// Gets the future result. - /// </summary> - /// <returns>Future result.</returns> - new T Get(); - - /// <summary> - /// Gets the future result with a timeout. - /// </summary> - /// <param name="timeout">The timeout.</param> - /// <returns> - /// Future result, if it is obtained within specified timeout; otherwise, throws <see cref="TimeoutException"/> - /// </returns> - /// <exception cref="TimeoutException">Thrown if Get operation exceeded specified timeout.</exception> - new T Get(TimeSpan timeout); - - /// <summary> - /// Gets a Task that returns the result of this Future. - /// </summary> - /// <returns>Task that completes when this future gets done and returns the result.</returns> - new Task<T> ToTask(); - - /// <summary> - /// Listens this instance and invokes callback upon future completion. - /// </summary> - /// <param name="callback">The callback to execute upon future completion.</param> - void Listen(Action<IFuture<T>> callback); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/cc1aa533/modules/platforms/dotnet/Apache.Ignite.Core/Compute/ComputeTaskAdapter.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Compute/ComputeTaskAdapter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Compute/ComputeTaskAdapter.cs index 367947a..db2ab51 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Compute/ComputeTaskAdapter.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Compute/ComputeTaskAdapter.cs @@ -79,7 +79,7 @@ namespace Apache.Ignite.Core.Compute /// <summary> /// Reduces (or aggregates) results received so far into one compound result to be returned to - /// caller via future. + /// caller via task. /// <para /> /// Note, that if some jobs did not succeed and could not be failed over then the list of /// results passed into this method will include the failed results. Otherwise, failed http://git-wip-us.apache.org/repos/asf/ignite/blob/cc1aa533/modules/platforms/dotnet/Apache.Ignite.Core/Compute/ICompute.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Compute/ICompute.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Compute/ICompute.cs index 28471aa..ad7bbb5 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Compute/ICompute.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Compute/ICompute.cs @@ -19,8 +19,8 @@ namespace Apache.Ignite.Core.Compute { using System; using System.Collections.Generic; + using System.Threading.Tasks; using Apache.Ignite.Core.Cluster; - using Apache.Ignite.Core.Common; /// <summary> /// Defines Ignite functionality for executing tasks and closures over nodes @@ -28,7 +28,7 @@ namespace Apache.Ignite.Core.Compute /// is obtained from grid projection using <see cref="IClusterGroup.GetCompute"/> method. /// <para /> /// Note that if attempt is made to execute a computation over an empty projection (i.e. projection that does - /// not have any alive nodes), <c>ClusterGroupEmptyException</c> will be thrown out of result future. + /// not have any alive nodes), <c>ClusterGroupEmptyException</c> will be thrown out of result task. /// <para /> /// Ignite must select a node for a computation to be executed. The node will be selected based on the /// underlying <c>GridLoadBalancingSpi</c>, which by default sequentially picks next available node from @@ -45,7 +45,7 @@ namespace Apache.Ignite.Core.Compute /// <para/> /// All members are thread-safe and may be used concurrently from multiple threads. /// </summary> - public interface ICompute : IAsyncSupport<ICompute> + public interface ICompute { /// <summary> /// Grid projection to which this compute instance belongs. @@ -88,6 +88,16 @@ namespace Apache.Ignite.Core.Compute TRes ExecuteJavaTask<TRes>(string taskName, object taskArg); /// <summary> + /// Executes given Java task on the grid projection. If task for given name has not been deployed yet, + /// then 'taskName' will be used as task class name to auto-deploy the task. + /// </summary> + /// <param name="taskName">Java task name</param> + /// <param name="taskArg">Optional argument of task execution, can be null.</param> + /// <returns>Task result.</returns> + /// <typeparam name="TRes">Type of task result.</typeparam> + Task<TRes> ExecuteJavaTaskAsync<TRes>(string taskName, object taskArg); + + /// <summary> /// Executes given task on the grid projection. For step-by-step explanation of task execution process /// refer to <see cref="IComputeTask{A,T,R}"/> documentation. /// </summary> @@ -97,9 +107,20 @@ namespace Apache.Ignite.Core.Compute /// <typeparam name="TArg">Argument type.</typeparam> /// <typeparam name="TJobRes">Type of job result.</typeparam> /// <typeparam name="TRes">Type of final task result.</typeparam> - [AsyncSupported] TRes Execute<TArg, TJobRes, TRes>(IComputeTask<TArg, TJobRes, TRes> task, TArg taskArg); - + + /// <summary> + /// Executes given task on the grid projection. For step-by-step explanation of task execution process + /// refer to <see cref="IComputeTask{A,T,R}"/> documentation. + /// </summary> + /// <param name="task">Task to execute.</param> + /// <param name="taskArg">Optional task argument.</param> + /// <returns>Task result.</returns> + /// <typeparam name="TArg">Argument type.</typeparam> + /// <typeparam name="TJobRes">Type of job result.</typeparam> + /// <typeparam name="TRes">Type of final task result.</typeparam> + Task<TRes> ExecuteAsync<TArg, TJobRes, TRes>(IComputeTask<TArg, TJobRes, TRes> task, TArg taskArg); + /// <summary> /// Executes given task on the grid projection. For step-by-step explanation of task execution process /// refer to <see cref="IComputeTask{A,T,R}"/> documentation. @@ -108,22 +129,42 @@ namespace Apache.Ignite.Core.Compute /// <returns>Task result.</returns> /// <typeparam name="TJobRes">Type of job result.</typeparam> /// <typeparam name="TRes">Type of reduce result.</typeparam> - [AsyncSupported] TRes Execute<TJobRes, TRes>(IComputeTask<TJobRes, TRes> task); /// <summary> /// Executes given task on the grid projection. For step-by-step explanation of task execution process /// refer to <see cref="IComputeTask{A,T,R}"/> documentation. /// </summary> + /// <param name="task">Task to execute.</param> + /// <returns>Task result.</returns> + /// <typeparam name="TJobRes">Type of job result.</typeparam> + /// <typeparam name="TRes">Type of reduce result.</typeparam> + Task<TRes> ExecuteAsync<TJobRes, TRes>(IComputeTask<TJobRes, TRes> task); + + /// <summary> + /// Executes given task on the grid projection. For step-by-step explanation of task execution process + /// refer to <see cref="IComputeTask{A,T,R}"/> documentation. + /// </summary> /// <param name="taskType">Task type.</param> /// <param name="taskArg">Optional task argument.</param> /// <returns>Task result.</returns> /// <typeparam name="TArg">Argument type.</typeparam> /// <typeparam name="TJobRes">Type of job result.</typeparam> /// <typeparam name="TRes">Type of reduce result.</typeparam> - [AsyncSupported] TRes Execute<TArg, TJobRes, TRes>(Type taskType, TArg taskArg); - + + /// <summary> + /// Executes given task on the grid projection. For step-by-step explanation of task execution process + /// refer to <see cref="IComputeTask{A,T,R}"/> documentation. + /// </summary> + /// <param name="taskType">Task type.</param> + /// <param name="taskArg">Optional task argument.</param> + /// <returns>Task result.</returns> + /// <typeparam name="TArg">Argument type.</typeparam> + /// <typeparam name="TJobRes">Type of job result.</typeparam> + /// <typeparam name="TRes">Type of reduce result.</typeparam> + Task<TRes> ExecuteAsync<TArg, TJobRes, TRes>(Type taskType, TArg taskArg); + /// <summary> /// Executes given task on the grid projection. For step-by-step explanation of task execution process /// refer to <see cref="IComputeTask{A,T,R}"/> documentation. @@ -132,21 +173,38 @@ namespace Apache.Ignite.Core.Compute /// <returns>Task result.</returns> /// <typeparam name="TJobRes">Type of job result.</typeparam> /// <typeparam name="TRes">Type of reduce result.</typeparam> - [AsyncSupported] TRes Execute<TJobRes, TRes>(Type taskType); /// <summary> + /// Executes given task on the grid projection. For step-by-step explanation of task execution process + /// refer to <see cref="IComputeTask{A,T,R}"/> documentation. + /// </summary> + /// <param name="taskType">Task type.</param> + /// <returns>Task result.</returns> + /// <typeparam name="TJobRes">Type of job result.</typeparam> + /// <typeparam name="TRes">Type of reduce result.</typeparam> + Task<TRes> ExecuteAsync<TJobRes, TRes>(Type taskType); + + /// <summary> /// Executes provided job on a node in this grid projection. The result of the /// job execution is returned from the result closure. /// </summary> /// <param name="clo">Job to execute.</param> /// <returns>Job result for this execution.</returns> /// <typeparam name="TRes">Type of job result.</typeparam> - [AsyncSupported] TRes Call<TRes>(IComputeFunc<TRes> clo); /// <summary> - /// Executes given job on the node where data for provided affinity key is located + /// Executes provided job on a node in this grid projection. The result of the + /// job execution is returned from the result closure. + /// </summary> + /// <param name="clo">Job to execute.</param> + /// <returns>Job result for this execution.</returns> + /// <typeparam name="TRes">Type of job result.</typeparam> + Task<TRes> CallAsync<TRes>(IComputeFunc<TRes> clo); + + /// <summary> + /// Executes given job on the node where data for provided affinity key is located /// (a.k.a. affinity co-location). /// </summary> /// <param name="cacheName">Name of the cache to use for affinity co-location.</param> @@ -154,10 +212,20 @@ namespace Apache.Ignite.Core.Compute /// <param name="clo">Job to execute.</param> /// <returns>Job result for this execution.</returns> /// <typeparam name="TRes">Type of job result.</typeparam> - [AsyncSupported] TRes AffinityCall<TRes>(string cacheName, object affinityKey, IComputeFunc<TRes> clo); /// <summary> + /// Executes given job on the node where data for provided affinity key is located + /// (a.k.a. affinity co-location). + /// </summary> + /// <param name="cacheName">Name of the cache to use for affinity co-location.</param> + /// <param name="affinityKey">Affinity key.</param> + /// <param name="clo">Job to execute.</param> + /// <returns>Job result for this execution.</returns> + /// <typeparam name="TRes">Type of job result.</typeparam> + Task<TRes> AffinityCallAsync<TRes>(string cacheName, object affinityKey, IComputeFunc<TRes> clo); + + /// <summary> /// Executes collection of jobs on nodes within this grid projection. /// </summary> /// <param name="clos">Collection of jobs to execute.</param> @@ -165,28 +233,50 @@ namespace Apache.Ignite.Core.Compute /// <returns>Reduced job result for this execution.</returns> /// <typeparam name="TFuncRes">Type of function result.</typeparam> /// <typeparam name="TRes">Type of result after reduce.</typeparam> - [AsyncSupported] - TRes Call<TFuncRes, TRes>(IEnumerable<IComputeFunc<TFuncRes>> clos, + TRes Call<TFuncRes, TRes>(IEnumerable<IComputeFunc<TFuncRes>> clos, IComputeReducer<TFuncRes, TRes> reducer); + + /// <summary> + /// Executes collection of jobs on nodes within this grid projection. + /// </summary> + /// <param name="clos">Collection of jobs to execute.</param> + /// <param name="reducer">Reducer to reduce all job results into one individual return value.</param> + /// <returns>Reduced job result for this execution.</returns> + /// <typeparam name="TFuncRes">Type of function result.</typeparam> + /// <typeparam name="TRes">Type of result after reduce.</typeparam> + Task<TRes> CallAsync<TFuncRes, TRes>(IEnumerable<IComputeFunc<TFuncRes>> clos, IComputeReducer<TFuncRes, TRes> reducer); - + /// <summary> /// Executes collection of jobs on nodes within this grid projection. /// </summary> /// <param name="clos">Collection of jobs to execute.</param> /// <returns>Collection of job results for this execution.</returns> /// <typeparam name="TRes">Type of job result.</typeparam> - [AsyncSupported] ICollection<TRes> Call<TRes>(IEnumerable<IComputeFunc<TRes>> clos); /// <summary> - /// Broadcasts given job to all nodes in grid projection. Every participating node will return a job result. + /// Executes collection of jobs on nodes within this grid projection. + /// </summary> + /// <param name="clos">Collection of jobs to execute.</param> + /// <returns>Collection of job results for this execution.</returns> + /// <typeparam name="TRes">Type of job result.</typeparam> + Task<ICollection<TRes>> CallAsync<TRes>(IEnumerable<IComputeFunc<TRes>> clos); + + /// <summary> + /// Broadcasts given job to all nodes in grid projection. Every participating node will return a job result. /// </summary> /// <param name="clo">Job to broadcast to all projection nodes.</param> /// <returns>Collection of results for this execution.</returns> - [AsyncSupported] ICollection<TRes> Broadcast<TRes>(IComputeFunc<TRes> clo); /// <summary> + /// Broadcasts given job to all nodes in grid projection. Every participating node will return a job result. + /// </summary> + /// <param name="clo">Job to broadcast to all projection nodes.</param> + /// <returns>Collection of results for this execution.</returns> + Task<ICollection<TRes>> BroadcastAsync<TRes>(IComputeFunc<TRes> clo); + + /// <summary> /// Broadcasts given closure job with passed in argument to all nodes in grid projection. /// Every participating node will return a job result. /// </summary> @@ -195,41 +285,74 @@ namespace Apache.Ignite.Core.Compute /// <returns>Collection of results for this execution.</returns> /// <typeparam name="TArg">Type of argument.</typeparam> /// <typeparam name="TRes">Type of job result.</typeparam> - [AsyncSupported] ICollection<TRes> Broadcast<TArg, TRes>(IComputeFunc<TArg, TRes> clo, TArg arg); /// <summary> + /// Broadcasts given closure job with passed in argument to all nodes in grid projection. + /// Every participating node will return a job result. + /// </summary> + /// <param name="clo">Job to broadcast to all projection nodes.</param> + /// <param name="arg">Job closure argument.</param> + /// <returns>Collection of results for this execution.</returns> + /// <typeparam name="TArg">Type of argument.</typeparam> + /// <typeparam name="TRes">Type of job result.</typeparam> + Task<ICollection<TRes>> BroadcastAsync<TArg, TRes>(IComputeFunc<TArg, TRes> clo, TArg arg); + + /// <summary> /// Broadcasts given job to all nodes in grid projection. /// </summary> /// <param name="action">Job to broadcast to all projection nodes.</param> - [AsyncSupported] void Broadcast(IComputeAction action); /// <summary> + /// Broadcasts given job to all nodes in grid projection. + /// </summary> + /// <param name="action">Job to broadcast to all projection nodes.</param> + Task BroadcastAsync(IComputeAction action); + + /// <summary> /// Executes provided job on a node in this grid projection. /// </summary> /// <param name="action">Job to execute.</param> - [AsyncSupported] void Run(IComputeAction action); /// <summary> + /// Executes provided job on a node in this grid projection. + /// </summary> + /// <param name="action">Job to execute.</param> + Task RunAsync(IComputeAction action); + + /// <summary> /// Executes given job on the node where data for provided affinity key is located /// (a.k.a. affinity co-location). /// </summary> /// <param name="cacheName">Name of the cache to use for affinity co-location.</param> /// <param name="affinityKey">Affinity key.</param> /// <param name="action">Job to execute.</param> - [AsyncSupported] void AffinityRun(string cacheName, object affinityKey, IComputeAction action); /// <summary> + /// Executes given job on the node where data for provided affinity key is located + /// (a.k.a. affinity co-location). + /// </summary> + /// <param name="cacheName">Name of the cache to use for affinity co-location.</param> + /// <param name="affinityKey">Affinity key.</param> + /// <param name="action">Job to execute.</param> + Task AffinityRunAsync(string cacheName, object affinityKey, IComputeAction action); + + /// <summary> /// Executes collection of jobs on Ignite nodes within this grid projection. /// </summary> /// <param name="actions">Jobs to execute.</param> - [AsyncSupported] void Run(IEnumerable<IComputeAction> actions); /// <summary> + /// Executes collection of jobs on Ignite nodes within this grid projection. + /// </summary> + /// <param name="actions">Jobs to execute.</param> + Task RunAsync(IEnumerable<IComputeAction> actions); + + /// <summary> /// Executes provided closure job on a node in this grid projection. /// </summary> /// <param name="clo">Job to run.</param> @@ -237,10 +360,19 @@ namespace Apache.Ignite.Core.Compute /// <returns>Job result for this execution.</returns> /// <typeparam name="TArg">Type of argument.</typeparam> /// <typeparam name="TRes">Type of job result.</typeparam> - [AsyncSupported] TRes Apply<TArg, TRes>(IComputeFunc<TArg, TRes> clo, TArg arg); /// <summary> + /// Executes provided closure job on a node in this grid projection. + /// </summary> + /// <param name="clo">Job to run.</param> + /// <param name="arg">Job argument.</param> + /// <returns>Job result for this execution.</returns> + /// <typeparam name="TArg">Type of argument.</typeparam> + /// <typeparam name="TRes">Type of job result.</typeparam> + Task<TRes> ApplyAsync<TArg, TRes>(IComputeFunc<TArg, TRes> clo, TArg arg); + + /// <summary> /// Executes provided closure job on nodes within this grid projection. A new job is executed for /// every argument in the passed in collection. The number of actual job executions will be /// equal to size of the job arguments collection. @@ -250,12 +382,23 @@ namespace Apache.Ignite.Core.Compute /// <returns>Сollection of job results.</returns> /// <typeparam name="TArg">Type of argument.</typeparam> /// <typeparam name="TRes">Type of job result.</typeparam> - [AsyncSupported] ICollection<TRes> Apply<TArg, TRes>(IComputeFunc<TArg, TRes> clo, IEnumerable<TArg> args); /// <summary> /// Executes provided closure job on nodes within this grid projection. A new job is executed for /// every argument in the passed in collection. The number of actual job executions will be + /// equal to size of the job arguments collection. + /// </summary> + /// <param name="clo">Job to run.</param> + /// <param name="args">Job arguments.</param> + /// <returns>Сollection of job results.</returns> + /// <typeparam name="TArg">Type of argument.</typeparam> + /// <typeparam name="TRes">Type of job result.</typeparam> + Task<ICollection<TRes>> ApplyAsync<TArg, TRes>(IComputeFunc<TArg, TRes> clo, IEnumerable<TArg> args); + + /// <summary> + /// Executes provided closure job on nodes within this grid projection. A new job is executed for + /// every argument in the passed in collection. The number of actual job executions will be /// equal to size of the job arguments collection. The returned job results will be reduced /// into an individual result by provided reducer. /// </summary> @@ -266,8 +409,23 @@ namespace Apache.Ignite.Core.Compute /// <typeparam name="TArg">Type of argument.</typeparam> /// <typeparam name="TFuncRes">Type of function result.</typeparam> /// <typeparam name="TRes">Type of result after reduce.</typeparam> - [AsyncSupported] TRes Apply<TArg, TFuncRes, TRes>(IComputeFunc<TArg, TFuncRes> clo, IEnumerable<TArg> args, IComputeReducer<TFuncRes, TRes> rdc); + + /// <summary> + /// Executes provided closure job on nodes within this grid projection. A new job is executed for + /// every argument in the passed in collection. The number of actual job executions will be + /// equal to size of the job arguments collection. The returned job results will be reduced + /// into an individual result by provided reducer. + /// </summary> + /// <param name="clo">Job to run.</param> + /// <param name="args">Job arguments.</param> + /// <param name="rdc">Reducer to reduce all job results into one individual return value.</param> + /// <returns>Reduced job result for this execution.</returns> + /// <typeparam name="TArg">Type of argument.</typeparam> + /// <typeparam name="TFuncRes">Type of function result.</typeparam> + /// <typeparam name="TRes">Type of result after reduce.</typeparam> + Task<TRes> ApplyAsync<TArg, TFuncRes, TRes>(IComputeFunc<TArg, TFuncRes> clo, IEnumerable<TArg> args, + IComputeReducer<TFuncRes, TRes> rdc); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/cc1aa533/modules/platforms/dotnet/Apache.Ignite.Core/Compute/IComputeTask.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Compute/IComputeTask.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Compute/IComputeTask.cs index 7677653..8c3136b 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Compute/IComputeTask.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Compute/IComputeTask.cs @@ -66,7 +66,7 @@ namespace Apache.Ignite.Core.Compute /// </item> /// <item> /// <description>Once all results are received or - /// <see cref="IComputeTask{A,T,R}.Result(IComputeJobResult{TJobRes}, IList{IComputeJobResult{TJobRes}})"/> + /// <see cref="IComputeTask{A,T,R}.OnResult(IComputeJobResult{TJobRes}, IList{IComputeJobResult{TJobRes}})"/> /// method returned <see cref="ComputeJobResultPolicy.Reduce"/> policy, method /// <see cref="IComputeTask{A,T,R}.Reduce(IList{IComputeJobResult{TJobRes}})"/> /// is called to aggregate received results into one final result. Once this method is finished the http://git-wip-us.apache.org/repos/asf/ignite/blob/cc1aa533/modules/platforms/dotnet/Apache.Ignite.Core/Datastream/IDataStreamer.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Datastream/IDataStreamer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Datastream/IDataStreamer.cs index 2713040..8c83b74 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Datastream/IDataStreamer.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Datastream/IDataStreamer.cs @@ -19,8 +19,8 @@ namespace Apache.Ignite.Core.Datastream { using System; using System.Collections.Generic; + using System.Threading.Tasks; using Apache.Ignite.Core.Cache.Store; - using Apache.Ignite.Core.Common; /// <summary> /// Data streamer is responsible for loading external data into cache. It achieves it by @@ -130,10 +130,10 @@ namespace Apache.Ignite.Core.Datastream long AutoFlushFrequency { get; set; } /// <summary> - /// Gets future for this loading process. This future completes whenever method + /// Gets the task for this loading process. This task completes whenever method /// <see cref="IDataStreamer{K,V}.Close(bool)"/> completes. /// </summary> - IFuture Future { get; } + Task Task { get; } /// <summary> /// Gets or sets custom stream receiver. @@ -146,30 +146,30 @@ namespace Apache.Ignite.Core.Datastream /// </summary> /// <param name="key">Key.</param> /// <param name="val">Value.</param> - /// <returns>Future for this operation.</returns> - IFuture AddData(TK key, TV val); + /// <returns>Task for this operation.</returns> + Task AddData(TK key, TV val); /// <summary> /// Adds single key-value pair for loading. Passing <c>null</c> as pair's value will /// be interpreted as removal. /// </summary> /// <param name="pair">Key-value pair.</param> - /// <returns>Future for this operation.</returns> - IFuture AddData(KeyValuePair<TK, TV> pair); + /// <returns>Task for this operation.</returns> + Task AddData(KeyValuePair<TK, TV> pair); /// <summary> /// Adds collection of key-value pairs for loading. /// </summary> /// <param name="entries">Entries.</param> - /// <returns>Future for this operation.</returns> - IFuture AddData(ICollection<KeyValuePair<TK, TV>> entries); + /// <returns>Task for this operation.</returns> + Task AddData(ICollection<KeyValuePair<TK, TV>> entries); /// <summary> /// Adds key for removal. /// </summary> /// <param name="key">Key.</param> - /// <returns>Future for this operation.</returns> - IFuture RemoveData(TK key); + /// <returns>Task for this operation.</returns> + Task RemoveData(TK key); /// <summary> /// Makes an attempt to load remaining data. This method is mostly similar to http://git-wip-us.apache.org/repos/asf/ignite/blob/cc1aa533/modules/platforms/dotnet/Apache.Ignite.Core/Events/IEvents.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Events/IEvents.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Events/IEvents.cs index e8459c6..abaa9e7 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Events/IEvents.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Events/IEvents.cs @@ -19,15 +19,15 @@ namespace Apache.Ignite.Core.Events { using System; using System.Collections.Generic; + using System.Threading.Tasks; using Apache.Ignite.Core.Cluster; - using Apache.Ignite.Core.Common; /// <summary> /// Provides functionality for event notifications on nodes defined by <see cref="ClusterGroup"/>. /// <para/> /// All members are thread-safe and may be used concurrently from multiple threads. /// </summary> - public interface IEvents : IAsyncSupport<IEvents> + public interface IEvents { /// <summary> /// Gets the cluster group to which this instance belongs. @@ -42,7 +42,6 @@ namespace Apache.Ignite.Core.Events /// <param name="timeout">Maximum time to wait for result, null or 0 to wait forever.</param> /// <param name="types">Event types to be queried.</param> /// <returns>Collection of Ignite events returned from specified nodes.</returns> - [AsyncSupported] ICollection<T> RemoteQuery<T>(IEventFilter<T> filter, TimeSpan? timeout = null, params int[] types) where T : IEvent; @@ -54,17 +53,37 @@ namespace Apache.Ignite.Core.Events /// <param name="timeout">Maximum time to wait for result, null or 0 to wait forever.</param> /// <param name="types">Event types to be queried.</param> /// <returns>Collection of Ignite events returned from specified nodes.</returns> - [AsyncSupported] + Task<ICollection<T>> RemoteQueryAsync<T>(IEventFilter<T> filter, TimeSpan? timeout = null, params int[] types) + where T : IEvent; + + /// <summary> + /// Queries nodes in this cluster group for events using passed in predicate filter for event selection. + /// </summary> + /// <typeparam name="T">Type of events.</typeparam> + /// <param name="filter">Predicate filter used to query events on remote nodes.</param> + /// <param name="timeout">Maximum time to wait for result, null or 0 to wait forever.</param> + /// <param name="types">Event types to be queried.</param> + /// <returns>Collection of Ignite events returned from specified nodes.</returns> ICollection<T> RemoteQuery<T>(IEventFilter<T> filter, TimeSpan? timeout = null, IEnumerable<int> types = null) where T : IEvent; /// <summary> + /// Queries nodes in this cluster group for events using passed in predicate filter for event selection. + /// </summary> + /// <typeparam name="T">Type of events.</typeparam> + /// <param name="filter">Predicate filter used to query events on remote nodes.</param> + /// <param name="timeout">Maximum time to wait for result, null or 0 to wait forever.</param> + /// <param name="types">Event types to be queried.</param> + /// <returns>Collection of Ignite events returned from specified nodes.</returns> + Task<ICollection<T>> RemoteQueryAsync<T>(IEventFilter<T> filter, TimeSpan? timeout = null, IEnumerable<int> types = null) + where T : IEvent; + + /// <summary> /// Waits for the specified events. /// </summary> /// <param name="types">Types of the events to wait for. /// If not provided, all events will be passed to the filter.</param> /// <returns>Ignite event.</returns> - [AsyncSupported] IEvent WaitForLocal(params int[] types); /// <summary> @@ -73,18 +92,32 @@ namespace Apache.Ignite.Core.Events /// <param name="types">Types of the events to wait for. /// If not provided, all events will be passed to the filter.</param> /// <returns>Ignite event.</returns> - [AsyncSupported] + Task<IEvent> WaitForLocalAsync(params int[] types); + + /// <summary> + /// Waits for the specified events. + /// </summary> + /// <param name="types">Types of the events to wait for. + /// If not provided, all events will be passed to the filter.</param> + /// <returns>Ignite event.</returns> IEvent WaitForLocal(IEnumerable<int> types); /// <summary> /// Waits for the specified events. /// </summary> + /// <param name="types">Types of the events to wait for. + /// If not provided, all events will be passed to the filter.</param> + /// <returns>Ignite event.</returns> + Task<IEvent> WaitForLocalAsync(IEnumerable<int> types); + + /// <summary> + /// Waits for the specified events. + /// </summary> /// <typeparam name="T">Type of events.</typeparam> /// <param name="filter">Optional filtering predicate. Event wait will end as soon as it returns false.</param> /// <param name="types">Types of the events to wait for. /// If not provided, all events will be passed to the filter.</param> /// <returns>Ignite event.</returns> - [AsyncSupported] T WaitForLocal<T>(IEventFilter<T> filter, params int[] types) where T : IEvent; /// <summary> @@ -95,10 +128,29 @@ namespace Apache.Ignite.Core.Events /// <param name="types">Types of the events to wait for. /// If not provided, all events will be passed to the filter.</param> /// <returns>Ignite event.</returns> - [AsyncSupported] + Task<T> WaitForLocalAsync<T>(IEventFilter<T> filter, params int[] types) where T : IEvent; + + /// <summary> + /// Waits for the specified events. + /// </summary> + /// <typeparam name="T">Type of events.</typeparam> + /// <param name="filter">Optional filtering predicate. Event wait will end as soon as it returns false.</param> + /// <param name="types">Types of the events to wait for. + /// If not provided, all events will be passed to the filter.</param> + /// <returns>Ignite event.</returns> T WaitForLocal<T>(IEventFilter<T> filter, IEnumerable<int> types) where T : IEvent; /// <summary> + /// Waits for the specified events. + /// </summary> + /// <typeparam name="T">Type of events.</typeparam> + /// <param name="filter">Optional filtering predicate. Event wait will end as soon as it returns false.</param> + /// <param name="types">Types of the events to wait for. + /// If not provided, all events will be passed to the filter.</param> + /// <returns>Ignite event.</returns> + Task<T> WaitForLocalAsync<T>(IEventFilter<T> filter, IEnumerable<int> types) where T : IEvent; + + /// <summary> /// Queries local node for events using of specified types. /// </summary> /// <param name="types">Event types to be queried. Optional.</param>
