2 * Copyright (c) 2016 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
9 package org.opendaylight.controller.cluster.datastore.config;
11 import akka.cluster.ddata.ReplicatedData;
12 import com.google.common.base.Preconditions;
13 import com.google.common.collect.ImmutableSet;
14 import java.io.Serializable;
15 import java.util.Collection;
16 import java.util.HashSet;
17 import org.opendaylight.controller.cluster.access.concepts.MemberName;
18 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
21 * Configuration for prefix based shards.
23 public class PrefixShardConfiguration implements ReplicatedData, Serializable {
24 private static final long serialVersionUID = 1L;
26 private final DOMDataTreeIdentifier prefix;
27 private final String shardStrategyName;
28 private final Collection<MemberName> shardMemberNames;
30 public PrefixShardConfiguration(final DOMDataTreeIdentifier prefix,
31 final String shardStrategyName,
32 final Collection<MemberName> shardMemberNames) {
33 this.prefix = Preconditions.checkNotNull(prefix);
34 this.shardStrategyName = Preconditions.checkNotNull(shardStrategyName);
35 this.shardMemberNames = ImmutableSet.copyOf(shardMemberNames);
38 public DOMDataTreeIdentifier getPrefix() {
42 public String getShardStrategyName() {
43 return shardStrategyName;
46 public Collection<MemberName> getShardMemberNames() {
47 return shardMemberNames;
51 public String toString() {
52 return "PrefixShardConfiguration{"
54 + ", shardStrategyName='"
55 + shardStrategyName + '\''
56 + ", shardMemberNames=" + shardMemberNames
60 public String toDataMapKey() {
61 return "prefix=" + prefix;
65 public ReplicatedData merge(final ReplicatedData replicatedData) {
66 if (!(replicatedData instanceof PrefixShardConfiguration)) {
67 throw new IllegalStateException("replicatedData expected to be instance of PrefixShardConfiguration");
69 final PrefixShardConfiguration entry = (PrefixShardConfiguration) replicatedData;
70 if (!entry.getPrefix().equals(prefix)) {
71 // this should never happen since the key is the prefix
72 // if it does just return current?
75 final HashSet<MemberName> members = new HashSet<>(shardMemberNames);
76 members.addAll(entry.getShardMemberNames());
77 return new PrefixShardConfiguration(prefix, shardStrategyName, members);