Use java.util.Optional in ShardLeaderStateChanged and PrimaryShardInfo
[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 com.google.common.base.Preconditions;
11 import java.util.Optional;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.controller.cluster.notifications.LeaderStateChanged;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
15
16 /**
17  * A local message derived from LeaderStateChanged containing additional Shard-specific info that is sent
18  * when some state of the shard leader has changed. This message is used by the ShardManager to maintain
19  * current Shard information.
20  *
21  * @author Thomas Pantelis
22  */
23 public class ShardLeaderStateChanged extends LeaderStateChanged {
24
25     private final DataTree localShardDataTree;
26
27     public ShardLeaderStateChanged(@Nonnull String memberId, @Nonnull String leaderId,
28             @Nonnull DataTree localShardDataTree, short leaderPayloadVersion) {
29         super(memberId, leaderId, leaderPayloadVersion);
30         this.localShardDataTree = Preconditions.checkNotNull(localShardDataTree);
31     }
32
33     public ShardLeaderStateChanged(@Nonnull String memberId, @Nonnull String leaderId,
34             short leaderPayloadVersion) {
35         super(memberId, leaderId, leaderPayloadVersion);
36         this.localShardDataTree = null;
37     }
38
39     public @Nonnull Optional<DataTree> getLocalShardDataTree() {
40         return Optional.ofNullable(localShardDataTree);
41     }
42 }