本文整理汇总了Java中io.atomix.messaging.Endpoint类的典型用法代码示例。如果您正苦于以下问题:Java Endpoint类的具体用法?Java Endpoint怎么用?Java Endpoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Endpoint类属于io.atomix.messaging包,在下文中一共展示了Endpoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAtomix
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
/**
* Creates an Atomix instance.
*/
private Atomix createAtomix(Node.Type type, int id, Integer... ids) {
Node localNode = Node.builder(String.valueOf(id))
.withType(type)
.withEndpoint(endpoints.computeIfAbsent(id, i -> Endpoint.from("localhost", findAvailablePort(BASE_PORT + id))))
.build();
Collection<Node> bootstrapNodes = Stream.of(ids)
.map(nodeId -> Node.builder(String.valueOf(nodeId))
.withType(Node.Type.DATA)
.withEndpoint(endpoints.computeIfAbsent(nodeId, i -> Endpoint.from("localhost", findAvailablePort(BASE_PORT + nodeId))))
.build())
.collect(Collectors.toList());
return new TestAtomix.Builder()
.withClusterName("test")
.withDataDirectory(new File("target/test-logs/" + id))
.withLocalNode(localNode)
.withBootstrapNodes(bootstrapNodes)
.withCoordinationPartitions(3)
.withDataPartitions(3) // Lower number of partitions for faster testing
.build();
}
示例2: createClient
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
/**
* Creates a Raft client.
*/
private RaftClient createClient() throws Exception {
NodeId nodeId = nextNodeId();
RaftClientProtocol protocol;
if (USE_NETTY) {
Endpoint endpoint = new Endpoint(InetAddress.getLocalHost(), ++port);
MessagingService messagingService = NettyMessagingService.builder().withEndpoint(endpoint).build().start().join();
endpointMap.put(nodeId, endpoint);
protocol = new RaftClientMessagingProtocol(messagingService, protocolSerializer, endpointMap::get);
} else {
protocol = protocolFactory.newClientProtocol(nodeId);
}
RaftClient client = RaftClient.builder()
.withNodeId(nodeId)
.withProtocol(protocol)
.withThreadModel(ThreadModel.THREAD_PER_SERVICE)
.build();
client.connect(members).join();
clients.add(client);
return client;
}
示例3: createClient
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
/**
* Creates a Raft client.
*/
private RaftClient createClient() throws Exception {
NodeId nodeId = nextNodeId();
RaftClientProtocol protocol;
if (USE_NETTY) {
Endpoint endpoint = new Endpoint(InetAddress.getLocalHost(), ++port);
MessagingService messagingManager = NettyMessagingService.builder().withEndpoint(endpoint).build().start().join();
endpointMap.put(nodeId, endpoint);
protocol = new RaftClientMessagingProtocol(messagingManager, protocolSerializer, endpointMap::get);
} else {
protocol = protocolFactory.newClientProtocol(nodeId);
}
RaftClient client = RaftClient.builder()
.withNodeId(nodeId)
.withProtocol(protocol)
.build();
client.connect(members.stream().map(RaftMember::nodeId).collect(Collectors.toList())).join();
clients.add(client);
return client;
}
示例4: handleAdvertisement
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
/**
* Handles an anti-entropy advertisement.
*/
private byte[] handleAdvertisement(Endpoint endpoint, byte[] payload) {
LogicalTimestamp timestamp = clock.increment();
ClusterMetadataAdvertisement advertisement = SERIALIZER.decode(payload);
Set<NodeId> staleNodes = nodes.values().stream().map(node -> {
NodeDigest digest = advertisement.digest(node.id());
if (digest == null || node.isNewerThan(digest.timestamp())) {
sendUpdate(endpoint, new NodeUpdate(node, timestamp));
} else if (digest.isNewerThan(node.timestamp())) {
if (digest.tombstone()) {
if (!node.tombstone()) {
nodes.put(node.id(), new ReplicatedNode(node.id(), node.type(), node.endpoint(), digest.timestamp(), true));
post(new ClusterMetadataEvent(ClusterMetadataEvent.Type.METADATA_CHANGED, getMetadata()));
}
} else {
return node.id();
}
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toSet());
return SERIALIZER.encode(Sets.newHashSet(Sets.union(Sets.difference(advertisement.digests(), nodes.keySet()), staleNodes)));
}
示例5: sendHeartbeat
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
/**
* Sends a heartbeat to the given peer.
*/
private void sendHeartbeat(Endpoint endpoint, byte[] payload) {
messagingService.sendAndReceive(endpoint, HEARTBEAT_MESSAGE, payload).whenComplete((response, error) -> {
if (error == null) {
Collection<StatefulNode> nodes = SERIALIZER.decode(response);
boolean sendHeartbeats = false;
for (StatefulNode node : nodes) {
if (this.nodes.putIfAbsent(node.id(), node) == null) {
post(new ClusterEvent(ClusterEvent.Type.NODE_ADDED, node));
post(new ClusterEvent(ClusterEvent.Type.NODE_ACTIVATED, node));
sendHeartbeats = true;
}
}
if (sendHeartbeats) {
sendHeartbeats();
}
} else {
LOGGER.trace("Sending heartbeat to {} failed", endpoint, error);
}
});
}
示例6: bootstrapClient
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
private Bootstrap bootstrapClient(Endpoint endpoint) {
Bootstrap bootstrap = new Bootstrap();
bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK,
new WriteBufferWaterMark(10 * 32 * 1024, 10 * 64 * 1024));
bootstrap.option(ChannelOption.SO_SNDBUF, 1048576);
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000);
bootstrap.group(clientGroup);
// TODO: Make this faster:
// http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#37.0
bootstrap.channel(clientChannelClass);
bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
bootstrap.remoteAddress(endpoint.host(), endpoint.port());
if (enableNettyTls) {
bootstrap.handler(new SslClientCommunicationChannelInitializer());
} else {
bootstrap.handler(new BasicChannelInitializer());
}
return bootstrap;
}
示例7: setUp
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
ep1 = new Endpoint(InetAddress.getByName("127.0.0.1"), findAvailablePort(5001));
netty1 = (ManagedMessagingService) NettyMessagingService.builder()
.withEndpoint(ep1)
.build()
.start()
.join();
ep2 = new Endpoint(InetAddress.getByName("127.0.0.1"), findAvailablePort(5003));
netty2 = (ManagedMessagingService) NettyMessagingService.builder()
.withEndpoint(ep2)
.build()
.start()
.join();
invalidEndPoint = new Endpoint(InetAddress.getByName(IP_STRING), 5003);
}
示例8: testSendAndReceive
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
@Test
@Ignore // FIXME disabled on 9/29/16 due to random failures
public void testSendAndReceive() {
String subject = nextSubject();
AtomicBoolean handlerInvoked = new AtomicBoolean(false);
AtomicReference<byte[]> request = new AtomicReference<>();
AtomicReference<Endpoint> sender = new AtomicReference<>();
BiFunction<Endpoint, byte[], byte[]> handler = (ep, data) -> {
handlerInvoked.set(true);
sender.set(ep);
request.set(data);
return "hello there".getBytes();
};
netty2.registerHandler(subject, handler, MoreExecutors.directExecutor());
CompletableFuture<byte[]> response = netty1.sendAndReceive(ep2, subject, "hello world".getBytes());
assertTrue(Arrays.equals("hello there".getBytes(), response.join()));
assertTrue(handlerInvoked.get());
assertTrue(Arrays.equals(request.get(), "hello world".getBytes()));
assertEquals(ep1, sender.get());
}
示例9: createAtomix
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
/**
* Creates an Atomix instance.
*/
protected static Atomix createAtomix(Node.Type type, int id, Integer... ids) {
Node localNode = Node.builder(String.valueOf(id))
.withType(type)
.withEndpoint(Endpoint.from("localhost", BASE_PORT + id))
.build();
Collection<Node> bootstrapNodes = Stream.of(ids)
.map(nodeId -> Node.builder(String.valueOf(nodeId))
.withType(Node.Type.DATA)
.withEndpoint(Endpoint.from("localhost", BASE_PORT + nodeId))
.build())
.collect(Collectors.toList());
return new TestAtomix.Builder()
.withClusterName("test")
.withDataDirectory(new File("target/test-logs/" + id))
.withLocalNode(localNode)
.withBootstrapNodes(bootstrapNodes)
.withCoordinationPartitions(3)
.withDataPartitions(3) // Lower number of partitions for faster testing
.build();
}
示例10: toNode
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
@JsonIgnore
public Node toNode() {
return Node.builder(id)
.withEndpoint(
Endpoint.from(endpoint.getHost(), endpoint.getPort()))
.withType(Type.valueOf(type.toUpperCase(Locale.ENGLISH)))
.build();
}
示例11: getLocalNode
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
@Override
public Node getLocalNode() {
return Node.builder(localNode)
.withType(Node.Type.DATA)
.withEndpoint(Endpoint.from("localhost", localNode.hashCode()))
.build();
}
示例12: getNodes
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
@Override
public Set<Node> getNodes() {
return nodes.stream()
.map(node -> Node.builder(node)
.withType(Node.Type.DATA)
.withEndpoint(Endpoint.from("localhost", node.hashCode()))
.build())
.collect(Collectors.toSet());
}
示例13: build
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
@Override
public ManagedRestService build() {
if (endpoint == null) {
endpoint = Endpoint.from(DEFAULT_HOST, DEFAULT_PORT);
}
return new VertxRestService(atomix, endpoint);
}
示例14: sendAndReceive
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
protected <T, U> CompletableFuture<U> sendAndReceive(NodeId nodeId, String type, T request) {
Endpoint endpoint = endpoint(nodeId);
if (endpoint == null) {
return Futures.exceptionalFuture(new ConnectException());
}
return messagingService.sendAndReceive(endpoint, type, serializer.encode(request))
.thenApply(serializer::decode);
}
示例15: sendAsync
import io.atomix.messaging.Endpoint; //导入依赖的package包/类
protected CompletableFuture<Void> sendAsync(NodeId nodeId, String type, Object request) {
Endpoint endpoint = endpoint(nodeId);
if (endpoint != null) {
return messagingService.sendAsync(endpoint(nodeId), type, serializer.encode(request));
}
return CompletableFuture.completedFuture(null);
}