use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.
the class SymphonyRoomSharedLog method handleEvent.
@Override
public Optional<LogMessage> handleEvent(V4Event e) {
Optional<LogMessage> out = super.handleEvent(e);
if (out.isPresent()) {
LogMessage logMessage = out.get();
Participant newParticipant = logMessage.participant;
if (logMessage.messageType == LogMessageType.LEADER) {
cachedLastKnownLeader = newParticipant;
}
List<Participant> allKnownParticipants = getRecentParticipants();
if (!allKnownParticipants.contains(newParticipant)) {
allKnownParticipants.add(newParticipant);
}
}
return out;
}
use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.
the class SharedStreamHandlerConfig method streamHandler.
protected SymphonyStreamHandler streamHandler(ApiInstance symphonyApi, List<StreamEventConsumer> consumers, ExceptionConsumer ec) {
SymphonyStreamHandler out = new SymphonyStreamHandler(symphonyApi, consumers, ec, false);
String email = symphonyApi.getIdentity().getEmail();
LOG.info("Created SymphonyStreamHandler for " + email + " with consumers " + consumers);
boolean cluster = true;
if (!StringUtils.hasText(streamProperties.getCoordinationStreamId())) {
LOG.info("No clustering = symphony.stream.coordinationStreamId not set");
cluster = false;
} else if (mc == null) {
LOG.info("No clustering = no multicaster available (maybe include spring-starter-web?)");
cluster = false;
} else if (self == null) {
LOG.info("No clustering = participant not set (maybe include spring-starter-web?)");
cluster = false;
}
if (cluster) {
SharedLog ls = symphonySharedLog(symphonyApi);
LOG.info("Creating cluster using " + email);
ClusterMember cm = clusterMember(email, mc, self, health == null ? () -> true : health, ls);
allClusterMembers.add(cm);
List<Participant> registeredParticipants = ls.getRecentParticipants();
LOG.info("Discovered cluster members: " + registeredParticipants.size());
participationNotifier(symphonyApi, self, taskScheduler, ls);
// filter cluster events so user doesn't see them
SymphonyLeaderEventFilter f = leaderEventFilter(ls);
out.setFilter(f);
}
out.start();
return out;
}
use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.
the class BullyDeathClusterTest method testClusterLeadership.
@ParameterizedTest
@MethodSource("setupConfigurations")
public void testClusterLeadership(Configuration c) throws InterruptedException {
System.out.println("--------------------------------------");
System.out.println("TEST: " + c.size + " " + c.time + "ms");
System.out.println("--------------------------------------");
Setup s = setupNetwork(c);
s.startup();
waitForLeaderCount(s);
if (c.size > 1) {
// kill the old leader, get a new one
Participant oldLeader = getLeaders(s).stream().findFirst().orElseThrow(() -> new IllegalStateException("Should be a leader"));
System.out.println("--------------------------------------");
s.c.isolate(oldLeader);
s.canTalkToSymphony.remove(oldLeader);
waitForLeaderCount(s);
getLeaders(s).stream().filter(l -> !l.equals(oldLeader)).findFirst().orElseThrow(() -> new IllegalStateException("Should be a new leader"));
// when we heal the network, we should go back to a single leader
System.out.println("--------------------------------------");
s.c.connect(oldLeader);
waitForLeaderCount(s);
getLeaders(s).stream().findFirst().orElseThrow(() -> new IllegalStateException("Should be a leader"));
}
s.shutdown();
Assertions.assertTrue(((DummyLeaderServiceImpl) s.ls).leaderHistory.size() < 10);
}
Aggregations