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 akka.actor.Props;
11 import com.google.common.base.Preconditions;
12 import java.util.concurrent.CountDownLatch;
13 import org.opendaylight.controller.cluster.datastore.AbstractDataStore;
14 import org.opendaylight.controller.cluster.datastore.ClusterWrapper;
15 import org.opendaylight.controller.cluster.datastore.DatastoreContextFactory;
16 import org.opendaylight.controller.cluster.datastore.config.Configuration;
17 import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot;
18 import org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache;
20 public abstract class AbstractShardManagerCreator<T extends AbstractShardManagerCreator<T>> {
21 private ClusterWrapper cluster;
22 private Configuration configuration;
23 private DatastoreContextFactory datastoreContextFactory;
24 private AbstractDataStore distributedDataStore;
25 private CountDownLatch waitTillReadyCountDownLatch;
26 private PrimaryShardInfoFutureCache primaryShardInfoCache;
27 private DatastoreSnapshot restoreFromSnapshot;
28 private volatile boolean sealed;
30 AbstractShardManagerCreator() {
31 // Prevent outside instantiation
34 @SuppressWarnings("unchecked")
39 protected final void checkSealed() {
40 Preconditions.checkState(!sealed, "Builder is already sealed - further modifications are not allowed");
43 ClusterWrapper getCluster() {
47 public T cluster(ClusterWrapper newCluster) {
49 this.cluster = newCluster;
53 Configuration getConfiguration() {
57 public T configuration(Configuration newConfiguration) {
59 this.configuration = newConfiguration;
63 DatastoreContextFactory getDatastoreContextFactory() {
64 return datastoreContextFactory;
67 public T datastoreContextFactory(final DatastoreContextFactory newDatastoreContextFactory) {
69 this.datastoreContextFactory = Preconditions.checkNotNull(newDatastoreContextFactory);
73 AbstractDataStore getDistributedDataStore() {
74 return distributedDataStore;
77 public T distributedDataStore(final AbstractDataStore newDistributedDataStore) {
79 this.distributedDataStore = newDistributedDataStore;
83 CountDownLatch getWaitTillReadyCountDownLatch() {
84 return waitTillReadyCountDownLatch;
87 public T waitTillReadyCountDownLatch(CountDownLatch newWaitTillReadyCountDownLatch) {
89 this.waitTillReadyCountDownLatch = newWaitTillReadyCountDownLatch;
93 PrimaryShardInfoFutureCache getPrimaryShardInfoCache() {
94 return primaryShardInfoCache;
97 public T primaryShardInfoCache(PrimaryShardInfoFutureCache newPrimaryShardInfoCache) {
99 this.primaryShardInfoCache = newPrimaryShardInfoCache;
103 DatastoreSnapshot getRestoreFromSnapshot() {
104 return restoreFromSnapshot;
107 public T restoreFromSnapshot(DatastoreSnapshot newRestoreFromSnapshot) {
109 this.restoreFromSnapshot = newRestoreFromSnapshot;
113 protected void verify() {
115 Preconditions.checkNotNull(cluster, "cluster should not be null");
116 Preconditions.checkNotNull(configuration, "configuration should not be null");
117 Preconditions.checkNotNull(datastoreContextFactory, "datastoreContextFactory should not be null");
118 Preconditions.checkNotNull(distributedDataStore, "distributedDataStore should not be null");
119 Preconditions.checkNotNull(waitTillReadyCountDownLatch, "waitTillReadyCountdownLatch should not be null");
120 Preconditions.checkNotNull(primaryShardInfoCache, "primaryShardInfoCache should not be null");
123 public Props props() {
125 return Props.create(ShardManager.class, this);