NCache 4.6 - Online Documentation

Sample Implementation of IAggregator Interface

 
Implement the interface IAggregator and provide implementation for the following methods in NCache:
 
Member
Description
Aggregate(Object)
This method takes in an Object and contains the logic of applying the aggregation operation on the same node (locally) as is with Combiner. If you wish to combine the values using a aggregator before being sent for further processing in the Reducer, you can use the Aggregate() call.
AggregateAll(Object)
This method takes in an Object and contains the logic of applying the aggregation operation in the Reduce Phase. If you wish to combine the values using an aggregator, you can use the AggregateAll() call.
 
      To utilize the IAggregator interface, include the following namespace in your application: Alachisoft.NCache.Runtime.Aggregation.
 
public class IntAggregator : IAggregator
    {
        string function;
 
        public IntAggregator(string function)
        {
            this.function = function;
        }
 
        public object Aggregate(object value)
        {
            return calculate(value);
        }
 
        public object AggregateAll(object value)
        {
            return calculate(value);
        }
 
        private object calculate(object value)
        {
            switch (function)
            {
                case "MIN":
                    value = int.MinValue;
                    return value;
 
                case "MAX":
                    value = int.MaxValue;
                    return value;
 
                default:
                    return 0;
            }
        }
    }
 
 
See Also