@Override public CompletableFuture<ManagedPartitionGroup> join(PartitionManagementService managementService) { this.metadata = buildPartitions(); this.communicationService = managementService.getMessagingService(); communicationService.<Void, Void>subscribe(snapshotSubject, m -> handleSnapshot()); List<CompletableFuture<Partition>> futures = metadata.stream() .map(metadata -> { RaftPartition partition = partitions.get(metadata.id()); return partition.open(metadata, managementService); }) .collect(Collectors.toList()); return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).thenApply(v -> { LOGGER.info("Started"); return this; }); }
/** * Creates a Raft server. */ protected RaftPartitionServer createServer(PartitionManagementService managementService) { return new RaftPartitionServer( this, config, managementService.getMembershipService().getLocalMember().id(), managementService.getMembershipService(), managementService.getMessagingService(), managementService.getPrimitiveTypes(), threadContextFactory); }
/** * Creates a Raft client. */ private RaftPartitionClient createClient(PartitionManagementService managementService) { return new RaftPartitionClient( this, managementService.getMembershipService().getLocalMember().id(), new RaftClientCommunicator( name(), Serializer.using(RaftNamespaces.RAFT_PROTOCOL), managementService.getMessagingService()), threadContextFactory); }
private PrimaryBackupServer buildServer() { return PrimaryBackupServer.builder() .withServerName(partition.name()) .withMembershipService(managementService.getMembershipService()) .withMemberGroupProvider(memberGroupProvider) .withProtocol(new PrimaryBackupServerCommunicator( partition.name(), Serializer.using(PrimaryBackupNamespaces.PROTOCOL), managementService.getMessagingService())) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withPrimitiveTypes(managementService.getPrimitiveTypes()) .withThreadContextFactory(threadFactory) .build(); }
private PrimaryBackupClient newClient() { return PrimaryBackupClient.builder() .withClientName(partition.name()) .withPartitionId(partition.id()) .withMembershipService(managementService.getMembershipService()) .withProtocol(new PrimaryBackupClientCommunicator( partition.name(), Serializer.using(PrimaryBackupNamespaces.PROTOCOL), managementService.getMessagingService())) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withSessionIdProvider(managementService.getSessionIdService()) .withThreadContextFactory(threadFactory) .build(); }
private DistributedLogSessionClient newClient() { return DistributedLogSessionClient.builder() .withClientName(partition.name()) .withPartitionId(partition.id()) .withMembershipService(managementService.getMembershipService()) .withProtocol(new LogClientCommunicator( partition.name(), Serializer.using(LogNamespaces.PROTOCOL), managementService.getMessagingService())) .withSessionIdProvider(() -> managementService.getSessionIdService().nextSessionId()) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withThreadContextFactory(threadFactory) .build(); }
private DistributedLogServer buildServer() { return DistributedLogServer.builder() .withServerName(partition.name()) .withMembershipService(managementService.getMembershipService()) .withMemberGroupProvider(config.getMemberGroupProvider()) .withProtocol(new LogServerCommunicator( partition.name(), Serializer.using(LogNamespaces.PROTOCOL), managementService.getMessagingService())) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withStorageLevel(config.getStorageConfig().getLevel()) .withDirectory(config.getStorageConfig().getDirectory(partition.name())) .withMaxSegmentSize((int) config.getStorageConfig().getSegmentSize().bytes()) .withMaxEntrySize((int) config.getStorageConfig().getMaxEntrySize().bytes()) .withFlushOnCommit(config.getStorageConfig().isFlushOnCommit()) .withMaxLogSize(config.getCompactionConfig().getSize().bytes()) .withMaxLogAge(config.getCompactionConfig().getAge()) .withThreadContextFactory(threadFactory) .build(); }
private DistributedLogSessionClient newClient() { return DistributedLogSessionClient.builder() .withClientName(partition.name()) .withPartitionId(partition.id()) .withMembershipService(managementService.getMembershipService()) .withProtocol(new LogClientCommunicator( partition.name(), Serializer.using(LogNamespaces.PROTOCOL), managementService.getMessagingService())) .withSessionIdProvider(() -> managementService.getSessionIdService().nextSessionId()) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withThreadContextFactory(threadFactory) .build(); }
private DistributedLogServer buildServer() { return DistributedLogServer.builder() .withServerName(partition.name()) .withMembershipService(managementService.getMembershipService()) .withMemberGroupProvider(config.getMemberGroupProvider()) .withProtocol(new LogServerCommunicator( partition.name(), Serializer.using(LogNamespaces.PROTOCOL), managementService.getMessagingService())) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withStorageLevel(config.getStorageConfig().getLevel()) .withDirectory(config.getStorageConfig().getDirectory(partition.name())) .withMaxSegmentSize((int) config.getStorageConfig().getSegmentSize().bytes()) .withMaxEntrySize((int) config.getStorageConfig().getMaxEntrySize().bytes()) .withFlushOnCommit(config.getStorageConfig().isFlushOnCommit()) .withMaxLogSize(config.getCompactionConfig().getSize().bytes()) .withMaxLogAge(config.getCompactionConfig().getAge()) .withThreadContextFactory(threadFactory) .build(); }