Merge "Fixed for bug 1197"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / FindPrimary.java
1 /*
2  * Copyright (c) 2014 Cisco 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
9 package org.opendaylight.controller.cluster.datastore.messages;
10
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.protobuff.messages.shard.ShardManagerMessages;
13
14 /**
15  * The FindPrimary message is used to locate the primary of any given shard
16  *
17  */
18 public class FindPrimary implements SerializableMessage{
19   public static final Class SERIALIZABLE_CLASS = ShardManagerMessages.FindPrimary.class;
20     private final String shardName;
21
22     public FindPrimary(String shardName){
23
24         Preconditions.checkNotNull(shardName, "shardName should not be null");
25
26         this.shardName = shardName;
27     }
28
29     public String getShardName() {
30         return shardName;
31     }
32
33   @Override
34   public Object toSerializable() {
35     return ShardManagerMessages.FindPrimary.newBuilder().setShardName(shardName).build();
36   }
37
38   public static FindPrimary fromSerializable(Object message){
39     return new FindPrimary(((ShardManagerMessages.FindPrimary)message).getShardName());
40   }
41 }