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.ClusterWrapper;
14 import org.opendaylight.controller.cluster.datastore.DatastoreContextFactory;
15 import org.opendaylight.controller.cluster.datastore.config.Configuration;
16 import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot;
17 import org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache;
19 public abstract class AbstractShardManagerCreator<T extends AbstractShardManagerCreator<T>> {
20 private ClusterWrapper cluster;
21 private Configuration configuration;
22 private DatastoreContextFactory datastoreContextFactory;
23 private CountDownLatch waitTillReadyCountDownLatch;
24 private PrimaryShardInfoFutureCache primaryShardInfoCache;
25 private DatastoreSnapshot restoreFromSnapshot;
26 private volatile boolean sealed;
28 AbstractShardManagerCreator() {
29 // Prevent outside instantiation
32 @SuppressWarnings("unchecked")
37 protected final void checkSealed() {
38 Preconditions.checkState(!sealed, "Builder is already sealed - further modifications are not allowed");
41 ClusterWrapper getCluster() {
45 public T cluster(ClusterWrapper newCluster) {
47 this.cluster = newCluster;
51 Configuration getConfiguration() {
55 public T configuration(Configuration newConfiguration) {
57 this.configuration = newConfiguration;
61 DatastoreContextFactory getDatastoreContextFactory() {
62 return datastoreContextFactory;
65 public T datastoreContextFactory(DatastoreContextFactory newDatastoreContextFactory) {
67 this.datastoreContextFactory = newDatastoreContextFactory;
71 CountDownLatch getWaitTillReadyCountDownLatch() {
72 return waitTillReadyCountDownLatch;
75 public T waitTillReadyCountDownLatch(CountDownLatch newWaitTillReadyCountDownLatch) {
77 this.waitTillReadyCountDownLatch = newWaitTillReadyCountDownLatch;
81 PrimaryShardInfoFutureCache getPrimaryShardInfoCache() {
82 return primaryShardInfoCache;
85 public T primaryShardInfoCache(PrimaryShardInfoFutureCache newPrimaryShardInfoCache) {
87 this.primaryShardInfoCache = newPrimaryShardInfoCache;
91 DatastoreSnapshot getRestoreFromSnapshot() {
92 return restoreFromSnapshot;
95 public T restoreFromSnapshot(DatastoreSnapshot newRestoreFromSnapshot) {
97 this.restoreFromSnapshot = newRestoreFromSnapshot;
101 protected void verify() {
103 Preconditions.checkNotNull(cluster, "cluster should not be null");
104 Preconditions.checkNotNull(configuration, "configuration should not be null");
105 Preconditions.checkNotNull(datastoreContextFactory, "datastoreContextFactory should not be null");
106 Preconditions.checkNotNull(waitTillReadyCountDownLatch, "waitTillReadyCountdownLatch should not be null");
107 Preconditions.checkNotNull(primaryShardInfoCache, "primaryShardInfoCache should not be null");
110 public Props props() {
112 return Props.create(ShardManager.class, this);