Search in sources :

Example 16 with NodeId

use of io.atomix.cluster.NodeId in project atomix by atomix.

the class RaftTest method createClient.

/**
 * Creates a Raft client.
 */
private RaftClient createClient() throws Throwable {
    NodeId nodeId = nextNodeId();
    RaftClient client = RaftClient.builder().withNodeId(nodeId).withProtocol(protocolFactory.newClientProtocol(nodeId)).build();
    client.connect(members.stream().map(RaftMember::nodeId).collect(Collectors.toList())).thenRun(this::resume);
    await(30000);
    clients.add(client);
    return client;
}
Also used : NodeId(io.atomix.cluster.NodeId)

Example 17 with NodeId

use of io.atomix.cluster.NodeId in project atomix by atomix.

the class ClusterMessage method fromBytes.

/**
 * Decodes a new ClusterMessage from raw bytes.
 *
 * @param bytes raw bytes
 * @return cluster message
 */
public static ClusterMessage fromBytes(byte[] bytes) {
    ByteBuffer buffer = ByteBuffer.wrap(bytes);
    byte[] senderBytes = new byte[buffer.getInt()];
    buffer.get(senderBytes);
    byte[] subjectBytes = new byte[buffer.getInt()];
    buffer.get(subjectBytes);
    byte[] payloadBytes = new byte[buffer.getInt()];
    buffer.get(payloadBytes);
    return new ClusterMessage(new NodeId(new String(senderBytes, StandardCharsets.UTF_8)), new String(subjectBytes, StandardCharsets.UTF_8), payloadBytes);
}
Also used : NodeId(io.atomix.cluster.NodeId) ByteBuffer(java.nio.ByteBuffer)

Aggregations

NodeId (io.atomix.cluster.NodeId)17 CompletableFuture (java.util.concurrent.CompletableFuture)7 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)5 Collection (java.util.Collection)5 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)4 Futures (io.atomix.utils.concurrent.Futures)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 Map (java.util.Map)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Logger (org.slf4j.Logger)4 RaftError (io.atomix.protocols.raft.RaftError)3 RaftServer (io.atomix.protocols.raft.RaftServer)3 RaftCluster (io.atomix.protocols.raft.cluster.RaftCluster)3 RaftClusterEvent (io.atomix.protocols.raft.cluster.RaftClusterEvent)3 RaftClusterEventListener (io.atomix.protocols.raft.cluster.RaftClusterEventListener)3 RaftMember (io.atomix.protocols.raft.cluster.RaftMember)3 RaftContext (io.atomix.protocols.raft.impl.RaftContext)3 JoinRequest (io.atomix.protocols.raft.protocol.JoinRequest)3