1ca06216dd1157a54727ae67c8c8124d2fc0bafa
[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 static java.util.Objects.requireNonNull;
11
12 import akka.actor.ActorSelection;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.ReadOnlyDataTree;
16
17 /**
18  * Local message DTO that contains information about the primary shard.
19  *
20  * @author Thomas Pantelis
21  */
22 public class PrimaryShardInfo {
23     private final ActorSelection primaryShardActor;
24     private final short primaryShardVersion;
25     private final ReadOnlyDataTree localShardDataTree;
26
27     public PrimaryShardInfo(@NonNull ActorSelection primaryShardActor, short primaryShardVersion,
28             @NonNull ReadOnlyDataTree localShardDataTree) {
29         this.primaryShardActor = requireNonNull(primaryShardActor);
30         this.primaryShardVersion = primaryShardVersion;
31         this.localShardDataTree = requireNonNull(localShardDataTree);
32     }
33
34     public PrimaryShardInfo(@NonNull ActorSelection primaryShardActor, short primaryShardVersion) {
35         this.primaryShardActor = requireNonNull(primaryShardActor);
36         this.primaryShardVersion = primaryShardVersion;
37         this.localShardDataTree = null;
38     }
39
40     /**
41      * Returns an ActorSelection representing the primary shard actor.
42      */
43     public @NonNull ActorSelection getPrimaryShardActor() {
44         return primaryShardActor;
45     }
46
47     /**
48      * Returns the version of the primary shard.
49      */
50     public short getPrimaryShardVersion() {
51         return primaryShardVersion;
52     }
53
54     /**
55      * Returns an Optional whose value contains the primary shard's DataTree if the primary shard is local
56      * to the caller. Otherwise the Optional value is absent.
57      */
58     public @NonNull Optional<ReadOnlyDataTree> getLocalShardDataTree() {
59         return Optional.ofNullable(localShardDataTree);
60     }
61 }