Fix sonar warnings in sal-distributed-datastore
[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 javax.annotation.Nonnull;
14 import javax.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     @Nullable
27     public Future<PrimaryShardInfo> getIfPresent(@Nonnull String shardName) {
28         return primaryShardInfoCache.getIfPresent(shardName);
29     }
30
31     public void putSuccessful(@Nonnull String shardName, @Nonnull PrimaryShardInfo info) {
32         primaryShardInfoCache.put(shardName, Futures.successful(info));
33     }
34
35     public void remove(@Nonnull String shardName) {
36         primaryShardInfoCache.invalidate(shardName);
37     }
38 }