Method ExecuteTask
ExecuteTask(MapReduceTask, IKeyFilter, QueryCommand)
Executes the specified MapReduce task on the cache, with Key Filter specified and QueryCommand which produce the resultset upon which the task is performed. This task contains implementations of the Mapper and Combiner/Reducer(optional), which will aid in the distributed processing of the cache data filtered out on Keyfilter implementation.
Declaration
ITrackableTask ExecuteTask(MapReduceTask task, IKeyFilter keyFilter = null, QueryCommand queryCommand = null)
Parameters
Type | Name | Description |
---|---|---|
MapReduceTask | task | Instance of MapReduceTask, which initializes the Mapper, Combiner and Reducer. |
IKeyFilter | keyFilter | Filters cache data based on its keys before being provided to the Mapper. The KeyFilter is called during Mapper’s execution. If it returns true, the Map will be executed on the key. If it returns false, Mapper will skip the key and move to next one from the Cache. |
QueryCommand | queryCommand | Instance of QueryCommand containing query and values. |
Returns
Type | Description |
---|---|
ITrackableTask | Tracks the submitted task for result and status. |
Examples
Note: Implemeting IReducerFactory,ICombinerFactory and ICombiner is optional.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string key1 = "2202";
Product product1 = new Product()
{
Id = 4,
Category = "Clothes",
UnitPrice = 4,
UnitsAvailable = 2
};
string key2 = "2203";
Product product2 = new Product()
{
Id = 4,
Category = "Shoes",
UnitPrice = 5,
UnitsAvailable = 9
};
cache.Add(key1, product1);
cache.Add(key2, product2);
MapReduceTask mapReduceTask = new MapReduceTask();
mapReduceTask.Mapper = new ProductCountMapper();
mapReduceTask.Combiner = new ProductCountCombinerFactory();
mapReduceTask.Reducer = new ProductCountReducerFactory();
string query = "SELECT Alachisoft.NCache.Sample.Data.Product WHERE this.Category IN (?)";
QueryCommand queryCommand = new QueryCommand(query);
queryCommand.Parameters.Add("Category", "Clothes");
ITrackableTask trackableInstance = cache.ExecutionService.ExecuteTask(mapReduceTask, null, queryCommand);