Bug 3020: Use leader version in LeaderStateChanged
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / PrimaryShardInfo.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 akka.actor.ActorSelection;
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
15
16 /**
17  * Local message DTO that contains information about the primary shard.
18  *
19  * @author Thomas Pantelis
20  */
21 public class PrimaryShardInfo {
22     private final ActorSelection primaryShardActor;
23     private final short primaryShardVersion;
24     private final Optional<DataTree> localShardDataTree;
25
26     public PrimaryShardInfo(@Nonnull ActorSelection primaryShardActor, short primaryShardVersion,
27             @Nonnull Optional<DataTree> localShardDataTree) {
28         this.primaryShardActor = Preconditions.checkNotNull(primaryShardActor);
29         this.primaryShardVersion = primaryShardVersion;
30         this.localShardDataTree = Preconditions.checkNotNull(localShardDataTree);
31     }
32
33     /**
34      * Returns an ActorSelection representing the primary shard actor.
35      */
36     public @Nonnull ActorSelection getPrimaryShardActor() {
37         return primaryShardActor;
38     }
39
40     /**
41      * Returns the version of the primary shard.
42      */
43     public short getPrimaryShardVersion() {
44         return primaryShardVersion;
45     }
46
47     /**
48      * Returns an Optional whose value contains the primary shard's DataTree if the primary shard is local
49      * to the caller. Otherwise the Optional value is absent.
50      */
51     public @Nonnull Optional<DataTree> getLocalShardDataTree() {
52         return localShardDataTree;
53     }
54 }