1 package com.trendmicro.grid.acl.ds.cache.commands;
2
3 import com.trendmicro.grid.acl.ds.cache.CacheDestination;
4 import com.trendmicro.grid.acl.ds.cache.CacheSettings;
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Map;
11
12
13
14
15
16
17
18 public class RemoveCommand<K, V> extends AbstractCommand<K, V> {
19
20 private static final Logger log = LoggerFactory.getLogger(RemoveCommand.class);
21
22 private CacheDestination<K, ?>[] cacheDestinations;
23
24
25
26
27
28
29
30 public RemoveCommand(Collection<K> keys, CacheDestination<K, ?>... cacheDestination) {
31 super(new ArrayList<K>(keys));
32
33
34 cacheDestinations = cacheDestination;
35 }
36
37
38
39
40
41
42 public BatchCommand<K, V> asBatchCommand() {
43 return new BatchCommand<K, V>(keys, this, cacheDestinations);
44 }
45
46 protected void removeKeys() {
47 for (CacheDestination<K, ?> destination : cacheDestinations)
48 destination.removeAll(keys);
49 }
50
51
52
53
54 @Override
55 public Map<K, V> call() throws Exception {
56 if (!CacheSettings.DISABLED)
57 removeKeys();
58 return keysToCallResult();
59 }
60 }