From 8c2bad295ec02f3fbd9a299e318a123ae1537c75 Mon Sep 17 00:00:00 2001 From: Hellblazer Date: Sat, 27 Jan 2024 15:37:17 -0800 Subject: [PATCH] Hide context in view change listener, add diadem --- .../com/salesforce/apollo/fireflies/View.java | 16 ++++++++++------ .../apollo/fireflies/ViewManagement.java | 2 +- .../apollo/demesnes/FireFliesTrace.java | 14 +++++++------- .../apollo/model/ProcessContainerDomain.java | 4 ++-- .../salesforce/apollo/model/ProcessDomain.java | 4 ++-- .../salesforce/apollo/model/FireFliesTest.java | 14 +++++++------- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/fireflies/src/main/java/com/salesforce/apollo/fireflies/View.java b/fireflies/src/main/java/com/salesforce/apollo/fireflies/View.java index 3eb61715b..a61eff86b 100644 --- a/fireflies/src/main/java/com/salesforce/apollo/fireflies/View.java +++ b/fireflies/src/main/java/com/salesforce/apollo/fireflies/View.java @@ -54,6 +54,7 @@ import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.BiConsumer; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -408,11 +409,13 @@ void introduced() { void notifyListeners(List joining, List leaving) { final var current = currentView(); viewNotificationQueue.execute(Utils.wrapped(() -> { + var diadem = viewManagement.diadem.get(); lifecycleListeners.forEach(listener -> { try { - log.trace("Notifying: {} view change: {} cardinality: {} joins: {} leaves: {} on: {} ", listener, - currentView(), context.totalCount(), joining.size(), leaving.size(), node.getId()); - listener.viewChange(context, current, joining, leaving); + log.trace("Notifying: {} view change: {} diadem: {} cardinality: {} joins: {} leaves: {} on: {} ", + listener, currentView(), diadem, context.totalCount(), joining.size(), leaving.size(), + node.getId()); + listener.viewChange(i -> context.getMember(i.getDigest()), diadem, current, joining, leaving); } catch (Throwable e) { log.error("error in view change listener: {} on: {} ", listener, node.getId(), e); } @@ -1473,13 +1476,14 @@ public interface ViewLifecycleListener { /** * Notification of a view change event * - * @param context - the context for which the view change has occurred + * @param members - the source of Members for supplied identifiers + * @param diadem - the wrapped diadem of the view * @param viewId - the Digest identity of the new view * @param joins - the list of joining member's id * @param leaves - the list of leaving member's id */ - void viewChange(Context context, Digest viewId, List joins, - List leaves); + void viewChange(Function members, HexBloom diadem, Digest viewId, + List joins, List leaves); } diff --git a/fireflies/src/main/java/com/salesforce/apollo/fireflies/ViewManagement.java b/fireflies/src/main/java/com/salesforce/apollo/fireflies/ViewManagement.java index 0033e6320..62584d8f0 100644 --- a/fireflies/src/main/java/com/salesforce/apollo/fireflies/ViewManagement.java +++ b/fireflies/src/main/java/com/salesforce/apollo/fireflies/ViewManagement.java @@ -49,6 +49,7 @@ public class ViewManagement { private static final Logger log = LoggerFactory.getLogger( ViewManagement.class); + final AtomicReference diadem = new AtomicReference<>(); private final AtomicInteger attempt = new AtomicInteger(); private final Digest bootstrapView; private final Context context; @@ -62,7 +63,6 @@ public class ViewManagement { private final AtomicReference vote = new AtomicReference<>(); private final Lock joinLock = new ReentrantLock(); private final AtomicReference currentView = new AtomicReference<>(); - private final AtomicReference diadem = new AtomicReference<>(); private boolean bootstrap; private CompletableFuture onJoined; diff --git a/isolates/src/test/java/com/salesforce/apollo/demesnes/FireFliesTrace.java b/isolates/src/test/java/com/salesforce/apollo/demesnes/FireFliesTrace.java index 469cce981..ddfc30ddd 100644 --- a/isolates/src/test/java/com/salesforce/apollo/demesnes/FireFliesTrace.java +++ b/isolates/src/test/java/com/salesforce/apollo/demesnes/FireFliesTrace.java @@ -16,12 +16,11 @@ import com.salesforce.apollo.choam.proto.FoundationSeal; import com.salesforce.apollo.cryptography.Digest; import com.salesforce.apollo.cryptography.DigestAlgorithm; +import com.salesforce.apollo.cryptography.HexBloom; import com.salesforce.apollo.delphinius.Oracle; import com.salesforce.apollo.delphinius.Oracle.Assertion; import com.salesforce.apollo.fireflies.View; -import com.salesforce.apollo.fireflies.View.Participant; import com.salesforce.apollo.fireflies.View.Seed; -import com.salesforce.apollo.membership.Context; import com.salesforce.apollo.membership.ContextImpl; import com.salesforce.apollo.membership.stereotomy.ControlledIdentifierMember; import com.salesforce.apollo.model.ProcessContainerDomain; @@ -43,6 +42,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -228,14 +228,14 @@ public void smokin() throws Exception { var listener = new View.ViewLifecycleListener() { @Override - public void viewChange(Context context, Digest viewId, - List joins, List leaves) { - if (context.totalCount() == CARDINALITY) { - System.out.printf("Full view: %s members: %s on: %s%n", viewId, context.totalCount(), + public void viewChange(Function context, HexBloom diadem, + Digest viewId, List joins, List leaves) { + if (diadem.getCardinality() == CARDINALITY) { + System.out.printf("Full view: %s members: %s on: %s%n", viewId, diadem.getCardinality(), d.getMember().getId()); countdown.countDown(); } else { - System.out.printf("Members joining: %s members: %s on: %s%n", viewId, context.totalCount(), + System.out.printf("Members joining: %s members: %s on: %s%n", viewId, diadem.getCardinality(), d.getMember().getId()); } } diff --git a/model/src/main/java/com/salesforce/apollo/model/ProcessContainerDomain.java b/model/src/main/java/com/salesforce/apollo/model/ProcessContainerDomain.java index 6f04e7061..710750db8 100644 --- a/model/src/main/java/com/salesforce/apollo/model/ProcessContainerDomain.java +++ b/model/src/main/java/com/salesforce/apollo/model/ProcessContainerDomain.java @@ -146,8 +146,8 @@ public SelfAddressingIdentifier spawn(DemesneParameters.Builder prototype) { @Override protected View.ViewLifecycleListener listener() { var delegate = super.listener(); - return (context, id, join, leaving) -> { - delegate.viewChange(context, id, join, leaving); + return (context, diadem, id, join, leaving) -> { + delegate.viewChange(context, diadem, id, join, leaving); log.info("View change: {} for: {} joining: {} leaving: {} on: {}", id, params.context().getId(), join.size(), leaving.size(), params.member().getId()); }; diff --git a/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java b/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java index b5a5a7b97..3d2472a57 100644 --- a/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java +++ b/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java @@ -116,9 +116,9 @@ public void stop() { } protected ViewLifecycleListener listener() { - return (context, id, join, leaving) -> { + return (context, diadem, id, join, leaving) -> { for (var d : join) { - params.context().activate(context.getMember(d.getDigest())); + params.context().activate(context.apply(d)); } for (var d : leaving) { params.context().remove(d); diff --git a/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java b/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java index 3bdf3b80c..4cb690d07 100644 --- a/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java +++ b/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java @@ -16,11 +16,10 @@ import com.salesforce.apollo.choam.proto.FoundationSeal; import com.salesforce.apollo.cryptography.Digest; import com.salesforce.apollo.cryptography.DigestAlgorithm; +import com.salesforce.apollo.cryptography.HexBloom; import com.salesforce.apollo.delphinius.Oracle; import com.salesforce.apollo.fireflies.View; -import com.salesforce.apollo.fireflies.View.Participant; import com.salesforce.apollo.fireflies.View.Seed; -import com.salesforce.apollo.membership.Context; import com.salesforce.apollo.membership.ContextImpl; import com.salesforce.apollo.membership.stereotomy.ControlledIdentifierMember; import com.salesforce.apollo.stereotomy.StereotomyImpl; @@ -41,6 +40,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -114,14 +114,14 @@ public void smokin() throws Exception { var listener = new View.ViewLifecycleListener() { @Override - public void viewChange(Context context, Digest viewId, - List joins, List leaves) { - if (context.totalCount() == CARDINALITY) { - System.out.printf("Full view: %s members: %s on: %s%n", viewId, context.totalCount(), + public void viewChange(Function context, HexBloom diadem, + Digest viewId, List joins, List leaves) { + if (diadem.getCardinality() == CARDINALITY) { + System.out.printf("Full view: %s members: %s on: %s%n", viewId, diadem.getCardinality(), d.getMember().getId()); countdown.countDown(); } else { - System.out.printf("Members joining: %s members: %s on: %s%n", viewId, context.totalCount(), + System.out.printf("Members joining: %s members: %s on: %s%n", viewId, diadem.getCardinality(), d.getMember().getId()); } }