2 * Copyright (c) 2014 Cisco 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.shardmanager;
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
13 import akka.actor.Props;
14 import com.google.common.util.concurrent.SettableFuture;
15 import org.opendaylight.controller.cluster.datastore.AbstractDataStore;
16 import org.opendaylight.controller.cluster.datastore.ClusterWrapper;
17 import org.opendaylight.controller.cluster.datastore.DatastoreContextFactory;
18 import org.opendaylight.controller.cluster.datastore.config.Configuration;
19 import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot;
20 import org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache;
21 import org.opendaylight.yangtools.yang.common.Empty;
23 public abstract class AbstractShardManagerCreator<T extends AbstractShardManagerCreator<T>> {
24 private SettableFuture<Empty> readinessFuture;
25 private ClusterWrapper cluster;
26 private Configuration configuration;
27 private DatastoreContextFactory datastoreContextFactory;
28 private AbstractDataStore distributedDataStore;
29 private PrimaryShardInfoFutureCache primaryShardInfoCache;
30 private DatastoreSnapshot restoreFromSnapshot;
31 private volatile boolean sealed;
33 AbstractShardManagerCreator() {
34 // Prevent outside instantiation
37 @SuppressWarnings("unchecked")
42 protected final void checkSealed() {
43 checkState(!sealed, "Builder is already sealed - further modifications are not allowed");
46 ClusterWrapper getCluster() {
50 public T cluster(final ClusterWrapper newCluster) {
52 this.cluster = newCluster;
56 Configuration getConfiguration() {
60 public T configuration(final Configuration newConfiguration) {
62 this.configuration = newConfiguration;
66 DatastoreContextFactory getDatastoreContextFactory() {
67 return datastoreContextFactory;
70 public T datastoreContextFactory(final DatastoreContextFactory newDatastoreContextFactory) {
72 this.datastoreContextFactory = requireNonNull(newDatastoreContextFactory);
76 AbstractDataStore getDistributedDataStore() {
77 return distributedDataStore;
80 public T distributedDataStore(final AbstractDataStore newDistributedDataStore) {
82 this.distributedDataStore = newDistributedDataStore;
86 SettableFuture<Empty> getReadinessFuture() {
87 return readinessFuture;
90 public T readinessFuture(final SettableFuture<Empty> newReadinessFuture) {
92 this.readinessFuture = newReadinessFuture;
96 PrimaryShardInfoFutureCache getPrimaryShardInfoCache() {
97 return primaryShardInfoCache;
100 public T primaryShardInfoCache(final PrimaryShardInfoFutureCache newPrimaryShardInfoCache) {
102 this.primaryShardInfoCache = newPrimaryShardInfoCache;
106 DatastoreSnapshot getRestoreFromSnapshot() {
107 return restoreFromSnapshot;
110 public T restoreFromSnapshot(final DatastoreSnapshot newRestoreFromSnapshot) {
112 this.restoreFromSnapshot = newRestoreFromSnapshot;
116 protected void verify() {
118 requireNonNull(cluster, "cluster should not be null");
119 requireNonNull(configuration, "configuration should not be null");
120 requireNonNull(datastoreContextFactory, "datastoreContextFactory should not be null");
121 requireNonNull(distributedDataStore, "distributedDataStore should not be null");
122 requireNonNull(readinessFuture, "readinessFuture should not be null");
123 requireNonNull(primaryShardInfoCache, "primaryShardInfoCache should not be null");
126 public Props props() {
128 return Props.create(ShardManager.class, this);