Runs a parallel method invocation on the map contents and returns the result.
The Eval and Merge methods should be defined via passing instance of the
NamedMapInvokableTKey, TValue, TParam, TResult class.
Note: this method requires that InvocationGrid is assigned to the NamedMapTKey, TValue.
Namespace: Soss.Client.Concurrent
Assembly: soss_namedcache (in soss_namedcache.dll) Version: 6.2.0.0
Syntax
public TResult Invoke<TParam, TResult>( NamedMapInvokable<TKey, TValue, TParam, TResult> operation, TParam parameter, TimeSpan invokeTimeout )
Parameters
- operation
- Type: Soss.Client.ConcurrentNamedMapInvokableTKey, TValue, TParam, TResult
Parallel operation to run - parameter
- Type: TParam
Invocation parameter - invokeTimeout
- Type: SystemTimeSpan
Timeout for the distributed invocation operation
Type Parameters
- TParam
- Type of parameter object
- TResult
- Type of result object
Return Value
Type: TResultResult object of type TResult
Examples
Performing a parallel method invocation using the NamedMap class
using System; using System.Reflection; using Soss.Client; using Soss.Client.Concurrent; // Perform a distributed PMI operation using NamedMap.Invoke() to // find the factorial of 12 (479,001,600). // // Prior to calling the Invoke method, the PMI operation is defined // using the NamedMapInvokable class, whose "Eval" and "Merge" callbacks // need to be specified at construction. The Eval method is called for // every object in the named map and, in this sample, is simply returns // the object that is being evaluated. The Merge method is used to // combine results from the Eval method calls--the PMI engine calls it // repeatedly to consolidate results down to a single result object that is // returned to the original NamedMap.Invoke() caller. class InvokeUsage { static void Main(string[] args) { NamedMap<string, int> map = new NamedMap<string, int>("Sample Map"); map.Clear(); // Configure an invocation grid that will be used to run Parallel // Method Invocation (PMI) operations on the elements in the // named map. An invocation grid is responsible for deploying your // custom code to worker processes that run on machines across the farm. InvocationGridBuilder igBuilder = new InvocationGridBuilder("MyGrid"); igBuilder.AddDependency(Assembly.GetExecutingAssembly()); InvocationGrid grid = igBuilder.Load(); map.InvocationGrid = grid; // Adding 12 integers (1 - 12) to the named map: for (int i = 1; i <= 12; i++) map.TryAdd(i.ToString(), i); // Use the NamedMapInvokable to define the Eval and Merge delegates: var factorialInvokable = new NamedMapInvokable<string, int, string, int> ( // Eval callback: (key, value, parameter) => { return value; }, // Merge callback: (firstResult, secondResult, param) => { firstResult *= secondResult; return firstResult; } ); // Issue the Invoke call to execute the Eval and Merge logic // against all elements in the named map in parallel across // all hosts in the ScaleOut farm. Specifying a 60 second // timeout for the entire distributed operation. int factorial = map.Invoke(factorialInvokable, null, TimeSpan.FromSeconds(60)); Console.WriteLine("fact(12): {0}", factorial); // Clean up if (grid != null) grid.Unload(); if (map != null) map.Clear(); } }
See Also