679d421eaf4d9e04f03b002fc7f4af2f6304a7c3
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / ShardLeaderStateChanged.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 java.util.Optional;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.controller.cluster.notifications.LeaderStateChanged;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
17
18 /**
19  * A local message derived from LeaderStateChanged containing additional Shard-specific info that is sent
20  * when some state of the shard leader has changed. This message is used by the ShardManager to maintain
21  * current Shard information.
22  *
23  * @author Thomas Pantelis
24  */
25 public class ShardLeaderStateChanged extends LeaderStateChanged {
26
27     private final DataTree localShardDataTree;
28
29     public ShardLeaderStateChanged(@NonNull String memberId, @Nullable String leaderId,
30             @NonNull DataTree localShardDataTree, short leaderPayloadVersion) {
31         super(memberId, leaderId, leaderPayloadVersion);
32         this.localShardDataTree = requireNonNull(localShardDataTree);
33     }
34
35     public ShardLeaderStateChanged(@NonNull String memberId, @Nullable String leaderId,
36             short leaderPayloadVersion) {
37         super(memberId, leaderId, leaderPayloadVersion);
38         this.localShardDataTree = null;
39     }
40
41     public @NonNull Optional<DataTree> getLocalShardDataTree() {
42         return Optional.ofNullable(localShardDataTree);
43     }
44 }