X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fshardmanager%2FShardInformation.java;h=0c892295a77888d5c635c380183db1b2fa67d10b;hb=1b24ce7d52a5acb3bb48bb6ae0724c4909220039;hp=a37a94fd0ec860cbb2de342c3f144d627b6b8cf7;hpb=0b50c6a2012206c2853e2fc7c4e50d89a1fe35ff;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardInformation.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardInformation.java index a37a94fd0e..0c892295a7 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardInformation.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardInformation.java @@ -10,15 +10,16 @@ package org.opendaylight.controller.cluster.datastore.shardmanager; import akka.actor.ActorRef; import akka.actor.Props; import akka.serialization.Serialization; -import com.google.common.base.Objects; -import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.Set; import javax.annotation.Nullable; +import org.opendaylight.controller.cluster.access.concepts.MemberName; import org.opendaylight.controller.cluster.datastore.DatastoreContext; import org.opendaylight.controller.cluster.datastore.Shard; import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; @@ -71,8 +72,8 @@ final class ShardInformation { Props newProps(SchemaContext schemaContext) { Preconditions.checkNotNull(builder); - Props props = builder.id(shardId).peerAddresses(initialPeerAddresses).datastoreContext(datastoreContext). - schemaContext(schemaContext).props(); + Props props = builder.id(shardId).peerAddresses(initialPeerAddresses).datastoreContext(datastoreContext) + .schemaContext(schemaContext).props(); builder = null; return props; } @@ -82,7 +83,7 @@ final class ShardInformation { } @Nullable - ActorRef getActor(){ + ActorRef getActor() { return actor; } @@ -114,14 +115,12 @@ final class ShardInformation { } } - void updatePeerAddress(String peerId, String peerAddress, ActorRef sender){ + void updatePeerAddress(String peerId, String peerAddress, ActorRef sender) { LOG.info("updatePeerAddress for peer {} with address {}", peerId, peerAddress); - if(actor != null) { - if(LOG.isDebugEnabled()) { - LOG.debug("Sending PeerAddressResolved for peer {} with address {} to {}", - peerId, peerAddress, actor.path()); - } + if (actor != null) { + LOG.debug("Sending PeerAddressResolved for peer {} with address {} to {}", peerId, + peerAddress, actor.path()); actor.tell(new PeerAddressResolved(peerId, peerAddress), sender); } @@ -129,14 +128,14 @@ final class ShardInformation { notifyOnShardInitializedCallbacks(); } - void peerDown(String memberName, String peerId, ActorRef sender) { - if(actor != null) { + void peerDown(MemberName memberName, String peerId, ActorRef sender) { + if (actor != null) { actor.tell(new PeerDown(memberName, peerId), sender); } } - void peerUp(String memberName, String peerId, ActorRef sender) { - if(actor != null) { + void peerUp(MemberName memberName, String peerId, ActorRef sender) { + if (actor != null) { actor.tell(new PeerUp(memberName, peerId), sender); } } @@ -146,8 +145,9 @@ final class ShardInformation { } boolean isShardReadyWithLeaderId() { - return leaderAvailable && isShardReady() && !RaftState.IsolatedLeader.name().equals(role) && - (isLeader() || addressResolver.resolve(leaderId) != null); + return leaderAvailable && isShardReady() && !RaftState.IsolatedLeader.name().equals(role) + && !RaftState.PreLeader.name().equals(role) + && (isLeader() || addressResolver.resolve(leaderId) != null); } boolean isShardInitialized() { @@ -155,11 +155,11 @@ final class ShardInformation { } boolean isLeader() { - return Objects.equal(leaderId, shardId.toString()); + return Objects.equals(leaderId, shardId.toString()); } String getSerializedLeaderActor() { - if(isLeader()) { + if (isLeader()) { return Serialization.serializedActorPath(getActor()); } else { return addressResolver.resolve(leaderId); @@ -175,7 +175,7 @@ final class ShardInformation { } private void notifyOnShardInitializedCallbacks() { - if(onShardInitializedSet.isEmpty()) { + if (onShardInitializedSet.isEmpty()) { return; } @@ -185,7 +185,7 @@ final class ShardInformation { ready ? "ready" : "initialized", onShardInitializedSet.size()); Iterator iter = onShardInitializedSet.iterator(); - while(iter.hasNext()) { + while (iter.hasNext()) { OnShardInitialized onShardInitialized = iter.next(); if (!(onShardInitialized instanceof OnShardReady) || ready) { iter.remove(); @@ -209,14 +209,18 @@ final class ShardInformation { notifyOnShardInitializedCallbacks(); } - void setFollowerSyncStatus(boolean syncStatus){ + String getRole() { + return role; + } + + void setFollowerSyncStatus(boolean syncStatus) { this.followerSyncStatus = syncStatus; } - boolean isInSync(){ - if(RaftState.Follower.name().equals(this.role)){ + boolean isInSync() { + if (RaftState.Follower.name().equals(this.role)) { return followerSyncStatus; - } else if(RaftState.Leader.name().equals(this.role)){ + } else if (RaftState.Leader.name().equals(this.role)) { return true; } @@ -224,9 +228,9 @@ final class ShardInformation { } boolean setLeaderId(String leaderId) { - boolean changed = !Objects.equal(this.leaderId, leaderId); + final boolean changed = !Objects.equals(this.leaderId, leaderId); this.leaderId = leaderId; - if(leaderId != null) { + if (leaderId != null) { this.leaderAvailable = true; } notifyOnShardInitializedCallbacks(); @@ -241,7 +245,7 @@ final class ShardInformation { void setLeaderAvailable(boolean leaderAvailable) { this.leaderAvailable = leaderAvailable; - if(leaderAvailable) { + if (leaderAvailable) { notifyOnShardInitializedCallbacks(); } } @@ -261,4 +265,4 @@ final class ShardInformation { void setActiveMember(boolean isActiveMember) { this.isActiveMember = isActiveMember; } -} \ No newline at end of file +}