import com.gemstone.gemfire.cache.execute.Function;
import com.gemstone.gemfire.cache.execute.FunctionException;
import com.gemstone.gemfire.cache.execute.ResultCollector;

import com.gemstone.gemfire.distributed.DistributedMember;

import java.util.List;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

import java.util.concurrent.atomic.AtomicInteger;

public class ValueBatchResultCollector implements ResultCollector<ValueBatch,List<ValueBatch>> {

  private static final AtomicInteger BATCH_COUNTER = new AtomicInteger();
  
  private static final AtomicInteger VALUE_COUNTER = new AtomicInteger();
  
  public void addResult(DistributedMember member, ValueBatch batch) {
    log(member, batch);
    batch.process();
  }
  
  private void log(DistributedMember member, ValueBatch batch) {
    System.out.println(Thread.currentThread().getName() + ": Processing batch " + BATCH_COUNTER.incrementAndGet() + " member " + member + " containing " + batch.size() + " values (total=" + VALUE_COUNTER.addAndGet(batch.size()) + ")");
  }

  public List<ValueBatch> getResult() throws FunctionException {
    return null;
  }

  public List<ValueBatch> getResult(long timeout, TimeUnit unit) throws FunctionException {
    return null;
  }

  public void endResults() {
  }

  public void clearResults() {
  }
}
