Runs a query on the map contents with the specified QueryConditionTKey, TValue.
If QueryConditionTKey, TValue is null, all map's keys will be returned.
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 IEnumerable<TKey> ExecuteParallelQuery( QueryCondition<TKey, TValue> condition, TimeSpan queryTimeout )
Parameters
- condition
- Type: Soss.Client.ConcurrentQueryConditionTKey, TValue
The query condition for selecting appropriate entries within the map, or null to return all keys. - queryTimeout
- Type: SystemTimeSpan
Timeout for the distributed query operation.
Return Value
Type: IEnumerableTKeyCollection of all matching keys.
Examples
Querying a named map by using the ExecuteParallelQuery method
using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using Soss.Client; using Soss.Client.Concurrent; // Definition of query criteria [Serializable] public class EvenNumbersQueryCondition : QueryCondition<string, int> { public override bool CheckCondition(string key, int val) { return (val % 2) == 0; } } // Queries a named map of integers for even values class QueryUsage { static void Main(string[] args) { NamedMap<string, int> map = new NamedMap<string, int>("Sample string/integer map"); map.Clear(); // Configure an invocation grid that will be used to run our // query. An invocation grid is responsible for deploying // custom code to worker processes that run on machines across the farm. InvocationGridBuilder igBuilder = new InvocationGridBuilder("Query worker grid"); igBuilder.AddDependency(Assembly.GetExecutingAssembly()); InvocationGrid grid = igBuilder.Load(); map.InvocationGrid = grid; // Add 10,000 integers to the map: for (int i = 0; i < 10000; i++) map.TryAdd(i.ToString(), i); // Query for even values. Specifying a 60 second timeout for the distributed query. Console.WriteLine("Querying for even values..."); IEnumerable<string> keys = map.ExecuteParallelQuery(new EvenNumbersQueryCondition(), TimeSpan.FromSeconds(60)); int resultCount = 0; int evenValue = 0; foreach (string key in keys) { // Get the associated value to make sure it is an even number map.TryGetValue(key, out evenValue); Debug.Assert(evenValue % 2 == 0); resultCount++; } // Check to make sure we got the half of all elements in the map Debug.Assert(resultCount == 5000); Console.WriteLine("{0} keys were returned from the query.", resultCount); // clean up grid.Unload(); map.Clear(); } }
See Also