io.atomix.protocols.raft.MultiRaftProtocol Java Examples

The following examples show how to use io.atomix.protocols.raft.MultiRaftProtocol. 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: ClusterConfig.java    From yfs with Apache License 2.0 6 votes vote down vote up
public ClusterConfig() {
    this.clusterProperties = getClusterProperties();
    Member m = gatewayMember.apply(clusterProperties);
    List<Member> ms = gatewayMembers.apply(clusterProperties);
    Atomix atomix = Atomix.builder()
            .withMemberId(clusterProperties.getLocal())
            .withAddress(m.address())
            .withMembershipProvider(BootstrapDiscoveryProvider.builder()
                    .withNodes((Collection) ms)
                    .build())
            .withManagementGroup(gatewayManagementGroup.apply(clusterProperties))
            .withPartitionGroups(gatewayDataGroup.apply(clusterProperties))
            .withZone(CommonConstant.gatewayZone)
            .build();
    atomix.start().join();
    this.atomicMap = atomix.<String, StoreInfo>atomicMapBuilder(CommonConstant.storeInfoMapName)
            .withProtocol(MultiRaftProtocol.builder()
                    .withReadConsistency(ReadConsistency.LINEARIZABLE)
                    .build())
            .withSerializer(CommonConstant.protocolSerializer)
            .build();
    ;
    this.atomix = atomix;
    LOGGER.info("Atomix[{},{}]启动成功", m.id(), m.address().toString());
}
 
Example #2
Source File: YfsConfig.java    From yfs with Apache License 2.0 6 votes vote down vote up
@Bean(name = "gatewayAtomix")
public Atomix getGatewayAtomix() {
    List<Member> ms = gatewayMembers.apply(clusterProperties);
    Atomix atomix = Atomix.builder()
            .withMemberId(clusterProperties.getLocal())
            .withAddress(clusterProperties.getGateway().getIp(), clusterProperties.getGateway().getPort())
            .withMembershipProvider(BootstrapDiscoveryProvider.builder()
                    .withNodes((Collection) ms)
                    .build())
            .withProfiles(Profile.client())
            .withZone(CommonConstant.storeZone)
            .withRack(clusterProperties.getGroup())
            .build();

    atomix.start().join();
    storeInfoMap = atomix.<String, StoreInfo>atomicMapBuilder(CommonConstant.storeInfoMapName)
            .withProtocol(MultiRaftProtocol.builder()
                    .withReadConsistency(ReadConsistency.LINEARIZABLE)
                    .build())
            .withSerializer(CommonConstant.protocolSerializer)
            .build();
    return atomix;
}
 
Example #3
Source File: SimpleRegistryTest.java    From atomix with Apache License 2.0 6 votes vote down vote up
@Test
public void testStaticRegistryBuilder() throws Exception {
  AtomixRegistry registry = SimpleRegistry.builder()
      .addProfileType(ConsensusProfile.TYPE)
      .addDiscoveryProviderType(BootstrapDiscoveryProvider.TYPE)
      .addPrimitiveType(AtomicCounterType.instance())
      .addProtocolType(MultiRaftProtocol.TYPE)
      .addPartitionGroupType(RaftPartitionGroup.TYPE)
      .build();

  assertEquals(ConsensusProfile.TYPE, registry.getType(Profile.Type.class, "consensus"));
  assertEquals(BootstrapDiscoveryProvider.TYPE, registry.getType(NodeDiscoveryProvider.Type.class, "bootstrap"));
  assertEquals(AtomicCounterType.instance(), registry.getType(PrimitiveType.class, "atomic-counter"));
  assertEquals(MultiRaftProtocol.TYPE, registry.getType(PrimitiveProtocol.Type.class, "multi-raft"));
  assertEquals(RaftPartitionGroup.TYPE, registry.getType(PartitionGroup.Type.class, "raft"));
}
 
Example #4
Source File: AtomixConsistentMultimapBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncConsistentMultimap<K, V> buildMultimap() {
    return new AtomixConsistentMultimap<>(atomix.<K, V>atomicMultimapBuilder(name())
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withCacheEnabled(relaxedReadConsistency())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #5
Source File: AtomixAtomicIdGeneratorBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncAtomicIdGenerator build() {
    return new AtomixAtomicIdGenerator(atomix.atomicIdGeneratorBuilder(name())
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #6
Source File: AtomixLeaderElectorBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncLeaderElector build() {
    Serializer serializer = Serializer.using(KryoNamespaces.API);
    return new AtomixLeaderElector(atomix.<NodeId>leaderElectorBuilder(name())
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .withMaxTimeout(Duration.ofMillis(electionTimeoutMillis()))
            .build())
        .withReadOnly(readOnly())
        .withCacheEnabled(relaxedReadConsistency())
        .withSerializer(new AtomixSerializerAdapter(serializer))
        .build()
        .async(), localNodeId);
}
 
Example #7
Source File: AtomixAtomicValueBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncAtomicValue<V> build() {
    return new AtomixAtomicValue<V>(atomix.<V>atomicValueBuilder(name())
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #8
Source File: AtomixWorkQueueBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public WorkQueue<E> build() {
    return new AtomixWorkQueue<>(atomix.<E>workQueueBuilder(name())
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #9
Source File: AtomixDistributedTopicBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Topic<T> build() {
    return new AtomixDistributedTopic<>(atomix.<T>atomicValueBuilder(name())
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #10
Source File: AtomixDocumentTreeBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncDocumentTree<V> buildDocumentTree() {
    return new AtomixDocumentTree<>(atomix.<V>atomicDocumentTreeBuilder(name())
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withCacheEnabled(relaxedReadConsistency())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #11
Source File: AtomixDistributedLockBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncDistributedLock build() {
    return new AtomixDistributedLock(atomix.atomicLockBuilder(name())
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #12
Source File: AtomixAtomicCounterMapBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncAtomicCounterMap<K> buildAsyncMap() {
    return new AtomixAtomicCounterMap<K>(atomix.<K>atomicCounterMapBuilder(name())
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #13
Source File: AtomixAtomicCounterBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncAtomicCounter build() {
    return new AtomixAtomicCounter(atomix.atomicCounterBuilder(name())
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #14
Source File: AtomixConsistentTreeMapBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncConsistentTreeMap<V> buildTreeMap() {
    return new AtomixConsistentTreeMap<>(atomix.<String, V>atomicNavigableMapBuilder(name())
        .withRegistrationRequired()
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withCacheEnabled(relaxedReadConsistency())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #15
Source File: AtomixTransactionContext.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> TransactionalMap<K, V> getTransactionalMap(String mapName, Serializer serializer) {
    return new AtomixTransactionalMap<>(atomixTransaction.<K, V>mapBuilder(mapName)
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withSerializer(new AtomixSerializerAdapter(serializer))
        .get());
}
 
Example #16
Source File: AtomixDistributedSetBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncDistributedSet<E> build() {
    return new AtomixDistributedSet<E>(atomix.<E>setBuilder(name())
        .withRegistrationRequired()
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        // TODO: Enable caching for DistributedSet in Atomix
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #17
Source File: AtomixConsistentMapBuilder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncConsistentMap<K, V> buildAsyncMap() {
    return new AtomixConsistentMap<>(atomix.<K, V>atomicMapBuilder(name())
        .withRegistrationRequired()
        .withProtocol(MultiRaftProtocol.builder(group)
            .withRecoveryStrategy(Recovery.RECOVER)
            .withMaxRetries(MAX_RETRIES)
            .build())
        .withReadOnly(readOnly())
        .withCacheEnabled(relaxedReadConsistency())
        .withSerializer(new AtomixSerializerAdapter(serializer()))
        .build()
        .async());
}
 
Example #18
Source File: RaftPartitionGroup.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Override
public ProxyProtocol newProtocol() {
  return MultiRaftProtocol.builder(name)
      .withRecoveryStrategy(Recovery.RECOVER)
      .withMaxRetries(5)
      .build();
}
 
Example #19
Source File: PartitionManager.java    From onos with Apache License 2.0 4 votes vote down vote up
@Activate
public void activate() {
    partitionGroup = atomixManager.getAtomix().getPartitionService().getPartitionGroup(MultiRaftProtocol.TYPE);
    eventDispatcher.addSink(PartitionEvent.class, listenerRegistry);
    log.info("Started");
}
 
Example #20
Source File: StorageManager.java    From onos with Apache License 2.0 4 votes vote down vote up
@Activate
public void activate() {
    atomix = atomixManager.getAtomix();
    group = atomix.getPartitionService().getPartitionGroup(MultiRaftProtocol.TYPE);
    log.info("Started");
}
 
Example #21
Source File: RaftPartitionGroup.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public PrimitiveProtocol.Type protocol() {
  return MultiRaftProtocol.TYPE;
}