Skip to content

Commit

Permalink
Hide context in view change listener, add diadem
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Jan 27, 2024
1 parent 186dd17 commit 8c2bad2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
16 changes: 10 additions & 6 deletions fireflies/src/main/java/com/salesforce/apollo/fireflies/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -408,11 +409,13 @@ void introduced() {
void notifyListeners(List<SelfAddressingIdentifier> joining, List<Digest> 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);
}
Expand Down Expand Up @@ -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<Participant> context, Digest viewId, List<SelfAddressingIdentifier> joins,
List<Digest> leaves);
void viewChange(Function<SelfAddressingIdentifier, Participant> members, HexBloom diadem, Digest viewId,
List<SelfAddressingIdentifier> joins, List<Digest> leaves);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
public class ViewManagement {
private static final Logger log = LoggerFactory.getLogger(
ViewManagement.class);
final AtomicReference<HexBloom> diadem = new AtomicReference<>();
private final AtomicInteger attempt = new AtomicInteger();
private final Digest bootstrapView;
private final Context<Participant> context;
Expand All @@ -62,7 +63,6 @@ public class ViewManagement {
private final AtomicReference<ViewChange> vote = new AtomicReference<>();
private final Lock joinLock = new ReentrantLock();
private final AtomicReference<Digest> currentView = new AtomicReference<>();
private final AtomicReference<HexBloom> diadem = new AtomicReference<>();
private boolean bootstrap;
private CompletableFuture<Void> onJoined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -228,14 +228,14 @@ public void smokin() throws Exception {
var listener = new View.ViewLifecycleListener() {

@Override
public void viewChange(Context<Participant> context, Digest viewId,
List<SelfAddressingIdentifier> joins, List<Digest> leaves) {
if (context.totalCount() == CARDINALITY) {
System.out.printf("Full view: %s members: %s on: %s%n", viewId, context.totalCount(),
public void viewChange(Function<SelfAddressingIdentifier, View.Participant> context, HexBloom diadem,
Digest viewId, List<SelfAddressingIdentifier> joins, List<Digest> 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -114,14 +114,14 @@ public void smokin() throws Exception {
var listener = new View.ViewLifecycleListener() {

@Override
public void viewChange(Context<Participant> context, Digest viewId,
List<SelfAddressingIdentifier> joins, List<Digest> leaves) {
if (context.totalCount() == CARDINALITY) {
System.out.printf("Full view: %s members: %s on: %s%n", viewId, context.totalCount(),
public void viewChange(Function<SelfAddressingIdentifier, View.Participant> context, HexBloom diadem,
Digest viewId, List<SelfAddressingIdentifier> joins, List<Digest> 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());
}
}
Expand Down

0 comments on commit 8c2bad2

Please sign in to comment.