Add UnsignedLongRangeSet.toString()
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / PrimaryShardInfoFutureCache.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore.utils;
9
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;
17
18 /**
19  * Maintains a cache of PrimaryShardInfo Future instances per shard.
20  *
21  * @author Thomas Pantelis
22  */
23 public class PrimaryShardInfoFutureCache {
24     private final Cache<String, Future<PrimaryShardInfo>> primaryShardInfoCache = CacheBuilder.newBuilder().build();
25
26     public @Nullable Future<PrimaryShardInfo> getIfPresent(@NonNull String shardName) {
27         return primaryShardInfoCache.getIfPresent(shardName);
28     }
29
30     public void putSuccessful(@NonNull String shardName, @NonNull PrimaryShardInfo info) {
31         primaryShardInfoCache.put(shardName, Futures.successful(info));
32     }
33
34     public void remove(@NonNull String shardName) {
35         primaryShardInfoCache.invalidate(shardName);
36     }
37 }