Skip to content

Commit

Permalink
remove old style view change listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Mar 10, 2024
1 parent 3cff7f3 commit 794b36e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public void publish() {
.map(Map.Entry::getValue)
.forEach(v -> b.addCertifications(v.getWitness()));
view.publish(new HashedCertifiedBlock(params().digestAlgorithm(), b.build()));
controller.completeIt();
log.debug("Genesis block: {} published for: {} on: {}", reconfiguration.hash, view.context().getId(),
params().member().getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public void publish() {
public Transitions nextEpoch(Integer epoch) {
return null;
}

@Override
public Transitions process(List<ByteString> preblock, boolean last) {
return null;
}
}

}
Expand Down
47 changes: 0 additions & 47 deletions fireflies/src/main/java/com/salesforce/apollo/fireflies/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
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 @@ -96,7 +95,6 @@ public class View {
private final DigestAlgorithm digestAlgo;
private final RingCommunications<Participant, Fireflies> gossiper;
private final AtomicBoolean introduced = new AtomicBoolean();
private final List<ViewLifecycleListener> lifecycleListeners = new CopyOnWriteArrayList<>();
private final List<BiConsumer<Context, Digest>> viewChangeListeners = new CopyOnWriteArrayList<>();
private final Executor viewNotificationQueue = Executors.newSingleThreadExecutor(
Thread.ofVirtual().factory());
Expand Down Expand Up @@ -169,13 +167,6 @@ public static boolean isValidMask(BitSet mask, DynamicContext<?> context) {
return false;
}

/**
* Deregister the listener
*/
public void deregister(ViewLifecycleListener listener) {
lifecycleListeners.remove(listener);
}

/**
* Deregister the listener
*/
Expand All @@ -197,15 +188,6 @@ public Digest getNodeId() {
return node.getId();
}

/**
* Register the listener to receive view change events
*
* @param listener - the ViewChangeListener to receive events
*/
public void register(ViewLifecycleListener listener) {
lifecycleListeners.add(listener);
}

/**
* Register the listener to receive view changes
*/
Expand Down Expand Up @@ -429,18 +411,6 @@ void introduced() {

void notifyListeners(List<SelfAddressingIdentifier> joining, List<Digest> leaving) {
final var current = currentView();
viewNotificationQueue.execute(Utils.wrapped(() -> {
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(i -> context.getMember(i.getDigest()), current, viewManagement.cardinality(),
joining, leaving);
} catch (Throwable e) {
log.error("error in view change listener: {} on: {} ", listener, node.getId(), e);
}
});
}, log));
var sc = context.asStatic();
viewNotificationQueue.execute(Utils.wrapped(() -> {
viewChangeListeners.forEach(listener -> {
Expand Down Expand Up @@ -1505,23 +1475,6 @@ private boolean verify(SelfAddressingIdentifier id, SigningThreshold threshold,
return verifier.get().verify(threshold, signature, message);
}

@FunctionalInterface
public interface ViewLifecycleListener {

/**
* Notification of a view change event
*
* @param members - the source of Members for supplied identifiers
* @param viewId - the compact Digest identifying the new view
* @param cardinality - the cardinality of the new view
* @param joins - the list of joining member's id
* @param leaves - the list of leaving member's id
*/
void viewChange(Function<SelfAddressingIdentifier, Participant> members, Digest viewId, int cardinality,
List<SelfAddressingIdentifier> joins, List<Digest> leaves);

}

public record Seed(SelfAddressingIdentifier identifier, InetSocketAddress endpoint) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
import com.salesforce.apollo.choam.Parameters.ProducerParameters;
import com.salesforce.apollo.choam.Parameters.RuntimeParameters;
import com.salesforce.apollo.choam.proto.FoundationSeal;
import com.salesforce.apollo.context.Context;
import com.salesforce.apollo.context.DynamicContextImpl;
import com.salesforce.apollo.cryptography.Digest;
import com.salesforce.apollo.cryptography.DigestAlgorithm;
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.Seed;
import com.salesforce.apollo.membership.stereotomy.ControlledIdentifierMember;
import com.salesforce.apollo.model.ProcessContainerDomain;
import com.salesforce.apollo.model.ProcessDomain;
import com.salesforce.apollo.stereotomy.StereotomyImpl;
import com.salesforce.apollo.stereotomy.identifier.SelfAddressingIdentifier;
import com.salesforce.apollo.stereotomy.identifier.spec.IdentifierSpecification;
import com.salesforce.apollo.stereotomy.mem.MemKERL;
import com.salesforce.apollo.stereotomy.mem.MemKeyStore;
Expand All @@ -41,7 +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.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -224,22 +223,17 @@ public void smokin() throws Exception {
final var seeds = Collections.singletonList(
new Seed(domains.getFirst().getMember().getIdentifier().getIdentifier(), new InetSocketAddress(0)));
domains.forEach(d -> {
var listener = new View.ViewLifecycleListener() {

@Override
public void viewChange(Function<SelfAddressingIdentifier, View.Participant> context, Digest viewId,
int cardinality, List<SelfAddressingIdentifier> joins, List<Digest> leaves) {
if (cardinality == CARDINALITY) {
System.out.printf("Full view: %s members: %s on: %s%n", viewId, cardinality,
d.getMember().getId());
countdown.countDown();
} else {
System.out.printf("Members joining: %s members: %s on: %s%n", viewId, cardinality,
d.getMember().getId());
}
BiConsumer<Context, Digest> c = (context, viewId) -> {
if (context.cardinality() == CARDINALITY) {
System.out.printf("Full view: %s members: %s on: %s%n", viewId, context.cardinality(),
d.getMember().getId());
countdown.countDown();
} else {
System.out.printf("Members joining: %s members: %s on: %s%n", viewId, context.cardinality(),
d.getMember().getId());
}
};
d.getFoundation().register(listener);
d.getFoundation().register(c);
});
// start seed
final var started = new AtomicReference<>(new CountDownLatch(1));
Expand Down

0 comments on commit 794b36e

Please sign in to comment.