Bug 4105: Add CreateShard message in ShardManager
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / CreateShard.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore.messages;
9
10 import com.google.common.base.Preconditions;
11 import java.util.Collection;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
15 import org.opendaylight.controller.cluster.datastore.ShardPropsCreator;
16
17 /**
18  * A message sent to the ShardManager to dynamically create a new shard.
19  *
20  * @author Thomas Pantelis
21  */
22 public class CreateShard {
23     private final String shardName;
24     private final Collection<String> memberNames;
25     private final ShardPropsCreator shardPropsCreator;
26     private final DatastoreContext datastoreContext;
27
28     /**
29      * Constructor.
30      *
31      * @param shardName the name of the new shard.
32      * @param memberNames the names of all the member replicas.
33      * @param shardPropsCreator used to obtain the Props for creating the shard actor instance.
34      * @param datastoreContext the DatastoreContext for the new shard. If null, the default is used.
35      */
36     public CreateShard(@Nonnull String shardName, @Nonnull Collection<String> memberNames,
37             @Nonnull ShardPropsCreator shardPropsCreator, @Nullable DatastoreContext datastoreContext) {
38         this.shardName = Preconditions.checkNotNull(shardName);
39         this.memberNames = Preconditions.checkNotNull(memberNames);
40         this.shardPropsCreator = Preconditions.checkNotNull(shardPropsCreator);
41         this.datastoreContext = datastoreContext;
42     }
43
44     @Nonnull public String getShardName() {
45         return shardName;
46     }
47
48     @Nonnull public Collection<String> getMemberNames() {
49         return memberNames;
50     }
51
52     @Nonnull public ShardPropsCreator getShardPropsCreator() {
53         return shardPropsCreator;
54     }
55
56     @Nullable public DatastoreContext getDatastoreContext() {
57         return datastoreContext;
58     }
59
60     @Override
61     public String toString() {
62         StringBuilder builder = new StringBuilder();
63         builder.append("CreateShard [shardName=").append(shardName).append(", memberNames=").append(memberNames)
64                 .append("]");
65         return builder.toString();
66     }
67 }