io.atomix.cluster.ClusterMembershipService Java Examples
The following examples show how to use
io.atomix.cluster.ClusterMembershipService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClusterResource.java From atomix with Apache License 2.0 | 6 votes |
@GET @Path("/nodes/{node}/events/{id}") @Produces(MediaType.APPLICATION_JSON) public void getNodeEvent(@PathParam("node") String memberId, @PathParam("id") String listenerId, @Context ClusterMembershipService clusterMembershipService, @Context EventManager events, @Suspended AsyncResponse response) { EventLog<ClusterMembershipEventListener, ClusterMembershipEvent> eventLog = events.getEventLog(ClusterResource.class, getNodeListener(memberId, listenerId)); if (eventLog == null) { response.resume(Response.status(Status.NOT_FOUND).build()); return; } eventLog.nextEvent().whenComplete((result, error) -> { if (error == null) { response.resume(Response.ok(new NodeEvent(result.subject().id(), result.type()))); } else { LOGGER.warn("{}", error); response.resume(Response.serverError().build()); } }); }
Example #2
Source File: ClusterResource.java From atomix with Apache License 2.0 | 6 votes |
@GET @Path("/events/{id}") @Produces(MediaType.APPLICATION_JSON) public void getEvent(@PathParam("id") String listenerId, @Context ClusterMembershipService clusterMembershipService, @Context EventManager events, @Suspended AsyncResponse response) { EventLog<ClusterMembershipEventListener, ClusterMembershipEvent> eventLog = events.getEventLog(ClusterResource.class, listenerId); if (eventLog == null) { response.resume(Response.status(Status.NOT_FOUND).build()); return; } eventLog.nextEvent().whenComplete((result, error) -> { if (error == null) { response.resume(Response.ok(new NodeEvent(result.subject().id(), result.type()))); } else { LOGGER.warn("{}", error); response.resume(Response.serverError().build()); } }); }
Example #3
Source File: RaftPartitionServer.java From atomix with Apache License 2.0 | 6 votes |
public RaftPartitionServer( RaftPartition partition, RaftPartitionGroupConfig config, MemberId localMemberId, ClusterMembershipService membershipService, ClusterCommunicationService clusterCommunicator, PrimitiveTypeRegistry primitiveTypes, ThreadContextFactory threadContextFactory) { this.partition = partition; this.config = config; this.localMemberId = localMemberId; this.membershipService = membershipService; this.clusterCommunicator = clusterCommunicator; this.primitiveTypes = primitiveTypes; this.threadContextFactory = threadContextFactory; }
Example #4
Source File: PrimaryBackupServerContext.java From atomix with Apache License 2.0 | 6 votes |
public PrimaryBackupServerContext( String serverName, ClusterMembershipService clusterMembershipService, ManagedMemberGroupService memberGroupService, PrimaryBackupServerProtocol protocol, PrimitiveTypeRegistry primitiveTypes, PrimaryElection primaryElection, ThreadContextFactory threadContextFactory, boolean closeOnStop) { this.serverName = serverName; this.clusterMembershipService = clusterMembershipService; this.memberGroupService = memberGroupService; this.protocol = protocol; this.threadContextFactory = threadContextFactory; this.closeOnStop = closeOnStop; this.primitiveTypes = primitiveTypes; this.primaryElection = primaryElection; }
Example #5
Source File: ClusterResource.java From atomix with Apache License 2.0 | 6 votes |
@GET @Path("/nodes/{node}/events") @Produces(MediaType.APPLICATION_JSON) public void getNodeEvent(@PathParam("node") String memberId, @Context ClusterMembershipService clusterMembershipService, @Context EventManager events, @Suspended AsyncResponse response) { EventLog<ClusterMembershipEventListener, ClusterMembershipEvent> eventLog = events.getOrCreateEventLog(ClusterResource.class, memberId, l -> e -> { if (e.subject().id().id().equals(memberId)) { l.addEvent(e); } }); if (eventLog.open()) { clusterMembershipService.addListener(eventLog.listener()); } eventLog.nextEvent().whenComplete((result, error) -> { if (error == null) { response.resume(Response.ok(new NodeEvent(result.subject().id(), result.type()))); } else { LOGGER.warn("{}", error); response.resume(Response.serverError().build()); } }); }
Example #6
Source File: ClusterResource.java From atomix with Apache License 2.0 | 6 votes |
@GET @Path("/events") @Produces(MediaType.APPLICATION_JSON) public void getEvent(@Context ClusterMembershipService clusterMembershipService, @Context EventManager events, @Suspended AsyncResponse response) { EventLog<ClusterMembershipEventListener, ClusterMembershipEvent> eventLog = events.getOrCreateEventLog(ClusterResource.class, "", l -> e -> l.addEvent(e)); if (eventLog.open()) { clusterMembershipService.addListener(eventLog.listener()); } eventLog.nextEvent().whenComplete((result, error) -> { if (error == null) { response.resume(Response.ok(new NodeEvent(result.subject().id(), result.type()))); } else { LOGGER.warn("{}", error); response.resume(Response.serverError().build()); } }); }
Example #7
Source File: PrimaryBackupClient.java From atomix with Apache License 2.0 | 6 votes |
public PrimaryBackupClient( String clientName, PartitionId partitionId, ClusterMembershipService clusterMembershipService, PrimaryBackupClientProtocol protocol, PrimaryElection primaryElection, SessionIdService sessionIdService, ThreadContextFactory threadContextFactory, boolean closeOnStop) { this.clientName = clientName; this.partitionId = partitionId; this.clusterMembershipService = clusterMembershipService; this.protocol = protocol; this.primaryElection = primaryElection; this.sessionIdService = sessionIdService; this.threadContextFactory = threadContextFactory; this.threadContext = threadContextFactory.createContext(); this.closeOnStop = closeOnStop; }
Example #8
Source File: PrimaryBackupSessionClient.java From atomix with Apache License 2.0 | 6 votes |
public PrimaryBackupSessionClient( String clientName, PartitionId partitionId, SessionId sessionId, PrimitiveType primitiveType, PrimitiveDescriptor descriptor, ClusterMembershipService clusterMembershipService, PrimaryBackupClientProtocol protocol, PrimaryElection primaryElection, ThreadContext threadContext) { this.partitionId = checkNotNull(partitionId); this.sessionId = checkNotNull(sessionId); this.primitiveType = primitiveType; this.descriptor = descriptor; this.clusterMembershipService = clusterMembershipService; this.protocol = protocol; this.primaryElection = primaryElection; this.threadContext = threadContext; clusterMembershipService.addListener(membershipEventListener); primaryElection.addListener(primaryElectionListener); this.log = ContextualLoggerFactory.getLogger(getClass(), LoggerContext.builder(SessionClient.class) .addValue(clientName) .add("type", primitiveType.name()) .add("name", descriptor.name()) .build()); }
Example #9
Source File: DistributedLogSessionClient.java From atomix with Apache License 2.0 | 6 votes |
public DistributedLogSessionClient( String clientName, PartitionId partitionId, ClusterMembershipService clusterMembershipService, LogClientProtocol protocol, Supplier<CompletableFuture<SessionId>> sessionIdProvider, PrimaryElection primaryElection, ThreadContextFactory threadContextFactory, boolean closeOnStop) { this.clientName = clientName; this.partitionId = partitionId; this.clusterMembershipService = clusterMembershipService; this.protocol = protocol; this.sessionIdProvider = sessionIdProvider; this.primaryElection = primaryElection; this.threadContextFactory = threadContextFactory; this.threadContext = threadContextFactory.createContext(); this.closeOnStop = closeOnStop; }
Example #10
Source File: Atomix.java From atomix with Apache License 2.0 | 6 votes |
/** * Builds a partition service. */ @SuppressWarnings("unchecked") private static ManagedPartitionService buildPartitionService( AtomixConfig config, ClusterMembershipService clusterMembershipService, ClusterCommunicationService messagingService, AtomixRegistry registry) { List<ManagedPartitionGroup> partitionGroups = new ArrayList<>(); for (PartitionGroupConfig<?> partitionGroupConfig : config.getPartitionGroups().values()) { partitionGroups.add(partitionGroupConfig.getType().newPartitionGroup(partitionGroupConfig)); } return new DefaultPartitionService( clusterMembershipService, messagingService, new DefaultPrimitiveTypeRegistry(registry.getTypes(PrimitiveType.class)), buildSystemPartitionGroup(config), partitionGroups, new DefaultPartitionGroupTypeRegistry(registry.getTypes(PartitionGroup.Type.class))); }
Example #11
Source File: DefaultPartitionService.java From atomix with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public DefaultPartitionService( ClusterMembershipService membershipService, ClusterCommunicationService messagingService, PrimitiveTypeRegistry primitiveTypeRegistry, ManagedPartitionGroup systemGroup, Collection<ManagedPartitionGroup> groups, PartitionGroupTypeRegistry groupTypeRegistry) { this.clusterMembershipService = membershipService; this.communicationService = messagingService; this.primitiveTypeRegistry = primitiveTypeRegistry; this.groupMembershipService = new DefaultPartitionGroupMembershipService( membershipService, messagingService, systemGroup, groups, groupTypeRegistry); this.systemGroup = systemGroup; groups.forEach(group -> this.groups.put(group.name(), group)); }
Example #12
Source File: HashBasedPrimaryElection.java From atomix with Apache License 2.0 | 6 votes |
public HashBasedPrimaryElection( PartitionId partitionId, ClusterMembershipService clusterMembershipService, PartitionGroupMembershipService groupMembershipService, ClusterCommunicationService communicationService, ScheduledExecutorService executor) { this.partitionId = partitionId; this.clusterMembershipService = clusterMembershipService; this.groupMembershipService = groupMembershipService; this.communicationService = communicationService; this.subject = String.format("primary-election-counter-%s-%d", partitionId.group(), partitionId.id()); recomputeTerm(groupMembershipService.getMembership(partitionId.group())); groupMembershipService.addListener(groupMembershipEventListener); clusterMembershipService.addListener(clusterMembershipEventListener); communicationService.subscribe(subject, SERIALIZER::decode, this::updateCounters, executor); broadcastFuture = executor.scheduleAtFixedRate(this::broadcastCounters, BROADCAST_INTERVAL, BROADCAST_INTERVAL, TimeUnit.MILLISECONDS); }
Example #13
Source File: CorePrimitiveManagementService.java From atomix with Apache License 2.0 | 6 votes |
public CorePrimitiveManagementService( ScheduledExecutorService executorService, ClusterMembershipService membershipService, ClusterCommunicationService communicationService, ClusterEventService eventService, SerializationService serializationService, PartitionService partitionService, PrimitiveCache primitiveCache, PrimitiveRegistry primitiveRegistry, PrimitiveTypeRegistry primitiveTypeRegistry, PrimitiveProtocolTypeRegistry protocolTypeRegistry, PartitionGroupTypeRegistry partitionGroupTypeRegistry) { this.executorService = executorService; this.membershipService = membershipService; this.communicationService = communicationService; this.eventService = eventService; this.serializationService = serializationService; this.partitionService = partitionService; this.primitiveCache = primitiveCache; this.primitiveRegistry = primitiveRegistry; this.primitiveTypeRegistry = primitiveTypeRegistry; this.protocolTypeRegistry = protocolTypeRegistry; this.partitionGroupTypeRegistry = partitionGroupTypeRegistry; }
Example #14
Source File: DistributedLogSession.java From atomix with Apache License 2.0 | 6 votes |
public DistributedLogSession( PartitionId partitionId, SessionId sessionId, ClusterMembershipService clusterMembershipService, LogClientProtocol protocol, PrimaryElection primaryElection, ThreadContext threadContext) { this.partitionId = checkNotNull(partitionId, "partitionId cannot be null"); this.sessionId = checkNotNull(sessionId, "sessionId cannot be null"); this.protocol = checkNotNull(protocol, "protocol cannot be null"); this.primaryElection = checkNotNull(primaryElection, "primaryElection cannot be null"); this.threadContext = checkNotNull(threadContext, "threadContext cannot be null"); this.memberId = clusterMembershipService.getLocalMember().id(); this.subject = String.format("%s-%s-%s", partitionId.group(), partitionId.id(), sessionId); clusterMembershipService.addListener(membershipEventListener); primaryElection.addListener(primaryElectionListener); this.log = ContextualLoggerFactory.getLogger(getClass(), LoggerContext.builder(DistributedLogProducer.class) .addValue(partitionId.group() != null ? String.format("%s-%d", partitionId.group(), partitionId.id()) : partitionId.id()) .build()); }
Example #15
Source File: ClusterResource.java From atomix with Apache License 2.0 | 5 votes |
@GET @Path("/nodes/{node}") @Produces(MediaType.APPLICATION_JSON) public Response getNodeInfo(@PathParam("node") String nodeId, @Context ClusterMembershipService clusterMembershipService) { Member member = clusterMembershipService.getMember(MemberId.from(nodeId)); if (member == null) { return Response.status(Status.NOT_FOUND).build(); } return Response.ok(new NodeInfo(member)).build(); }
Example #16
Source File: ClusterResource.java From atomix with Apache License 2.0 | 5 votes |
@POST @Path("/nodes/{node}/events") @Produces(MediaType.APPLICATION_JSON) public Response addNodeListener(@PathParam("node") String memberId, @Context ClusterMembershipService clusterMembershipService, @Context EventManager events) { String id = UUID.randomUUID().toString(); EventLog<ClusterMembershipEventListener, ClusterMembershipEvent> eventLog = events.getOrCreateEventLog(ClusterResource.class, getNodeListener(memberId, id), l -> e -> { if (e.subject().id().id().equals(memberId)) { l.addEvent(e); } }); if (eventLog.open()) { clusterMembershipService.addListener(eventLog.listener()); } return Response.ok(id).build(); }
Example #17
Source File: DistributedLogServerContext.java From atomix with Apache License 2.0 | 5 votes |
public DistributedLogServerContext( String serverName, ClusterMembershipService clusterMembershipService, ManagedMemberGroupService memberGroupService, LogServerProtocol protocol, PrimaryElection primaryElection, int replicationFactor, Replication replicationStrategy, SegmentedJournal<LogEntry> journal, long maxLogSize, Duration maxLogAge, ThreadContextFactory threadContextFactory, boolean closeOnStop) { this.serverName = serverName; this.memberId = clusterMembershipService.getLocalMember().id(); this.clusterMembershipService = clusterMembershipService; this.memberGroupService = memberGroupService; this.protocol = protocol; this.replicationFactor = replicationFactor; this.replicationStrategy = replicationStrategy; this.threadContextFactory = threadContextFactory; this.threadContext = threadContextFactory.createContext(); this.closeOnStop = closeOnStop; this.journal = journal; this.writer = journal.writer(); this.reader = journal.openReader(1); this.maxLogSize = maxLogSize; this.maxLogAge = maxLogAge; this.primaryElection = primaryElection; this.log = new ContextualLogger(LoggerFactory.getLogger(getClass()), LoggerContext.builder(getClass()) .addValue(serverName) .build()); }
Example #18
Source File: ClusterResource.java From atomix with Apache License 2.0 | 5 votes |
@POST @Path("/events") @Produces(MediaType.APPLICATION_JSON) public Response addListener(@Context ClusterMembershipService clusterMembershipService, @Context EventManager events) { String listenerId = UUID.randomUUID().toString(); EventLog<ClusterMembershipEventListener, ClusterMembershipEvent> eventLog = events.getOrCreateEventLog(ClusterResource.class, listenerId, l -> e -> l.addEvent(e)); if (eventLog.open()) { clusterMembershipService.addListener(eventLog.listener()); } return Response.ok(listenerId).build(); }
Example #19
Source File: ClusterResource.java From atomix with Apache License 2.0 | 5 votes |
@DELETE @Path("/events/{id}") public void removeListener(@PathParam("id") String listenerId, @Context ClusterMembershipService clusterMembershipService, @Context EventManager events) { EventLog<ClusterMembershipEventListener, ClusterMembershipEvent> eventLog = events.removeEventLog(ClusterResource.class, listenerId); if (eventLog != null && eventLog.close()) { clusterMembershipService.removeListener(eventLog.listener()); } }
Example #20
Source File: DefaultPartitionManagementService.java From atomix with Apache License 2.0 | 5 votes |
public DefaultPartitionManagementService( ClusterMembershipService membershipService, ClusterCommunicationService communicationService, PrimitiveTypeRegistry primitiveTypes, PrimaryElectionService electionService, SessionIdService sessionIdService) { this.membershipService = membershipService; this.communicationService = communicationService; this.primitiveTypes = primitiveTypes; this.electionService = electionService; this.sessionIdService = sessionIdService; }
Example #21
Source File: ClusterResource.java From atomix with Apache License 2.0 | 5 votes |
@DELETE @Path("/nodes/{node}/events/{id}") public void removeNodeListener(@PathParam("node") String memberId, @PathParam("id") String listenerId, @Context ClusterMembershipService clusterMembershipService, @Context EventManager events) { EventLog<ClusterMembershipEventListener, ClusterMembershipEvent> eventLog = events.removeEventLog(ClusterResource.class, getNodeListener(memberId, listenerId)); if (eventLog != null && eventLog.close()) { clusterMembershipService.removeListener(eventLog.listener()); } }
Example #22
Source File: DefaultClusterCommunicationService.java From atomix with Apache License 2.0 | 5 votes |
public DefaultClusterCommunicationService( ClusterMembershipService membershipService, MessagingService messagingService, UnicastService unicastService) { this.membershipService = checkNotNull(membershipService, "clusterService cannot be null"); this.messagingService = checkNotNull(messagingService, "messagingService cannot be null"); this.unicastService = checkNotNull(unicastService, "unicastService cannot be null"); }
Example #23
Source File: DefaultClusterMembershipService.java From atomix with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<ClusterMembershipService> start() { if (started.compareAndSet(false, true)) { protocol.addListener(membershipEventListener); return discoveryService.start().thenCompose(v -> { localMember.setActive(true); localMember.setReachable(true); return protocol.join(bootstrapService, discoveryService, localMember); }).thenApply(v -> { LOGGER.info("Started"); return this; }); } return CompletableFuture.completedFuture(null); }
Example #24
Source File: CorePrimitivesService.java From atomix with Apache License 2.0 | 5 votes |
public CorePrimitivesService( ScheduledExecutorService executorService, ClusterMembershipService membershipService, ClusterCommunicationService communicationService, ClusterEventService eventService, SerializationService serializationService, PartitionService partitionService, PrimitiveCache primitiveCache, AtomixRegistry registry, ConfigService configService) { this.cache = checkNotNull(primitiveCache); this.registry = checkNotNull(registry); this.primitiveRegistry = new CorePrimitiveRegistry(partitionService, new DefaultPrimitiveTypeRegistry(registry.getTypes(PrimitiveType.class))); this.managementService = new CorePrimitiveManagementService( executorService, membershipService, communicationService, eventService, serializationService, partitionService, primitiveCache, primitiveRegistry, new DefaultPrimitiveTypeRegistry(registry.getTypes(PrimitiveType.class)), new DefaultPrimitiveProtocolTypeRegistry(registry.getTypes(PrimitiveProtocol.Type.class)), new DefaultPartitionGroupTypeRegistry(registry.getTypes(PartitionGroup.Type.class))); this.transactionService = new CoreTransactionService(managementService); this.configService = checkNotNull(configService); }
Example #25
Source File: RaftServiceManagerTest.java From atomix with Apache License 2.0 | 5 votes |
@Before public void setupContext() throws IOException { deleteStorage(); RaftStorage storage = RaftStorage.builder() .withPrefix("test") .withDirectory(PATH.toFile()) .withNamespace(NAMESPACE) .build(); PrimitiveTypeRegistry registry = new PrimitiveTypeRegistry() { @Override public Collection<PrimitiveType> getPrimitiveTypes() { return Collections.singleton(new TestType()); } @Override public PrimitiveType getPrimitiveType(String typeName) { return new TestType(); } }; raft = new RaftContext( "test", MemberId.from("test-1"), mock(ClusterMembershipService.class), mock(RaftServerProtocol.class), storage, registry, ThreadModel.SHARED_THREAD_POOL.factory("raft-server-test-%d", 1, LoggerFactory.getLogger(RaftServer.class)), true); snapshotTaken = new AtomicBoolean(); snapshotInstalled = new AtomicBoolean(); }
Example #26
Source File: RaftTest.java From atomix with Apache License 2.0 | 5 votes |
private RaftServer createServer(MemberId memberId, Function<RaftServer.Builder, RaftServer.Builder> configurator) { final RaftServer.Builder defaults = RaftServer.builder(memberId) .withMembershipService(mock(ClusterMembershipService.class)) .withProtocol(protocolFactory.newServerProtocol(memberId)); final RaftServer server = configurator.apply(defaults).build(); servers.add(server); return server; }
Example #27
Source File: DefaultPartitionGroupMembershipService.java From atomix with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public DefaultPartitionGroupMembershipService( ClusterMembershipService membershipService, ClusterCommunicationService messagingService, ManagedPartitionGroup systemGroup, Collection<ManagedPartitionGroup> groups, PartitionGroupTypeRegistry groupTypeRegistry) { this.membershipService = membershipService; this.messagingService = messagingService; this.systemGroup = systemGroup != null ? new PartitionGroupMembership( systemGroup.name(), systemGroup.config(), ImmutableSet.of(membershipService.getLocalMember().id()), true) : null; groups.forEach(group -> { this.groups.put(group.name(), new PartitionGroupMembership( group.name(), group.config(), ImmutableSet.of(membershipService.getLocalMember().id()), false)); }); Namespace.Builder namespaceBuilder = Namespace.builder() .register(Namespaces.BASIC) .register(MemberId.class) .register(PartitionGroupMembership.class) .register(PartitionGroupInfo.class) .register(PartitionGroupConfig.class) .register(MemberGroupStrategy.class); List<PartitionGroup.Type> groupTypes = Lists.newArrayList(groupTypeRegistry.getGroupTypes()); groupTypes.sort(Comparator.comparing(PartitionGroup.Type::name)); for (PartitionGroup.Type groupType : groupTypes) { namespaceBuilder.register(groupType.namespace()); } serializer = Serializer.using(namespaceBuilder.build()); }
Example #28
Source File: PrimaryBackupServiceContext.java From atomix with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public PrimaryBackupServiceContext( String serverName, PrimitiveId primitiveId, PrimitiveType primitiveType, PrimitiveDescriptor descriptor, ThreadContext threadContext, ClusterMembershipService clusterMembershipService, MemberGroupService memberGroupService, PrimaryBackupServerProtocol protocol, PrimaryElection primaryElection) { this.localMemberId = clusterMembershipService.getLocalMember().id(); this.serverName = checkNotNull(serverName); this.primitiveId = checkNotNull(primitiveId); this.primitiveType = checkNotNull(primitiveType); this.serviceConfig = Serializer.using(primitiveType.namespace()).decode(descriptor.config()); this.descriptor = checkNotNull(descriptor); this.service = primitiveType.newService(serviceConfig); this.threadContext = checkNotNull(threadContext); this.clusterMembershipService = checkNotNull(clusterMembershipService); this.memberGroupService = checkNotNull(memberGroupService); this.protocol = checkNotNull(protocol); this.primaryElection = checkNotNull(primaryElection); this.log = ContextualLoggerFactory.getLogger(getClass(), LoggerContext.builder(PrimitiveService.class) .addValue(serverName) .add("type", descriptor.type()) .add("name", descriptor.name()) .build()); clusterMembershipService.addListener(membershipEventListener); primaryElection.addListener(primaryElectionListener); }
Example #29
Source File: CorePrimitiveManagementService.java From atomix with Apache License 2.0 | 4 votes |
@Override public ClusterMembershipService getMembershipService() { return membershipService; }
Example #30
Source File: ClusterResource.java From atomix with Apache License 2.0 | 4 votes |
@GET @Path("/node") @Produces(MediaType.APPLICATION_JSON) public Response getNode(@Context ClusterMembershipService clusterMembershipService) { return Response.ok(new NodeInfo(clusterMembershipService.getLocalMember())).build(); }