use of io.zeebe.broker.logstreams.LogStreamService in project zeebe by zeebe-io.
the class RaftService method onStateChange.
@Override
public void onStateChange(int partitionId, DirectBuffer topicName, SocketAddress socketAddress, RaftState raftState) {
actor.call(() -> {
currentRaftState = raftState;
if (currentRaftState == RaftState.LEADER) {
Loggers.CLUSTERING_LOGGER.debug("Start log stream...topic {}", BufferUtil.bufferAsString(raft.getLogStream().getTopicName()));
final LogStream logStream = raft.getLogStream();
final LogStreamService service = new LogStreamService(logStream);
final ServiceName<LogStream> streamGroup = Protocol.SYSTEM_TOPIC_BUF.equals(logStream.getTopicName()) ? LogStreamServiceNames.SYSTEM_STREAM_GROUP : LogStreamServiceNames.WORKFLOW_STREAM_GROUP;
final ActorFuture<Void> future = startContext.createService(logStreamServiceName, service).dependency(CLUSTER_MANAGER_SERVICE).dependency(raftServiceName).group(streamGroup).install();
actor.runOnCompletion(future, (v, throwable) -> {
if (throwable == null) {
actor.submit(() -> {
onOpenLogStreamListener.onOpenLogStreamService(raft.getLogStream());
});
} else {
LOG.error("Failed to install log stream service '{}'", logStreamServiceName);
}
});
} else if (currentRaftState == RaftState.FOLLOWER && startContext.hasService(logStreamServiceName)) {
startContext.removeService(logStreamServiceName);
}
});
}
Aggregations