blob: 3706b4bb89d81bc2a755c8e3114fcbb750f2b71d [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Thomas Vachuskac97aa612015-06-23 16:00:18 -070016package org.onosproject.store.trivial;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070017
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080018import com.google.common.cache.Cache;
19import com.google.common.cache.CacheBuilder;
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -080020import com.google.common.cache.RemovalListener;
21import com.google.common.cache.RemovalNotification;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070022import com.google.common.collect.FluentIterable;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070023import com.google.common.collect.ImmutableList;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080024import com.google.common.collect.Sets;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080025import com.google.common.util.concurrent.SettableFuture;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070026
tom85c612b2014-09-19 19:25:47 -070027import org.apache.felix.scr.annotations.Activate;
28import org.apache.felix.scr.annotations.Component;
29import org.apache.felix.scr.annotations.Deactivate;
sangyun-hanc1806862016-04-05 11:42:03 +090030import org.apache.felix.scr.annotations.Modified;
31import org.apache.felix.scr.annotations.Property;
tom85c612b2014-09-19 19:25:47 -070032import org.apache.felix.scr.annotations.Service;
sangyun-hanc1806862016-04-05 11:42:03 +090033import org.onlab.util.Tools;
Brian O'Connorabafb502014-12-02 22:26:20 -080034import org.onosproject.net.DeviceId;
35import org.onosproject.net.flow.CompletedBatchOperation;
36import org.onosproject.net.flow.DefaultFlowEntry;
37import org.onosproject.net.flow.FlowEntry;
38import org.onosproject.net.flow.FlowEntry.FlowEntryState;
39import org.onosproject.net.flow.FlowId;
40import org.onosproject.net.flow.FlowRule;
41import org.onosproject.net.flow.FlowRuleBatchEntry;
42import org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
43import org.onosproject.net.flow.FlowRuleBatchEvent;
44import org.onosproject.net.flow.FlowRuleBatchOperation;
45import org.onosproject.net.flow.FlowRuleBatchRequest;
46import org.onosproject.net.flow.FlowRuleEvent;
47import org.onosproject.net.flow.FlowRuleEvent.Type;
48import org.onosproject.net.flow.FlowRuleStore;
49import org.onosproject.net.flow.FlowRuleStoreDelegate;
50import org.onosproject.net.flow.StoredFlowEntry;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070051import org.onosproject.net.flow.TableStatisticsEntry;
Brian O'Connorabafb502014-12-02 22:26:20 -080052import org.onosproject.store.AbstractStore;
sangyun-hanc1806862016-04-05 11:42:03 +090053import org.osgi.service.component.ComponentContext;
tom85c612b2014-09-19 19:25:47 -070054import org.slf4j.Logger;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070055
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080056import java.util.ArrayList;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070057import java.util.Collections;
sangyun-hanc1806862016-04-05 11:42:03 +090058import java.util.Dictionary;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070059import java.util.List;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070060import java.util.concurrent.ConcurrentHashMap;
61import java.util.concurrent.ConcurrentMap;
62import java.util.concurrent.CopyOnWriteArrayList;
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -080063import java.util.concurrent.ExecutionException;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080064import java.util.concurrent.TimeUnit;
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -080065import java.util.concurrent.TimeoutException;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080066import java.util.concurrent.atomic.AtomicInteger;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070067
Brian O'Connorabafb502014-12-02 22:26:20 -080068import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
Thomas Vachuska8ac922d2014-10-23 16:17:03 -070069import static org.slf4j.LoggerFactory.getLogger;
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -070070
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070071/**
72 * Manages inventory of flow rules using trivial in-memory implementation.
73 */
tom85c612b2014-09-19 19:25:47 -070074@Component(immediate = true)
75@Service
tomc78acee2014-09-24 15:16:55 -070076public class SimpleFlowRuleStore
Madan Jampani117aaae2014-10-23 10:04:05 -070077 extends AbstractStore<FlowRuleBatchEvent, FlowRuleStoreDelegate>
tomc78acee2014-09-24 15:16:55 -070078 implements FlowRuleStore {
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070079
tom85c612b2014-09-19 19:25:47 -070080 private final Logger log = getLogger(getClass());
81
alshabiba68eb962014-09-24 20:34:13 -070082
Yuta HIGUCHI605347c2014-10-17 21:05:23 -070083 // inner Map is Device flow table
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -070084 // inner Map value (FlowId synonym list) must be synchronized before modifying
85 private final ConcurrentMap<DeviceId, ConcurrentMap<FlowId, List<StoredFlowEntry>>>
Yuta HIGUCHI605347c2014-10-17 21:05:23 -070086 flowEntries = new ConcurrentHashMap<>();
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -070087
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070088 private final ConcurrentMap<DeviceId, List<TableStatisticsEntry>>
89 deviceTableStats = new ConcurrentHashMap<>();
90
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080091 private final AtomicInteger localBatchIdGen = new AtomicInteger();
92
sangyun-hanc1806862016-04-05 11:42:03 +090093 private static final int DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES = 5;
94 @Property(name = "pendingFutureTimeoutMinutes", intValue = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES,
95 label = "Expiration time after an entry is created that it should be automatically removed")
96 private int pendingFutureTimeoutMinutes = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080097
98 private Cache<Integer, SettableFuture<CompletedBatchOperation>> pendingFutures =
99 CacheBuilder.newBuilder()
100 .expireAfterWrite(pendingFutureTimeoutMinutes, TimeUnit.MINUTES)
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -0800101 .removalListener(new TimeoutFuture())
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800102 .build();
103
tom85c612b2014-09-19 19:25:47 -0700104 @Activate
105 public void activate() {
106 log.info("Started");
107 }
108
109 @Deactivate
110 public void deactivate() {
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700111 deviceTableStats.clear();
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700112 flowEntries.clear();
tom85c612b2014-09-19 19:25:47 -0700113 log.info("Stopped");
114 }
115
sangyun-hanc1806862016-04-05 11:42:03 +0900116 @Modified
117 public void modified(ComponentContext context) {
118
119 readComponentConfiguration(context);
120
121 // Reset Cache and copy all.
122 Cache<Integer, SettableFuture<CompletedBatchOperation>> prevFutures = pendingFutures;
123 pendingFutures = CacheBuilder.newBuilder()
124 .expireAfterWrite(pendingFutureTimeoutMinutes, TimeUnit.MINUTES)
125 .removalListener(new TimeoutFuture())
126 .build();
127
128 pendingFutures.putAll(prevFutures.asMap());
129 }
130
alshabiba68eb962014-09-24 20:34:13 -0700131
tombe988312014-09-19 18:38:47 -0700132 @Override
tom9b4030d2014-10-06 10:39:03 -0700133 public int getFlowRuleCount() {
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700134 int sum = 0;
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700135 for (ConcurrentMap<FlowId, List<StoredFlowEntry>> ft : flowEntries.values()) {
136 for (List<StoredFlowEntry> fes : ft.values()) {
137 sum += fes.size();
138 }
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700139 }
140 return sum;
141 }
142
sangyun-hanc1806862016-04-05 11:42:03 +0900143 /**
144 * Extracts properties from the component configuration context.
145 *
146 * @param context the component context
147 */
148 private void readComponentConfiguration(ComponentContext context) {
149 Dictionary<?, ?> properties = context.getProperties();
150
151 Integer newPendingFutureTimeoutMinutes =
152 Tools.getIntegerProperty(properties, "pendingFutureTimeoutMinutes");
153 if (newPendingFutureTimeoutMinutes == null) {
154 pendingFutureTimeoutMinutes = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES;
155 log.info("Pending future timeout is not configured, " +
156 "using current value of {}", pendingFutureTimeoutMinutes);
157 } else {
158 pendingFutureTimeoutMinutes = newPendingFutureTimeoutMinutes;
159 log.info("Configured. Pending future timeout is configured to {}",
160 pendingFutureTimeoutMinutes);
161 }
162 }
163
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700164 /**
165 * Returns the flow table for specified device.
166 *
167 * @param deviceId identifier of the device
168 * @return Map representing Flow Table of given device.
169 */
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700170 private ConcurrentMap<FlowId, List<StoredFlowEntry>> getFlowTable(DeviceId deviceId) {
Yuta HIGUCHIc2e68152016-08-16 13:47:36 -0700171 return flowEntries.computeIfAbsent(deviceId, k -> new ConcurrentHashMap<>());
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700172 }
173
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700174 private List<StoredFlowEntry> getFlowEntries(DeviceId deviceId, FlowId flowId) {
175 final ConcurrentMap<FlowId, List<StoredFlowEntry>> flowTable = getFlowTable(deviceId);
176 List<StoredFlowEntry> r = flowTable.get(flowId);
177 if (r == null) {
178 final List<StoredFlowEntry> concurrentlyAdded;
179 r = new CopyOnWriteArrayList<>();
180 concurrentlyAdded = flowTable.putIfAbsent(flowId, r);
181 if (concurrentlyAdded != null) {
182 return concurrentlyAdded;
183 }
184 }
185 return r;
186 }
187
188 private FlowEntry getFlowEntryInternal(DeviceId deviceId, FlowRule rule) {
189 List<StoredFlowEntry> fes = getFlowEntries(deviceId, rule.id());
190 for (StoredFlowEntry fe : fes) {
191 if (fe.equals(rule)) {
192 return fe;
193 }
194 }
195 return null;
tom9b4030d2014-10-06 10:39:03 -0700196 }
197
198 @Override
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700199 public FlowEntry getFlowEntry(FlowRule rule) {
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700200 return getFlowEntryInternal(rule.deviceId(), rule);
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700201 }
202
203 @Override
204 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700205 // flatten and make iterator unmodifiable
206 return FluentIterable.from(getFlowTable(deviceId).values())
Sho SHIMIZU74626412015-09-11 11:46:27 -0700207 .transformAndConcat(Collections::unmodifiableList);
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700208 }
209
210 @Override
Madan Jampani117aaae2014-10-23 10:04:05 -0700211 public void storeFlowRule(FlowRule rule) {
212 storeFlowRuleInternal(rule);
alshabib219ebaa2014-09-22 15:41:24 -0700213 }
214
Madan Jampani117aaae2014-10-23 10:04:05 -0700215 private void storeFlowRuleInternal(FlowRule rule) {
Yuta HIGUCHIf6f50a62014-10-19 15:58:49 -0700216 StoredFlowEntry f = new DefaultFlowEntry(rule);
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700217 final DeviceId did = f.deviceId();
218 final FlowId fid = f.id();
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700219 List<StoredFlowEntry> existing = getFlowEntries(did, fid);
220 synchronized (existing) {
221 for (StoredFlowEntry fe : existing) {
222 if (fe.equals(rule)) {
223 // was already there? ignore
Madan Jampani117aaae2014-10-23 10:04:05 -0700224 return;
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700225 }
226 }
227 // new flow rule added
228 existing.add(f);
alshabiba68eb962014-09-24 20:34:13 -0700229 }
230 }
231
232 @Override
Madan Jampani117aaae2014-10-23 10:04:05 -0700233 public void deleteFlowRule(FlowRule rule) {
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700234
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700235 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
alshabib2374fc92014-10-22 11:03:23 -0700236
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700237 synchronized (entries) {
238 for (StoredFlowEntry entry : entries) {
239 if (entry.equals(rule)) {
240 synchronized (entry) {
241 entry.setState(FlowEntryState.PENDING_REMOVE);
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700242 }
243 }
244 }
alshabib219ebaa2014-09-22 15:41:24 -0700245 }
Madan Jampani31961c12014-10-23 12:06:58 -0700246
247
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700248 //log.warn("Cannot find rule {}", rule);
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700249 }
250
tombe988312014-09-19 18:38:47 -0700251 @Override
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700252 public FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) {
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700253 // check if this new rule is an update to an existing entry
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700254 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
255 synchronized (entries) {
256 for (StoredFlowEntry stored : entries) {
257 if (stored.equals(rule)) {
258 synchronized (stored) {
Brian O'Connora3e5cd52015-12-05 15:59:19 -0800259 //FIXME modification of "stored" flow entry outside of flow table
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700260 stored.setBytes(rule.bytes());
261 stored.setLife(rule.life());
262 stored.setPackets(rule.packets());
263 if (stored.state() == FlowEntryState.PENDING_ADD) {
264 stored.setState(FlowEntryState.ADDED);
265 // TODO: Do we need to change `rule` state?
266 return new FlowRuleEvent(Type.RULE_ADDED, rule);
267 }
268 return new FlowRuleEvent(Type.RULE_UPDATED, rule);
269 }
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700270 }
alshabibba5ac482014-10-02 17:15:20 -0700271 }
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700272 }
alshabib219ebaa2014-09-22 15:41:24 -0700273
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700274 // should not reach here
275 // storeFlowRule was expected to be called
276 log.error("FlowRule was not found in store {} to update", rule);
277
alshabib8ca53902014-10-07 13:11:17 -0700278 //flowEntries.put(did, rule);
alshabibba5ac482014-10-02 17:15:20 -0700279 return null;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700280 }
281
tombe988312014-09-19 18:38:47 -0700282 @Override
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700283 public FlowRuleEvent removeFlowRule(FlowEntry rule) {
alshabib1c319ff2014-10-04 20:29:09 -0700284 // This is where one could mark a rule as removed and still keep it in the store.
Yuta HIGUCHI605347c2014-10-17 21:05:23 -0700285 final DeviceId did = rule.deviceId();
286
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700287 List<StoredFlowEntry> entries = getFlowEntries(did, rule.id());
288 synchronized (entries) {
289 if (entries.remove(rule)) {
290 return new FlowRuleEvent(RULE_REMOVED, rule);
291 }
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700292 }
Yuta HIGUCHI94ffdd42014-10-20 16:36:52 -0700293 return null;
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700294 }
Madan Jampani117aaae2014-10-23 10:04:05 -0700295
296 @Override
Charles Chan93fa7272016-01-26 22:27:02 -0800297 public FlowRuleEvent pendingFlowRule(FlowEntry rule) {
298 List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
299 synchronized (entries) {
300 for (StoredFlowEntry entry : entries) {
301 if (entry.equals(rule) &&
302 entry.state() != FlowEntryState.PENDING_ADD) {
303 synchronized (entry) {
304 entry.setState(FlowEntryState.PENDING_ADD);
305 return new FlowRuleEvent(Type.RULE_UPDATED, rule);
306 }
307 }
308 }
309 }
310 return null;
311 }
312
Yuta HIGUCHIc2e68152016-08-16 13:47:36 -0700313 @Override
Charles Chan0c7c43b2016-01-14 17:39:20 -0800314 public void purgeFlowRule(DeviceId deviceId) {
315 flowEntries.remove(deviceId);
316 }
317
Charles Chan93fa7272016-01-26 22:27:02 -0800318 @Override
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800319 public void storeBatch(
320 FlowRuleBatchOperation operation) {
Brian O'Connor427a1762014-11-19 18:40:32 -0800321 List<FlowRuleBatchEntry> toAdd = new ArrayList<>();
322 List<FlowRuleBatchEntry> toRemove = new ArrayList<>();
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800323
324 for (FlowRuleBatchEntry entry : operation.getOperations()) {
Ray Milkeyf7329c72015-02-17 11:37:01 -0800325 final FlowRule flowRule = entry.target();
326 if (entry.operator().equals(FlowRuleOperation.ADD)) {
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800327 if (!getFlowEntries(flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
328 storeFlowRule(flowRule);
Brian O'Connor427a1762014-11-19 18:40:32 -0800329 toAdd.add(entry);
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800330 }
Sho SHIMIZUaba9d002015-01-29 14:51:04 -0800331 } else if (entry.operator().equals(FlowRuleOperation.REMOVE)) {
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800332 if (getFlowEntries(flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
333 deleteFlowRule(flowRule);
Brian O'Connor427a1762014-11-19 18:40:32 -0800334 toRemove.add(entry);
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800335 }
Madan Jampani117aaae2014-10-23 10:04:05 -0700336 } else {
337 throw new UnsupportedOperationException("Unsupported operation type");
338 }
339 }
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800340
341 if (toAdd.isEmpty() && toRemove.isEmpty()) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800342 notifyDelegate(FlowRuleBatchEvent.completed(
343 new FlowRuleBatchRequest(operation.id(), Collections.emptySet()),
344 new CompletedBatchOperation(true, Collections.emptySet(),
345 operation.deviceId())));
346 return;
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800347 }
348
349 SettableFuture<CompletedBatchOperation> r = SettableFuture.create();
350 final int batchId = localBatchIdGen.incrementAndGet();
351
352 pendingFutures.put(batchId, r);
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800353
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800354 toAdd.addAll(toRemove);
355 notifyDelegate(FlowRuleBatchEvent.requested(
356 new FlowRuleBatchRequest(batchId, Sets.newHashSet(toAdd)), operation.deviceId()));
357
Madan Jampani117aaae2014-10-23 10:04:05 -0700358 }
359
360 @Override
361 public void batchOperationComplete(FlowRuleBatchEvent event) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800362 final Long batchId = event.subject().batchId();
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -0800363 SettableFuture<CompletedBatchOperation> future
364 = pendingFutures.getIfPresent(batchId);
365 if (future != null) {
366 future.set(event.result());
367 pendingFutures.invalidate(batchId);
368 }
Madan Jampani117aaae2014-10-23 10:04:05 -0700369 notifyDelegate(event);
370 }
Yuta HIGUCHIf1ccee82014-11-11 20:39:58 -0800371
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700372 @Override
373 public FlowRuleEvent updateTableStatistics(DeviceId deviceId,
374 List<TableStatisticsEntry> tableStats) {
375 deviceTableStats.put(deviceId, tableStats);
376 return null;
377 }
378
379 @Override
380 public Iterable<TableStatisticsEntry> getTableStatistics(DeviceId deviceId) {
381 List<TableStatisticsEntry> tableStats = deviceTableStats.get(deviceId);
382 if (tableStats == null) {
383 return Collections.emptyList();
384 }
385 return ImmutableList.copyOf(tableStats);
386 }
sangyun-hanc1806862016-04-05 11:42:03 +0900387
388 private static final class TimeoutFuture
389 implements RemovalListener<Integer, SettableFuture<CompletedBatchOperation>> {
390 @Override
391 public void onRemoval(RemovalNotification<Integer, SettableFuture<CompletedBatchOperation>> notification) {
392 // wrapping in ExecutionException to support Future.get
393 if (notification.wasEvicted()) {
394 notification.getValue()
395 .setException(new ExecutionException("Timed out",
396 new TimeoutException()));
397 }
398 }
399 }
Ayaka Koshibe08eabaa2014-09-17 14:59:25 -0700400}