2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore.utils;
10 import akka.dispatch.Futures;
11 import com.google.common.cache.Cache;
12 import com.google.common.cache.CacheBuilder;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
16 import scala.concurrent.Future;
19 * Maintains a cache of PrimaryShardInfo Future instances per shard.
21 * @author Thomas Pantelis
23 public class PrimaryShardInfoFutureCache {
24 private final Cache<String, Future<PrimaryShardInfo>> primaryShardInfoCache = CacheBuilder.newBuilder().build();
26 public @Nullable Future<PrimaryShardInfo> getIfPresent(@NonNull String shardName) {
27 return primaryShardInfoCache.getIfPresent(shardName);
30 public void putSuccessful(@NonNull String shardName, @NonNull PrimaryShardInfo info) {
31 primaryShardInfoCache.put(shardName, Futures.successful(info));
34 public void remove(@NonNull String shardName) {
35 primaryShardInfoCache.invalidate(shardName);