2 * Copyright (c) 2015 Brocade Communications 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
8 package org.opendaylight.controller.cluster.datastore.messages;
10 import static java.util.Objects.requireNonNull;
12 import akka.actor.ActorSelection;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.data.tree.api.ReadOnlyDataTree;
18 * Local message DTO that contains information about the primary shard.
20 * @author Thomas Pantelis
22 public class PrimaryShardInfo {
23 private final ActorSelection primaryShardActor;
24 private final short primaryShardVersion;
25 private final ReadOnlyDataTree localShardDataTree;
27 public PrimaryShardInfo(final @NonNull ActorSelection primaryShardActor, final short primaryShardVersion,
28 final @NonNull ReadOnlyDataTree localShardDataTree) {
29 this.primaryShardActor = requireNonNull(primaryShardActor);
30 this.primaryShardVersion = primaryShardVersion;
31 this.localShardDataTree = requireNonNull(localShardDataTree);
34 public PrimaryShardInfo(final @NonNull ActorSelection primaryShardActor, final short primaryShardVersion) {
35 this.primaryShardActor = requireNonNull(primaryShardActor);
36 this.primaryShardVersion = primaryShardVersion;
37 localShardDataTree = null;
41 * Returns an ActorSelection representing the primary shard actor.
43 public @NonNull ActorSelection getPrimaryShardActor() {
44 return primaryShardActor;
48 * Returns the version of the primary shard.
50 public short getPrimaryShardVersion() {
51 return primaryShardVersion;
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.
58 public @NonNull Optional<ReadOnlyDataTree> getLocalShardDataTree() {
59 return Optional.ofNullable(localShardDataTree);