NamedMapTKey, TValueExecuteParallelQuery Method (QueryConditionTKey, TValue, TimeSpan)

ScaleOut Software NamedCache API

Namespace:  Soss.Client.Concurrent
Assembly:  soss_namedcache (in soss_namedcache.dll) Version:

public IEnumerable<TKey> ExecuteParallelQuery(
	QueryCondition<TKey, TValue> condition,
	TimeSpan queryTimeout


Type: Soss.Client.ConcurrentQueryConditionTKey, TValue
The query condition for selecting appropriate entries within the map, or null to return all keys.
Type: SystemTimeSpan
Timeout for the distributed query operation.

Return Value

Type: IEnumerableTKey
Collection of all matching keys.

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
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");

        // 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");

        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);

        // 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
See Also