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 java.util.concurrent.CountDownLatch;
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;
22 public abstract class AbstractShardManagerCreator<T extends AbstractShardManagerCreator<T>> {
23 private ClusterWrapper cluster;
24 private Configuration configuration;
25 private DatastoreContextFactory datastoreContextFactory;
26 private AbstractDataStore distributedDataStore;
27 private CountDownLatch waitTillReadyCountDownLatch;
28 private PrimaryShardInfoFutureCache primaryShardInfoCache;
29 private DatastoreSnapshot restoreFromSnapshot;
30 private volatile boolean sealed;
32 AbstractShardManagerCreator() {
33 // Prevent outside instantiation
36 @SuppressWarnings("unchecked")
41 protected final void checkSealed() {
42 checkState(!sealed, "Builder is already sealed - further modifications are not allowed");
45 ClusterWrapper getCluster() {
49 public T cluster(final ClusterWrapper newCluster) {
51 this.cluster = newCluster;
55 Configuration getConfiguration() {
59 public T configuration(final Configuration newConfiguration) {
61 this.configuration = newConfiguration;
65 DatastoreContextFactory getDatastoreContextFactory() {
66 return datastoreContextFactory;
69 public T datastoreContextFactory(final DatastoreContextFactory newDatastoreContextFactory) {
71 this.datastoreContextFactory = requireNonNull(newDatastoreContextFactory);
75 AbstractDataStore getDistributedDataStore() {
76 return distributedDataStore;
79 public T distributedDataStore(final AbstractDataStore newDistributedDataStore) {
81 this.distributedDataStore = newDistributedDataStore;
85 CountDownLatch getWaitTillReadyCountDownLatch() {
86 return waitTillReadyCountDownLatch;
89 public T waitTillReadyCountDownLatch(final CountDownLatch newWaitTillReadyCountDownLatch) {
91 this.waitTillReadyCountDownLatch = newWaitTillReadyCountDownLatch;
95 PrimaryShardInfoFutureCache getPrimaryShardInfoCache() {
96 return primaryShardInfoCache;
99 public T primaryShardInfoCache(final PrimaryShardInfoFutureCache newPrimaryShardInfoCache) {
101 this.primaryShardInfoCache = newPrimaryShardInfoCache;
105 DatastoreSnapshot getRestoreFromSnapshot() {
106 return restoreFromSnapshot;
109 public T restoreFromSnapshot(final DatastoreSnapshot newRestoreFromSnapshot) {
111 this.restoreFromSnapshot = newRestoreFromSnapshot;
115 protected void verify() {
117 requireNonNull(cluster, "cluster should not be null");
118 requireNonNull(configuration, "configuration should not be null");
119 requireNonNull(datastoreContextFactory, "datastoreContextFactory should not be null");
120 requireNonNull(distributedDataStore, "distributedDataStore should not be null");
121 requireNonNull(waitTillReadyCountDownLatch, "waitTillReadyCountdownLatch should not be null");
122 requireNonNull(primaryShardInfoCache, "primaryShardInfoCache should not be null");
125 public Props props() {
127 return Props.create(ShardManager.class, this);