1   package com.trendmicro.grid.acl.ds.cache.commands;
2   
3   import java.util.Collection;
4   import java.util.Map;
5   import java.util.concurrent.atomic.AtomicLong;
6   
7   /**
8    * Returns the values of all keys asking the source (other cache, or data provider).
9    *
10   * @author juergen_kellerer, 2011-03-24
11   * @version 1.0
12   */
13  public abstract class GetFromSourceCommand<K, V> extends AbstractCommand<K, V> {
14  
15  	private final AtomicLong fetchedKeyCount;
16  
17  	/**
18  	 * Creates the command.
19  	 *
20  	 * @param fetchedKeyCount a counter that receives the number of time that the
21  	 *                        original source is asked for keys.
22  	 * @param keys            the keys to look after.
23  	 */
24  	protected GetFromSourceCommand(AtomicLong fetchedKeyCount, Collection<K> keys) {
25  		super(keys);
26  		this.fetchedKeyCount = fetchedKeyCount;
27  	}
28  
29  	@Override
30  	public final Map<K, V> call() throws Exception {
31  		if (keys != null) fetchedKeyCount.addAndGet(keys.size());
32  		return doCall();
33  	}
34  
35  	protected abstract Map<K, V> doCall() throws Exception;
36  }