io.atomix.protocols.raft.protocol.RaftClientProtocol Java Examples

The following examples show how to use io.atomix.protocols.raft.protocol.RaftClientProtocol. 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: DefaultRaftSessionClient.java    From atomix with Apache License 2.0 6 votes vote down vote up
public DefaultRaftSessionClient(
    String serviceName,
    PrimitiveType primitiveType,
    ServiceConfig serviceConfig,
    PartitionId partitionId,
    RaftClientProtocol protocol,
    MemberSelectorManager selectorManager,
    RaftSessionManager sessionManager,
    ReadConsistency readConsistency,
    CommunicationStrategy communicationStrategy,
    ThreadContext context,
    Duration minTimeout,
    Duration maxTimeout) {
  this.serviceName = checkNotNull(serviceName, "serviceName cannot be null");
  this.primitiveType = checkNotNull(primitiveType, "serviceType cannot be null");
  this.serviceConfig = checkNotNull(serviceConfig, "serviceConfig cannot be null");
  this.partitionId = checkNotNull(partitionId, "partitionId cannot be null");
  this.protocol = checkNotNull(protocol, "protocol cannot be null");
  this.selectorManager = checkNotNull(selectorManager, "selectorManager cannot be null");
  this.readConsistency = checkNotNull(readConsistency, "readConsistency cannot be null");
  this.communicationStrategy = checkNotNull(communicationStrategy, "communicationStrategy cannot be null");
  this.context = checkNotNull(context, "context cannot be null");
  this.minTimeout = checkNotNull(minTimeout, "minTimeout cannot be null");
  this.maxTimeout = checkNotNull(maxTimeout, "maxTimeout cannot be null");
  this.sessionManager = checkNotNull(sessionManager, "sessionManager cannot be null");
}
 
Example #2
Source File: RaftSessionManager.java    From atomix with Apache License 2.0 6 votes vote down vote up
public RaftSessionManager(String clientId, MemberId memberId, RaftClientProtocol protocol, MemberSelectorManager selectorManager, ThreadContextFactory threadContextFactory) {
  this.clientId = checkNotNull(clientId, "clientId cannot be null");
  this.memberId = checkNotNull(memberId, "memberId cannot be null");
  this.protocol = checkNotNull(protocol, "protocol cannot be null");
  this.selectorManager = checkNotNull(selectorManager, "selectorManager cannot be null");
  this.threadContext = threadContextFactory.createContext();
  this.log = ContextualLoggerFactory.getLogger(getClass(), LoggerContext.builder(RaftClient.class)
      .addValue(clientId)
      .build());

  this.connection = new RaftSessionConnection(
      protocol,
      selectorManager.createSelector(CommunicationStrategy.LEADER),
      threadContextFactory.createContext(),
      LoggerContext.builder(RaftClient.class)
          .addValue(clientId)
          .build());
  protocol.registerHeartbeatHandler(this::handleHeartbeat);
  this.threadContextFactory = checkNotNull(threadContextFactory, "threadContextFactory cannot be null");
}
 
Example #3
Source File: DefaultRaftClient.java    From atomix with Apache License 2.0 6 votes vote down vote up
public DefaultRaftClient(
    String clientId,
    PartitionId partitionId,
    MemberId memberId,
    Collection<MemberId> cluster,
    RaftClientProtocol protocol,
    ThreadContextFactory threadContextFactory,
    boolean closeThreadFactoryOnClose) {
  this.clientId = checkNotNull(clientId, "clientId cannot be null");
  this.partitionId = checkNotNull(partitionId, "partitionId cannot be null");
  this.cluster = checkNotNull(cluster, "cluster cannot be null");
  this.protocol = checkNotNull(protocol, "protocol cannot be null");
  this.threadContextFactory = checkNotNull(threadContextFactory, "threadContextFactory cannot be null");
  this.threadContext = threadContextFactory.createContext();
  this.metadata = new DefaultRaftMetadataClient(clientId, protocol, selectorManager, threadContextFactory.createContext());
  this.sessionManager = new RaftSessionManager(clientId, memberId, protocol, selectorManager, threadContextFactory);
  this.closeThreadFactoryOnClose = closeThreadFactoryOnClose;
}
 
Example #4
Source File: RaftPerformanceTest.java    From atomix with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Raft client.
 */
private RaftClient createClient() throws Exception {
  Member member = nextNode();

  RaftClientProtocol protocol;
  if (USE_NETTY) {
    MessagingService messagingService = new NettyMessagingService("test", member.address(), new MessagingConfig()).start().join();
    protocol = new RaftClientMessagingProtocol(messagingService, PROTOCOL_SERIALIZER, addressMap::get);
  } else {
    protocol = protocolFactory.newClientProtocol(member.id());
  }

  RaftClient client = RaftClient.builder()
      .withMemberId(member.id())
      .withPartitionId(PartitionId.from("test", 1))
      .withProtocol(protocol)
      .withThreadModel(ThreadModel.SHARED_THREAD_POOL)
      .build();

  client.connect(members.stream().map(Member::id).collect(Collectors.toList())).join();
  clients.add(client);
  return client;
}
 
Example #5
Source File: RaftFuzzTest.java    From atomix with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Raft client.
 */
private RaftClient createClient() throws Exception {
  MemberId memberId = nextNodeId();

  RaftClientProtocol protocol;
  if (USE_NETTY) {
    Address address = Address.from(++port);
    MessagingService messagingManager = new NettyMessagingService("test", address, new MessagingConfig()).start().join();
    addressMap.put(memberId, address);
    protocol = new RaftClientMessagingProtocol(messagingManager, PROTOCOL_SERIALIZER, addressMap::get);
  } else {
    protocol = protocolFactory.newClientProtocol(memberId);
  }

  RaftClient client = RaftClient.builder()
      .withMemberId(memberId)
      .withProtocol(protocol)
      .build();

  client.connect(members.stream().map(RaftMember::memberId).collect(Collectors.toList())).join();
  clients.add(client);
  return client;
}
 
Example #6
Source File: RaftSessionListener.java    From atomix with Apache License 2.0 5 votes vote down vote up
RaftSessionListener(RaftClientProtocol protocol, MemberSelector memberSelector, RaftSessionState state, RaftSessionSequencer sequencer, Executor executor) {
  this.protocol = checkNotNull(protocol, "protocol cannot be null");
  this.memberSelector = checkNotNull(memberSelector, "nodeSelector cannot be null");
  this.state = checkNotNull(state, "state cannot be null");
  this.sequencer = checkNotNull(sequencer, "sequencer cannot be null");
  this.executor = checkNotNull(executor, "executor cannot be null");
  this.log = ContextualLoggerFactory.getLogger(getClass(), LoggerContext.builder(SessionClient.class)
      .addValue(state.getSessionId())
      .add("type", state.getPrimitiveType())
      .add("name", state.getPrimitiveName())
      .build());
  protocol.registerPublishListener(state.getSessionId(), this::handlePublish, executor);
}
 
Example #7
Source File: RaftPartitionClient.java    From atomix with Apache License 2.0 5 votes vote down vote up
public RaftPartitionClient(
    RaftPartition partition,
    MemberId localMemberId,
    RaftClientProtocol protocol,
    ThreadContextFactory threadContextFactory) {
  this.partition = partition;
  this.localMemberId = localMemberId;
  this.protocol = protocol;
  this.threadContextFactory = threadContextFactory;
}
 
Example #8
Source File: RaftPartitionClient.java    From atomix with Apache License 2.0 5 votes vote down vote up
private RaftClient newRaftClient(RaftClientProtocol protocol) {
  return RaftClient.builder()
      .withClientId(partition.name())
      .withPartitionId(partition.id())
      .withMemberId(localMemberId)
      .withProtocol(protocol)
      .withThreadContextFactory(threadContextFactory)
      .build();
}
 
Example #9
Source File: DefaultRaftMetadataClient.java    From atomix with Apache License 2.0 5 votes vote down vote up
public DefaultRaftMetadataClient(String clientId, RaftClientProtocol protocol, MemberSelectorManager selectorManager, ThreadContext context) {
  this.selectorManager = checkNotNull(selectorManager, "selectorManager cannot be null");
  this.connection = new RaftSessionConnection(
      protocol,
      selectorManager.createSelector(CommunicationStrategy.LEADER),
      context,
      LoggerContext.builder(RaftClient.class)
          .addValue(clientId)
          .build());
}
 
Example #10
Source File: RaftSessionConnection.java    From atomix with Apache License 2.0 4 votes vote down vote up
public RaftSessionConnection(RaftClientProtocol protocol, MemberSelector selector, ThreadContext context, LoggerContext loggerContext) {
  this.protocol = checkNotNull(protocol, "protocol cannot be null");
  this.selector = checkNotNull(selector, "selector cannot be null");
  this.context = checkNotNull(context, "context cannot be null");
  this.log = ContextualLoggerFactory.getLogger(getClass(), loggerContext);
}
 
Example #11
Source File: LocalRaftProtocolFactory.java    From submarine with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a new test client protocol.
 *
 * @param memberId the client member identifier
 * @return a new test client protocol
 */
public RaftClientProtocol newClientProtocol(MemberId memberId) {
  return new LocalRaftClientProtocol(memberId, serializer, servers, clients);
}
 
Example #12
Source File: LocalRaftProtocolFactory.java    From zeppelin with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a new test client protocol.
 *
 * @param memberId the client member identifier
 * @return a new test client protocol
 */
public RaftClientProtocol newClientProtocol(MemberId memberId) {
  return new LocalRaftClientProtocol(memberId, serializer, servers, clients);
}
 
Example #13
Source File: RaftClient.java    From atomix with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the client protocol.
 *
 * @param protocol the client protocol
 * @return the client builder
 * @throws NullPointerException if the protocol is null
 */
public Builder withProtocol(RaftClientProtocol protocol) {
  this.protocol = checkNotNull(protocol, "protocol cannot be null");
  return this;
}
 
Example #14
Source File: LocalRaftProtocolFactory.java    From atomix with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a new test client protocol.
 *
 * @param memberId the client member identifier
 * @return a new test client protocol
 */
public RaftClientProtocol newClientProtocol(MemberId memberId) {
  return new LocalRaftClientProtocol(memberId, serializer, servers, clients);
}