Tabnine Logo
RaftClient
Code IndexAdd Tabnine to your IDE (free)

How to use
RaftClient
in
io.atomix.protocols.raft

Best Java code snippets using io.atomix.protocols.raft.RaftClient (Showing top 19 results out of 315)

origin: atomix/atomix

/**
 * Returns a new Raft client builder.
 * <p>
 * The provided set of members will be used to connect to the Raft cluster. The members list does not have to represent
 * the complete list of servers in the cluster, but it must have at least one reachable member that can communicate with
 * the cluster's leader.
 *
 * @return The client builder.
 */
@SuppressWarnings("unchecked")
static Builder builder() {
 return builder(Collections.EMPTY_LIST);
}
origin: atomix/atomix

@Override
public CompletableFuture<Void> stop() {
 return client != null ? client.close() : CompletableFuture.completedFuture(null);
}
origin: atomix/atomix

/**
 * Connects the client to Raft cluster via the default server address.
 * <p>
 * If the client was built with a default cluster list, the default server addresses will be used. Otherwise, the client
 * will attempt to connect to localhost:8700.
 * <p>
 * The client will connect to servers in the cluster according to the pattern specified by the configured
 * {@link CommunicationStrategy}.
 *
 * @return A completable future to be completed once the client is registered.
 */
default CompletableFuture<RaftClient> connect() {
 return connect((Collection<MemberId>) null);
}
origin: atomix/atomix

/**
 * 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;
}
origin: atomix/atomix

@Override
public RaftSessionClient.Builder sessionBuilder(String primitiveName, PrimitiveType primitiveType, ServiceConfig serviceConfig) {
 return client.sessionBuilder(primitiveName, primitiveType, serviceConfig);
}
origin: atomix/atomix

/**
 * Returns the partition leader.
 *
 * @return the partition leader
 */
public MemberId leader() {
 return client != null ? client.leader() : null;
}
origin: atomix/atomix

/**
 * Returns the partition term.
 *
 * @return the partition term
 */
public long term() {
 return client != null ? client.term() : 0;
}
origin: apache/zeppelin

 @Override
 public void run() {
  LOGGER.info("RaftClientThread run() >>>");
  int raftClientPort = 0;
  try {
   raftClientPort = RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces();
  } catch (IOException e) {
   LOGGER.error(e.getMessage());
  }
  MemberId memberId = MemberId.from(ZEPL_CLIENT_ID + zeplServerHost + ":" + raftClientPort);
  Address address = Address.from(zeplServerHost, raftClientPort);
  raftAddressMap.put(memberId, address);
  MessagingService messagingManager
    = NettyMessagingService.builder().withAddress(address).build().start().join();
  RaftClientProtocol protocol = new RaftClientMessagingProtocol(
    messagingManager, protocolSerializer, raftAddressMap::get);
  raftClient = RaftClient.builder()
    .withMemberId(memberId)
    .withPartitionId(PartitionId.from("partition", 1))
    .withProtocol(protocol)
    .build();
  raftClient.connect(clusterMemberIds).join();
  raftSessionClient = createProxy(raftClient);
  LOGGER.info("RaftClientThread run() <<<");
 }
}).start();
origin: apache/zeppelin

private SessionClient createProxy(RaftClient client) {
 return client.sessionBuilder(ClusterPrimitiveType.PRIMITIVE_NAME,
   ClusterPrimitiveType.INSTANCE, new ServiceConfig())
   .withReadConsistency(ReadConsistency.SEQUENTIAL)
   .withCommunicationStrategy(CommunicationStrategy.LEADER)
   .build()
   .connect()
   .join();
}
origin: atomix/atomix

/**
 * 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;
}
origin: atomix/atomix

/**
 * Creates a test session.
 */
private SessionClient createProxy(RaftClient client, ReadConsistency consistency) {
 return client.sessionBuilder("raft-fuzz-test", TestPrimitiveType.INSTANCE, new ServiceConfig())
   .withReadConsistency(consistency)
   .withCommunicationStrategy(COMMUNICATION_STRATEGY)
   .build()
   .connect()
   .join();
}
origin: apache/zeppelin

public void shutdown() {
 if (!zconf.isClusterMode()) {
  return;
 }
 running.set(false);
 try {
  if (null != raftSessionClient) {
   raftSessionClient.close().get(3, TimeUnit.SECONDS);
  }
  if (null != raftClient) {
   raftClient.close().get(3, TimeUnit.SECONDS);
  }
 } catch (InterruptedException e) {
  LOGGER.error(e.getMessage());
 } catch (ExecutionException e) {
  LOGGER.error(e.getMessage());
 } catch (TimeoutException e) {
  LOGGER.error(e.getMessage());
 }
}
origin: atomix/atomix

/**
 * Returns a new Raft client builder.
 * <p>
 * The provided set of members will be used to connect to the Raft cluster. The members list does not have to represent
 * the complete list of servers in the cluster, but it must have at least one reachable member that can communicate with
 * the cluster's leader.
 *
 * @param cluster The cluster to which to connect.
 * @return The client builder.
 */
static Builder builder(MemberId... cluster) {
 return builder(Arrays.asList(cluster));
}
origin: atomix/atomix

/**
 * Connects the client to Raft cluster via the provided server addresses.
 * <p>
 * The client will connect to servers in the cluster according to the pattern specified by the configured
 * {@link CommunicationStrategy}.
 *
 * @param members A set of server addresses to which to connect.
 * @return A completable future to be completed once the client is registered.
 */
default CompletableFuture<RaftClient> connect(MemberId... members) {
 if (members == null || members.length == 0) {
  return connect();
 } else {
  return connect(Arrays.asList(members));
 }
}
origin: atomix/atomix

/**
 * Creates a test session.
 */
private SessionClient createProxy(RaftClient client) {
 return client.sessionBuilder("raft-performance-test", TestPrimitiveType.INSTANCE, new ServiceConfig())
   .withReadConsistency(READ_CONSISTENCY)
   .withCommunicationStrategy(COMMUNICATION_STRATEGY)
   .build();
}
origin: atomix/atomix

clients.forEach(c -> {
 try {
  c.close().get(10, TimeUnit.SECONDS);
 } catch (Exception e) {
origin: atomix/atomix

 private RaftClient newRaftClient(RaftClientProtocol protocol) {
  return RaftClient.builder()
    .withClientId(partition.name())
    .withPartitionId(partition.id())
    .withMemberId(localMemberId)
    .withProtocol(protocol)
    .withThreadContextFactory(threadContextFactory)
    .build();
 }
}
origin: atomix/atomix

@Override
public CompletableFuture<RaftPartitionClient> start() {
 synchronized (RaftPartitionClient.this) {
  client = newRaftClient(protocol);
 }
 return client.connect(partition.members()).whenComplete((r, e) -> {
  if (e == null) {
   log.debug("Successfully started client for partition {}", partition.id());
  } else {
   log.warn("Failed to start client for partition {}", partition.id(), e);
  }
 }).thenApply(v -> null);
}
origin: atomix/atomix

 c.close().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
io.atomix.protocols.raftRaftClient

Javadoc

Provides an interface for submitting operations to the Raft cluster.

Most used methods

  • builder
    Returns a new Raft client builder. The provided set of members will be used to connect to the Raft c
  • close
    Closes the client.
  • connect
    Connects the client to Raft cluster via the provided server addresses. The client will connect to se
  • sessionBuilder
    Builds a Raft proxy session.
  • leader
    Returns the current leader.
  • term
    Returns the current term.

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • getExternalFilesDir (Context)
  • onRequestPermissionsResult (Fragment)
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • BoxLayout (javax.swing)
  • JButton (javax.swing)
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Join (org.hibernate.mapping)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now