Committed by
Gerrit Code Review
Updates to ConsistentMap and LeaderElector state machines
Change-Id: I7734b253a56fef7300a8a094a3cfc8c1b45c2453
Showing
7 changed files
with
126 additions
and
41 deletions
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.store.primitives.impl; | 16 | package org.onosproject.store.primitives.impl; |
| 17 | 17 | ||
| 18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 18 | import io.atomix.catalyst.serializer.Serializer; | 19 | import io.atomix.catalyst.serializer.Serializer; |
| 19 | import io.atomix.catalyst.transport.Address; | 20 | import io.atomix.catalyst.transport.Address; |
| 20 | import io.atomix.catalyst.transport.Transport; | 21 | import io.atomix.catalyst.transport.Transport; |
| ... | @@ -35,6 +36,7 @@ import java.util.function.Supplier; | ... | @@ -35,6 +36,7 @@ import java.util.function.Supplier; |
| 35 | 36 | ||
| 36 | import org.onosproject.cluster.NodeId; | 37 | import org.onosproject.cluster.NodeId; |
| 37 | import org.onosproject.store.service.PartitionInfo; | 38 | import org.onosproject.store.service.PartitionInfo; |
| 39 | +import org.slf4j.Logger; | ||
| 38 | 40 | ||
| 39 | import com.google.common.collect.ImmutableSet; | 41 | import com.google.common.collect.ImmutableSet; |
| 40 | import com.google.common.collect.Sets; | 42 | import com.google.common.collect.Sets; |
| ... | @@ -44,6 +46,8 @@ import com.google.common.collect.Sets; | ... | @@ -44,6 +46,8 @@ import com.google.common.collect.Sets; |
| 44 | */ | 46 | */ |
| 45 | public class StoragePartitionServer implements Managed<StoragePartitionServer> { | 47 | public class StoragePartitionServer implements Managed<StoragePartitionServer> { |
| 46 | 48 | ||
| 49 | + private final Logger log = getLogger(getClass()); | ||
| 50 | + | ||
| 47 | private static final int MAX_ENTRIES_PER_LOG_SEGMENT = 32768; | 51 | private static final int MAX_ENTRIES_PER_LOG_SEGMENT = 32768; |
| 48 | private final StoragePartition partition; | 52 | private final StoragePartition partition; |
| 49 | private final Address localAddress; | 53 | private final Address localAddress; |
| ... | @@ -81,7 +85,13 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { | ... | @@ -81,7 +85,13 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { |
| 81 | } else { | 85 | } else { |
| 82 | serverOpenFuture = CompletableFuture.completedFuture(null); | 86 | serverOpenFuture = CompletableFuture.completedFuture(null); |
| 83 | } | 87 | } |
| 84 | - return serverOpenFuture.thenApply(v -> null); | 88 | + return serverOpenFuture.whenComplete((r, e) -> { |
| 89 | + if (e == null) { | ||
| 90 | + log.info("Successfully started server for partition {}", partition.getId()); | ||
| 91 | + } else { | ||
| 92 | + log.info("Failed to start server for partition {}", partition.getId(), e); | ||
| 93 | + } | ||
| 94 | + }).thenApply(v -> null); | ||
| 85 | } | 95 | } |
| 86 | 96 | ||
| 87 | @Override | 97 | @Override |
| ... | @@ -105,7 +115,6 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { | ... | @@ -105,7 +115,6 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { |
| 105 | .withStorage(Storage.builder() | 115 | .withStorage(Storage.builder() |
| 106 | // FIXME: StorageLevel should be DISK | 116 | // FIXME: StorageLevel should be DISK |
| 107 | .withStorageLevel(StorageLevel.MEMORY) | 117 | .withStorageLevel(StorageLevel.MEMORY) |
| 108 | - .withSerializer(serializer.clone()) | ||
| 109 | .withDirectory(dataFolder) | 118 | .withDirectory(dataFolder) |
| 110 | .withMaxEntriesPerSegment(MAX_ENTRIES_PER_LOG_SEGMENT) | 119 | .withMaxEntriesPerSegment(MAX_ENTRIES_PER_LOG_SEGMENT) |
| 111 | .build()) | 120 | .build()) | ... | ... |
| ... | @@ -17,12 +17,12 @@ package org.onosproject.store.primitives.resources.impl; | ... | @@ -17,12 +17,12 @@ package org.onosproject.store.primitives.resources.impl; |
| 17 | 17 | ||
| 18 | import io.atomix.catalyst.util.Listener; | 18 | import io.atomix.catalyst.util.Listener; |
| 19 | import io.atomix.copycat.client.CopycatClient; | 19 | import io.atomix.copycat.client.CopycatClient; |
| 20 | -import io.atomix.resource.Consistency; | ||
| 21 | import io.atomix.resource.Resource; | 20 | import io.atomix.resource.Resource; |
| 22 | import io.atomix.resource.ResourceTypeInfo; | 21 | import io.atomix.resource.ResourceTypeInfo; |
| 23 | 22 | ||
| 24 | import java.util.Collection; | 23 | import java.util.Collection; |
| 25 | import java.util.ConcurrentModificationException; | 24 | import java.util.ConcurrentModificationException; |
| 25 | +import java.util.List; | ||
| 26 | import java.util.Map.Entry; | 26 | import java.util.Map.Entry; |
| 27 | import java.util.Set; | 27 | import java.util.Set; |
| 28 | import java.util.concurrent.CompletableFuture; | 28 | import java.util.concurrent.CompletableFuture; |
| ... | @@ -49,7 +49,7 @@ public class AtomixConsistentMap extends Resource<AtomixConsistentMap, Resource. | ... | @@ -49,7 +49,7 @@ public class AtomixConsistentMap extends Resource<AtomixConsistentMap, Resource. |
| 49 | 49 | ||
| 50 | private final Set<MapEventListener<String, byte[]>> mapEventListeners = Sets.newCopyOnWriteArraySet(); | 50 | private final Set<MapEventListener<String, byte[]>> mapEventListeners = Sets.newCopyOnWriteArraySet(); |
| 51 | 51 | ||
| 52 | - private static final String CHANGE_SUBJECT = "change"; | 52 | + public static final String CHANGE_SUBJECT = "changeEvents"; |
| 53 | 53 | ||
| 54 | public AtomixConsistentMap(CopycatClient client, Resource.Options options) { | 54 | public AtomixConsistentMap(CopycatClient client, Resource.Options options) { |
| 55 | super(client, options); | 55 | super(client, options); |
| ... | @@ -68,14 +68,8 @@ public class AtomixConsistentMap extends Resource<AtomixConsistentMap, Resource. | ... | @@ -68,14 +68,8 @@ public class AtomixConsistentMap extends Resource<AtomixConsistentMap, Resource. |
| 68 | }); | 68 | }); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | - private void handleEvent(MapEvent<String, byte[]> event) { | 71 | + private void handleEvent(List<MapEvent<String, byte[]>> events) { |
| 72 | - mapEventListeners.forEach(listener -> listener.event(event)); | 72 | + events.forEach(event -> mapEventListeners.forEach(listener -> listener.event(event))); |
| 73 | - } | ||
| 74 | - | ||
| 75 | - @Override | ||
| 76 | - public AtomixConsistentMap with(Consistency consistency) { | ||
| 77 | - super.with(consistency); | ||
| 78 | - return this; | ||
| 79 | } | 73 | } |
| 80 | 74 | ||
| 81 | @Override | 75 | @Override | ... | ... |
| ... | @@ -18,7 +18,9 @@ package org.onosproject.store.primitives.resources.impl; | ... | @@ -18,7 +18,9 @@ package org.onosproject.store.primitives.resources.impl; |
| 18 | import io.atomix.catalyst.buffer.BufferInput; | 18 | import io.atomix.catalyst.buffer.BufferInput; |
| 19 | import io.atomix.catalyst.buffer.BufferOutput; | 19 | import io.atomix.catalyst.buffer.BufferOutput; |
| 20 | import io.atomix.catalyst.serializer.CatalystSerializable; | 20 | import io.atomix.catalyst.serializer.CatalystSerializable; |
| 21 | +import io.atomix.catalyst.serializer.SerializableTypeResolver; | ||
| 21 | import io.atomix.catalyst.serializer.Serializer; | 22 | import io.atomix.catalyst.serializer.Serializer; |
| 23 | +import io.atomix.catalyst.serializer.SerializerRegistry; | ||
| 22 | import io.atomix.catalyst.util.Assert; | 24 | import io.atomix.catalyst.util.Assert; |
| 23 | import io.atomix.copycat.client.Command; | 25 | import io.atomix.copycat.client.Command; |
| 24 | import io.atomix.copycat.client.Query; | 26 | import io.atomix.copycat.client.Query; |
| ... | @@ -514,4 +516,28 @@ public final class AtomixConsistentMapCommands { | ... | @@ -514,4 +516,28 @@ public final class AtomixConsistentMapCommands { |
| 514 | .toString(); | 516 | .toString(); |
| 515 | } | 517 | } |
| 516 | } | 518 | } |
| 519 | + | ||
| 520 | + /** | ||
| 521 | + * Map command type resolver. | ||
| 522 | + */ | ||
| 523 | + public static class TypeResolver implements SerializableTypeResolver { | ||
| 524 | + @Override | ||
| 525 | + public void resolve(SerializerRegistry registry) { | ||
| 526 | + registry.register(ContainsKey.class, -761); | ||
| 527 | + registry.register(ContainsValue.class, -762); | ||
| 528 | + registry.register(Get.class, -763); | ||
| 529 | + registry.register(EntrySet.class, -764); | ||
| 530 | + registry.register(Values.class, -765); | ||
| 531 | + registry.register(KeySet.class, -766); | ||
| 532 | + registry.register(Clear.class, -767); | ||
| 533 | + registry.register(IsEmpty.class, -768); | ||
| 534 | + registry.register(Size.class, -769); | ||
| 535 | + registry.register(Listen.class, -770); | ||
| 536 | + registry.register(Unlisten.class, -771); | ||
| 537 | + registry.register(TransactionPrepare.class, -772); | ||
| 538 | + registry.register(TransactionCommit.class, -773); | ||
| 539 | + registry.register(TransactionRollback.class, -774); | ||
| 540 | + registry.register(UpdateAndGet.class, -775); | ||
| 541 | + } | ||
| 542 | + } | ||
| 517 | } | 543 | } | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -17,7 +17,6 @@ package org.onosproject.store.primitives.resources.impl; | ... | @@ -17,7 +17,6 @@ package org.onosproject.store.primitives.resources.impl; |
| 17 | 17 | ||
| 18 | import io.atomix.catalyst.util.Listener; | 18 | import io.atomix.catalyst.util.Listener; |
| 19 | import io.atomix.copycat.client.CopycatClient; | 19 | import io.atomix.copycat.client.CopycatClient; |
| 20 | -import io.atomix.resource.Consistency; | ||
| 21 | import io.atomix.resource.Resource; | 20 | import io.atomix.resource.Resource; |
| 22 | import io.atomix.resource.ResourceTypeInfo; | 21 | import io.atomix.resource.ResourceTypeInfo; |
| 23 | 22 | ||
| ... | @@ -26,6 +25,7 @@ import java.util.Set; | ... | @@ -26,6 +25,7 @@ import java.util.Set; |
| 26 | import java.util.concurrent.CompletableFuture; | 25 | import java.util.concurrent.CompletableFuture; |
| 27 | import java.util.function.Consumer; | 26 | import java.util.function.Consumer; |
| 28 | 27 | ||
| 28 | +import org.onlab.util.SharedExecutors; | ||
| 29 | import org.onosproject.cluster.Leadership; | 29 | import org.onosproject.cluster.Leadership; |
| 30 | import org.onosproject.cluster.NodeId; | 30 | import org.onosproject.cluster.NodeId; |
| 31 | import org.onosproject.event.Change; | 31 | import org.onosproject.event.Change; |
| ... | @@ -37,8 +37,8 @@ import com.google.common.collect.Sets; | ... | @@ -37,8 +37,8 @@ import com.google.common.collect.Sets; |
| 37 | * Distributed resource providing the {@link AsyncLeaderElector} primitive. | 37 | * Distributed resource providing the {@link AsyncLeaderElector} primitive. |
| 38 | */ | 38 | */ |
| 39 | @ResourceTypeInfo(id = -152, stateMachine = AtomixLeaderElectorState.class) | 39 | @ResourceTypeInfo(id = -152, stateMachine = AtomixLeaderElectorState.class) |
| 40 | -public class AtomixLeaderElector | 40 | +public class AtomixLeaderElector extends Resource<AtomixLeaderElector, Resource.Options> |
| 41 | - extends Resource<AtomixLeaderElector, Resource.Options> implements AsyncLeaderElector { | 41 | + implements AsyncLeaderElector { |
| 42 | private final Set<Consumer<Change<Leadership>>> leadershipChangeListeners = | 42 | private final Set<Consumer<Change<Leadership>>> leadershipChangeListeners = |
| 43 | Sets.newConcurrentHashSet(); | 43 | Sets.newConcurrentHashSet(); |
| 44 | 44 | ||
| ... | @@ -62,13 +62,8 @@ public class AtomixLeaderElector | ... | @@ -62,13 +62,8 @@ public class AtomixLeaderElector |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | private void handleEvent(Change<Leadership> change) { | 64 | private void handleEvent(Change<Leadership> change) { |
| 65 | - leadershipChangeListeners.forEach(l -> l.accept(change)); | 65 | + SharedExecutors.getSingleThreadExecutor().execute(() -> |
| 66 | - } | 66 | + leadershipChangeListeners.forEach(l -> l.accept(change))); |
| 67 | - | ||
| 68 | - @Override | ||
| 69 | - public AtomixLeaderElector with(Consistency consistency) { | ||
| 70 | - super.with(consistency); | ||
| 71 | - return this; | ||
| 72 | } | 67 | } |
| 73 | 68 | ||
| 74 | @Override | 69 | @Override | ... | ... |
| ... | @@ -21,13 +21,16 @@ import java.util.Set; | ... | @@ -21,13 +21,16 @@ import java.util.Set; |
| 21 | import org.onosproject.cluster.Leadership; | 21 | import org.onosproject.cluster.Leadership; |
| 22 | import org.onosproject.cluster.NodeId; | 22 | import org.onosproject.cluster.NodeId; |
| 23 | 23 | ||
| 24 | + | ||
| 24 | import com.google.common.base.MoreObjects; | 25 | import com.google.common.base.MoreObjects; |
| 25 | import com.google.common.base.Strings; | 26 | import com.google.common.base.Strings; |
| 26 | 27 | ||
| 27 | import io.atomix.catalyst.buffer.BufferInput; | 28 | import io.atomix.catalyst.buffer.BufferInput; |
| 28 | import io.atomix.catalyst.buffer.BufferOutput; | 29 | import io.atomix.catalyst.buffer.BufferOutput; |
| 29 | import io.atomix.catalyst.serializer.CatalystSerializable; | 30 | import io.atomix.catalyst.serializer.CatalystSerializable; |
| 31 | +import io.atomix.catalyst.serializer.SerializableTypeResolver; | ||
| 30 | import io.atomix.catalyst.serializer.Serializer; | 32 | import io.atomix.catalyst.serializer.Serializer; |
| 33 | +import io.atomix.catalyst.serializer.SerializerRegistry; | ||
| 31 | import io.atomix.catalyst.util.Assert; | 34 | import io.atomix.catalyst.util.Assert; |
| 32 | import io.atomix.copycat.client.Command; | 35 | import io.atomix.copycat.client.Command; |
| 33 | import io.atomix.copycat.client.Query; | 36 | import io.atomix.copycat.client.Query; |
| ... | @@ -232,6 +235,18 @@ public final class AtomixLeaderElectorCommands { | ... | @@ -232,6 +235,18 @@ public final class AtomixLeaderElectorCommands { |
| 232 | .add("nodeId", nodeId) | 235 | .add("nodeId", nodeId) |
| 233 | .toString(); | 236 | .toString(); |
| 234 | } | 237 | } |
| 238 | + | ||
| 239 | + @Override | ||
| 240 | + public void writeObject(BufferOutput<?> buffer, Serializer serializer) { | ||
| 241 | + buffer.writeString(topic); | ||
| 242 | + buffer.writeString(nodeId.toString()); | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + @Override | ||
| 246 | + public void readObject(BufferInput<?> buffer, Serializer serializer) { | ||
| 247 | + topic = buffer.readString(); | ||
| 248 | + nodeId = new NodeId(buffer.readString()); | ||
| 249 | + } | ||
| 235 | } | 250 | } |
| 236 | 251 | ||
| 237 | /** | 252 | /** |
| ... | @@ -263,6 +278,16 @@ public final class AtomixLeaderElectorCommands { | ... | @@ -263,6 +278,16 @@ public final class AtomixLeaderElectorCommands { |
| 263 | .add("topic", topic) | 278 | .add("topic", topic) |
| 264 | .toString(); | 279 | .toString(); |
| 265 | } | 280 | } |
| 281 | + | ||
| 282 | + @Override | ||
| 283 | + public void writeObject(BufferOutput<?> buffer, Serializer serializer) { | ||
| 284 | + buffer.writeString(topic); | ||
| 285 | + } | ||
| 286 | + | ||
| 287 | + @Override | ||
| 288 | + public void readObject(BufferInput<?> buffer, Serializer serializer) { | ||
| 289 | + topic = buffer.readString(); | ||
| 290 | + } | ||
| 266 | } | 291 | } |
| 267 | 292 | ||
| 268 | /** | 293 | /** |
| ... | @@ -306,5 +331,34 @@ public final class AtomixLeaderElectorCommands { | ... | @@ -306,5 +331,34 @@ public final class AtomixLeaderElectorCommands { |
| 306 | .add("nodeId", nodeId) | 331 | .add("nodeId", nodeId) |
| 307 | .toString(); | 332 | .toString(); |
| 308 | } | 333 | } |
| 334 | + | ||
| 335 | + @Override | ||
| 336 | + public void writeObject(BufferOutput<?> buffer, Serializer serializer) { | ||
| 337 | + buffer.writeString(topic); | ||
| 338 | + buffer.writeString(nodeId.toString()); | ||
| 339 | + } | ||
| 340 | + | ||
| 341 | + @Override | ||
| 342 | + public void readObject(BufferInput<?> buffer, Serializer serializer) { | ||
| 343 | + topic = buffer.readString(); | ||
| 344 | + nodeId = new NodeId(buffer.readString()); | ||
| 345 | + } | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + /** | ||
| 349 | + * Map command type resolver. | ||
| 350 | + */ | ||
| 351 | + public static class TypeResolver implements SerializableTypeResolver { | ||
| 352 | + @Override | ||
| 353 | + public void resolve(SerializerRegistry registry) { | ||
| 354 | + registry.register(Run.class, -861); | ||
| 355 | + registry.register(Withdraw.class, -862); | ||
| 356 | + registry.register(Anoint.class, -863); | ||
| 357 | + registry.register(GetAllLeaderships.class, -864); | ||
| 358 | + registry.register(GetElectedTopics.class, -865); | ||
| 359 | + registry.register(GetLeadership.class, -866); | ||
| 360 | + registry.register(Listen.class, -867); | ||
| 361 | + registry.register(Unlisten.class, -868); | ||
| 362 | + } | ||
| 309 | } | 363 | } |
| 310 | } | 364 | } | ... | ... |
| ... | @@ -41,6 +41,14 @@ import org.onosproject.cluster.Leader; | ... | @@ -41,6 +41,14 @@ import org.onosproject.cluster.Leader; |
| 41 | import org.onosproject.cluster.Leadership; | 41 | import org.onosproject.cluster.Leadership; |
| 42 | import org.onosproject.cluster.NodeId; | 42 | import org.onosproject.cluster.NodeId; |
| 43 | import org.onosproject.event.Change; | 43 | import org.onosproject.event.Change; |
| 44 | +import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands.Anoint; | ||
| 45 | +import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands.GetAllLeaderships; | ||
| 46 | +import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands.GetElectedTopics; | ||
| 47 | +import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands.GetLeadership; | ||
| 48 | +import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands.Listen; | ||
| 49 | +import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands.Run; | ||
| 50 | +import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands.Unlisten; | ||
| 51 | +import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands.Withdraw; | ||
| 44 | import org.onosproject.store.serializers.KryoNamespaces; | 52 | import org.onosproject.store.serializers.KryoNamespaces; |
| 45 | import org.onosproject.store.service.Serializer; | 53 | import org.onosproject.store.service.Serializer; |
| 46 | import org.slf4j.Logger; | 54 | import org.slf4j.Logger; |
| ... | @@ -59,7 +67,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -59,7 +67,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
| 59 | private final Logger log = getLogger(getClass()); | 67 | private final Logger log = getLogger(getClass()); |
| 60 | private Map<String, AtomicLong> termCounters = new HashMap<>(); | 68 | private Map<String, AtomicLong> termCounters = new HashMap<>(); |
| 61 | private Map<String, ElectionState> elections = new HashMap<>(); | 69 | private Map<String, ElectionState> elections = new HashMap<>(); |
| 62 | - private final Map<Long, Commit<? extends AtomixLeaderElectorCommands.Listen>> listeners = new LinkedHashMap<>(); | 70 | + private final Map<Long, Commit<? extends Listen>> listeners = new LinkedHashMap<>(); |
| 63 | private final Serializer serializer = Serializer.using(Arrays.asList(KryoNamespaces.API), | 71 | private final Serializer serializer = Serializer.using(Arrays.asList(KryoNamespaces.API), |
| 64 | ElectionState.class, | 72 | ElectionState.class, |
| 65 | Registration.class); | 73 | Registration.class); |
| ... | @@ -67,16 +75,16 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -67,16 +75,16 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
| 67 | @Override | 75 | @Override |
| 68 | protected void configure(StateMachineExecutor executor) { | 76 | protected void configure(StateMachineExecutor executor) { |
| 69 | // Notification | 77 | // Notification |
| 70 | - executor.register(AtomixLeaderElectorCommands.Listen.class, this::listen); | 78 | + executor.register(Listen.class, this::listen); |
| 71 | - executor.register(AtomixLeaderElectorCommands.Unlisten.class, this::unlisten); | 79 | + executor.register(Unlisten.class, this::unlisten); |
| 72 | // Commands | 80 | // Commands |
| 73 | - executor.register(AtomixLeaderElectorCommands.Run.class, this::run); | 81 | + executor.register(Run.class, this::run); |
| 74 | - executor.register(AtomixLeaderElectorCommands.Withdraw.class, this::withdraw); | 82 | + executor.register(Withdraw.class, this::withdraw); |
| 75 | - executor.register(AtomixLeaderElectorCommands.Anoint.class, this::anoint); | 83 | + executor.register(Anoint.class, this::anoint); |
| 76 | // Queries | 84 | // Queries |
| 77 | - executor.register(AtomixLeaderElectorCommands.GetLeadership.class, this::leadership); | 85 | + executor.register(GetLeadership.class, this::leadership); |
| 78 | - executor.register(AtomixLeaderElectorCommands.GetAllLeaderships.class, this::allLeaderships); | 86 | + executor.register(GetAllLeaderships.class, this::allLeaderships); |
| 79 | - executor.register(AtomixLeaderElectorCommands.GetElectedTopics.class, this::electedTopics); | 87 | + executor.register(GetElectedTopics.class, this::electedTopics); |
| 80 | } | 88 | } |
| 81 | 89 | ||
| 82 | private void notifyLeadershipChange(Leadership previousLeadership, Leadership newLeadership) { | 90 | private void notifyLeadershipChange(Leadership previousLeadership, Leadership newLeadership) { |
| ... | @@ -96,7 +104,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -96,7 +104,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
| 96 | * | 104 | * |
| 97 | * @param commit listen commit | 105 | * @param commit listen commit |
| 98 | */ | 106 | */ |
| 99 | - public void listen(Commit<? extends AtomixLeaderElectorCommands.Listen> commit) { | 107 | + public void listen(Commit<? extends Listen> commit) { |
| 100 | if (listeners.putIfAbsent(commit.session().id(), commit) != null) { | 108 | if (listeners.putIfAbsent(commit.session().id(), commit) != null) { |
| 101 | commit.close(); | 109 | commit.close(); |
| 102 | } | 110 | } |
| ... | @@ -107,9 +115,9 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -107,9 +115,9 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
| 107 | * | 115 | * |
| 108 | * @param commit unlisten commit | 116 | * @param commit unlisten commit |
| 109 | */ | 117 | */ |
| 110 | - public void unlisten(Commit<? extends AtomixLeaderElectorCommands.Unlisten> commit) { | 118 | + public void unlisten(Commit<? extends Unlisten> commit) { |
| 111 | try { | 119 | try { |
| 112 | - Commit<? extends AtomixLeaderElectorCommands.Listen> listener = listeners.remove(commit.session().id()); | 120 | + Commit<? extends Listen> listener = listeners.remove(commit.session().id()); |
| 113 | if (listener != null) { | 121 | if (listener != null) { |
| 114 | listener.close(); | 122 | listener.close(); |
| 115 | } | 123 | } |
| ... | @@ -123,7 +131,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -123,7 +131,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
| 123 | * @param commit commit entry | 131 | * @param commit commit entry |
| 124 | * @return topic leader. If no previous leader existed this is the node that just entered the race. | 132 | * @return topic leader. If no previous leader existed this is the node that just entered the race. |
| 125 | */ | 133 | */ |
| 126 | - public Leadership run(Commit<? extends AtomixLeaderElectorCommands.Run> commit) { | 134 | + public Leadership run(Commit<? extends Run> commit) { |
| 127 | try { | 135 | try { |
| 128 | String topic = commit.operation().topic(); | 136 | String topic = commit.operation().topic(); |
| 129 | Leadership oldLeadership = leadership(topic); | 137 | Leadership oldLeadership = leadership(topic); |
| ... | @@ -154,7 +162,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -154,7 +162,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
| 154 | * Applies an {@link AtomixLeaderElectorCommands.Withdraw} commit. | 162 | * Applies an {@link AtomixLeaderElectorCommands.Withdraw} commit. |
| 155 | * @param commit withdraw commit | 163 | * @param commit withdraw commit |
| 156 | */ | 164 | */ |
| 157 | - public void withdraw(Commit<? extends AtomixLeaderElectorCommands.Withdraw> commit) { | 165 | + public void withdraw(Commit<? extends Withdraw> commit) { |
| 158 | try { | 166 | try { |
| 159 | String topic = commit.operation().topic(); | 167 | String topic = commit.operation().topic(); |
| 160 | Leadership oldLeadership = leadership(topic); | 168 | Leadership oldLeadership = leadership(topic); |
| ... | @@ -174,7 +182,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -174,7 +182,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
| 174 | * @param commit anoint commit | 182 | * @param commit anoint commit |
| 175 | * @return {@code true} if changes were made and the transfer occurred; {@code false} if it did not. | 183 | * @return {@code true} if changes were made and the transfer occurred; {@code false} if it did not. |
| 176 | */ | 184 | */ |
| 177 | - public boolean anoint(Commit<? extends AtomixLeaderElectorCommands.Anoint> commit) { | 185 | + public boolean anoint(Commit<? extends Anoint> commit) { |
| 178 | try { | 186 | try { |
| 179 | String topic = commit.operation().topic(); | 187 | String topic = commit.operation().topic(); |
| 180 | Leadership oldLeadership = leadership(topic); | 188 | Leadership oldLeadership = leadership(topic); |
| ... | @@ -197,7 +205,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -197,7 +205,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
| 197 | * @param commit GetLeadership commit | 205 | * @param commit GetLeadership commit |
| 198 | * @return leader | 206 | * @return leader |
| 199 | */ | 207 | */ |
| 200 | - public Leadership leadership(Commit<? extends AtomixLeaderElectorCommands.GetLeadership> commit) { | 208 | + public Leadership leadership(Commit<? extends GetLeadership> commit) { |
| 201 | String topic = commit.operation().topic(); | 209 | String topic = commit.operation().topic(); |
| 202 | try { | 210 | try { |
| 203 | return leadership(topic); | 211 | return leadership(topic); |
| ... | @@ -211,7 +219,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -211,7 +219,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
| 211 | * @param commit commit entry | 219 | * @param commit commit entry |
| 212 | * @return set of topics for which the node is the leader | 220 | * @return set of topics for which the node is the leader |
| 213 | */ | 221 | */ |
| 214 | - public Set<String> electedTopics(Commit<? extends AtomixLeaderElectorCommands.GetElectedTopics> commit) { | 222 | + public Set<String> electedTopics(Commit<? extends GetElectedTopics> commit) { |
| 215 | try { | 223 | try { |
| 216 | NodeId nodeId = commit.operation().nodeId(); | 224 | NodeId nodeId = commit.operation().nodeId(); |
| 217 | return Maps.filterEntries(elections, e -> { | 225 | return Maps.filterEntries(elections, e -> { |
| ... | @@ -228,8 +236,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -228,8 +236,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
| 228 | * @param commit GetAllLeaderships commit | 236 | * @param commit GetAllLeaderships commit |
| 229 | * @return topic to leader mapping | 237 | * @return topic to leader mapping |
| 230 | */ | 238 | */ |
| 231 | - public Map<String, Leadership> allLeaderships( | 239 | + public Map<String, Leadership> allLeaderships(Commit<? extends GetAllLeaderships> commit) { |
| 232 | - Commit<? extends AtomixLeaderElectorCommands.GetAllLeaderships> commit) { | ||
| 233 | try { | 240 | try { |
| 234 | return Maps.transformEntries(elections, (k, v) -> leadership(k)); | 241 | return Maps.transformEntries(elections, (k, v) -> leadership(k)); |
| 235 | } finally { | 242 | } finally { | ... | ... |
-
Please register or login to post a comment