X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShard.java;h=f634aecc6285fbbe925f89044df2c326ced9ea10;hp=ba18ac23e7237092654e2a060ab34cd56c3fd768;hb=3859df9beca8f13f1ff2b2744ed3470a1715bec3;hpb=8182b2647acc326e66da9f66fbe69e16435567d6 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java index ba18ac23e7..f634aecc62 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java @@ -7,7 +7,9 @@ */ package org.opendaylight.controller.cluster.datastore; +import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Verify.verify; +import static java.util.Objects.requireNonNull; import akka.actor.ActorRef; import akka.actor.ActorSelection; @@ -19,8 +21,6 @@ import akka.actor.Status.Failure; import akka.serialization.JavaSerializer; import akka.serialization.Serialization; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; import com.google.common.base.Ticker; import com.google.common.base.Verify; import com.google.common.collect.ImmutableList; @@ -32,6 +32,8 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.OptionalLong; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -189,7 +191,9 @@ public class Shard extends RaftActor { private final ShardTransactionMessageRetrySupport messageRetrySupport; - private final FrontendMetadata frontendMetadata; + @VisibleForTesting + final FrontendMetadata frontendMetadata; + private Map knownFrontends = ImmutableMap.of(); private boolean paused; @@ -413,22 +417,22 @@ public class Shard extends RaftActor { requestMessageAssembler.checkExpiredAssembledMessageState(); } - private Optional updateAccess(final SimpleShardDataTreeCohort cohort) { + private OptionalLong updateAccess(final SimpleShardDataTreeCohort cohort) { final FrontendIdentifier frontend = cohort.getIdentifier().getHistoryId().getClientId().getFrontendId(); final LeaderFrontendState state = knownFrontends.get(frontend); if (state == null) { // Not tell-based protocol, do nothing - return Optional.absent(); + return OptionalLong.empty(); } if (isIsolatedLeader()) { // We are isolated and no new request can come through until we emerge from it. We are still updating // liveness of frontend when we see it attempting to communicate. Use the last access timer. - return Optional.of(state.getLastSeenTicks()); + return OptionalLong.of(state.getLastSeenTicks()); } // If this frontend has freshly connected, give it some time to catch up before killing its transactions. - return Optional.of(state.getLastConnectTicks()); + return OptionalLong.of(state.getLastConnectTicks()); } private void disableTracking(final DisableTrackingPayload payload) { @@ -1083,21 +1087,22 @@ public class Shard extends RaftActor { } public abstract static class AbstractBuilder, S extends Shard> { - private final Class shardClass; + private final Class shardClass; private ShardIdentifier id; private Map peerAddresses = Collections.emptyMap(); private DatastoreContext datastoreContext; private SchemaContextProvider schemaContextProvider; private DatastoreSnapshot.ShardSnapshot restoreFromSnapshot; private DataTree dataTree; + private volatile boolean sealed; - protected AbstractBuilder(final Class shardClass) { + protected AbstractBuilder(final Class shardClass) { this.shardClass = shardClass; } protected void checkSealed() { - Preconditions.checkState(!sealed, "Builder isalready sealed - further modifications are not allowed"); + checkState(!sealed, "Builder isalready sealed - further modifications are not allowed"); } @SuppressWarnings("unchecked") @@ -1125,7 +1130,7 @@ public class Shard extends RaftActor { public T schemaContextProvider(final SchemaContextProvider newSchemaContextProvider) { checkSealed(); - this.schemaContextProvider = Preconditions.checkNotNull(newSchemaContextProvider); + this.schemaContextProvider = requireNonNull(newSchemaContextProvider); return self(); } @@ -1178,10 +1183,10 @@ public class Shard extends RaftActor { } protected void verify() { - Preconditions.checkNotNull(id, "id should not be null"); - Preconditions.checkNotNull(peerAddresses, "peerAddresses should not be null"); - Preconditions.checkNotNull(datastoreContext, "dataStoreContext should not be null"); - Preconditions.checkNotNull(schemaContextProvider, "schemaContextProvider should not be null"); + requireNonNull(id, "id should not be null"); + requireNonNull(peerAddresses, "peerAddresses should not be null"); + requireNonNull(datastoreContext, "dataStoreContext should not be null"); + requireNonNull(schemaContextProvider, "schemaContextProvider should not be null"); } public Props props() { @@ -1193,7 +1198,11 @@ public class Shard extends RaftActor { public static class Builder extends AbstractBuilder { Builder() { - super(Shard.class); + this(Shard.class); + } + + Builder(Class shardClass) { + super(shardClass); } }