2 * Copyright (c) 2015 Brocade Communications 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.config;
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableMap;
12 import java.util.Collection;
13 import java.util.HashMap;
15 import javax.annotation.Nonnull;
16 import javax.annotation.Nullable;
17 import org.opendaylight.controller.cluster.access.concepts.MemberName;
18 import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy;
21 * Encapsulates configuration for a module.
23 * @author Thomas Pantelis
25 public class ModuleConfig {
26 private final String name;
27 private final String namespace;
28 private final ShardStrategy shardStrategy;
29 private final Map<String, ShardConfig> shardConfigs;
31 private ModuleConfig(String name, String namespace, ShardStrategy shardStrategy,
32 Map<String, ShardConfig> shardConfigs) {
34 this.namespace = namespace;
35 this.shardStrategy = shardStrategy;
36 this.shardConfigs = shardConfigs;
40 public String getName() {
45 public String getNamespace() {
50 public ShardStrategy getShardStrategy() {
55 public ShardConfig getShardConfig(String forName) {
56 return shardConfigs.get(forName);
60 public Collection<ShardConfig> getShardConfigs() {
61 return shardConfigs.values();
65 public Collection<String> getShardNames() {
66 return shardConfigs.keySet();
69 public static Builder builder(String name) {
70 return new Builder(name);
73 public static Builder builder(ModuleConfig moduleConfig) {
74 return new Builder(moduleConfig);
77 public static class Builder {
79 private String nameSpace;
80 private ShardStrategy shardStrategy;
81 private final Map<String, ShardConfig> shardConfigs = new HashMap<>();
83 private Builder(String name) {
87 private Builder(ModuleConfig moduleConfig) {
88 this.name = moduleConfig.getName();
89 this.nameSpace = moduleConfig.getNamespace();
90 this.shardStrategy = moduleConfig.getShardStrategy();
91 for (ShardConfig shardConfig : moduleConfig.getShardConfigs()) {
92 shardConfigs.put(shardConfig.getName(), shardConfig);
96 public Builder name(String newName) {
101 public Builder nameSpace(String newNameSpace) {
102 this.nameSpace = newNameSpace;
106 public Builder shardStrategy(ShardStrategy newShardStrategy) {
107 this.shardStrategy = newShardStrategy;
111 public Builder shardConfig(String shardName, Collection<MemberName> replicas) {
112 shardConfigs.put(shardName, new ShardConfig(shardName, replicas));
116 public ModuleConfig build() {
117 return new ModuleConfig(Preconditions.checkNotNull(name), nameSpace, shardStrategy,
118 ImmutableMap.copyOf(shardConfigs));