io.atomix.cluster.messaging.MessagingService Java Examples

The following examples show how to use io.atomix.cluster.messaging.MessagingService. 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: 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 #2
Source File: RaftFuzzTest.java    From atomix with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Raft server.
 */
private RaftServer createServer(RaftMember member) {
  RaftServerProtocol protocol;
  if (USE_NETTY) {
    Address address = Address.from(++port);
    MessagingService messagingManager = new NettyMessagingService("test", address, new MessagingConfig()).start().join();
    messagingServices.add(messagingManager);
    addressMap.put(member.memberId(), address);
    protocol = new RaftServerMessagingProtocol(messagingManager, PROTOCOL_SERIALIZER, addressMap::get);
  } else {
    protocol = protocolFactory.newServerProtocol(member.memberId());
  }

  RaftServer.Builder builder = RaftServer.builder(member.memberId())
      .withProtocol(protocol)
      .withStorage(RaftStorage.builder()
          .withStorageLevel(StorageLevel.DISK)
          .withDirectory(new File(String.format("target/fuzz-logs/%s", member.memberId())))
          .withNamespace(STORAGE_NAMESPACE)
          .withMaxSegmentSize(1024 * 1024)
          .build());

  RaftServer server = builder.build();
  servers.add(server);
  return server;
}
 
Example #3
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 #4
Source File: NettyMessagingService.java    From atomix with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<MessagingService> start() {
  if (started.get()) {
    log.warn("Already running at local address: {}", returnAddress);
    return CompletableFuture.completedFuture(this);
  }

  enableNettyTls = loadKeyStores();
  initEventLoopGroup();
  return bootstrapServer().thenRun(() -> {
    timeoutExecutor = Executors.newScheduledThreadPool(
        4, namedThreads("netty-messaging-timeout-%d", log));
    localConnection = new LocalClientConnection(timeoutExecutor, handlers);
    started.set(true);
    log.info("Started");
  }).thenApply(v -> this);
}
 
Example #5
Source File: RaftMessagingProtocol.java    From submarine with Apache License 2.0 5 votes vote down vote up
public RaftMessagingProtocol(MessagingService messagingService,
                             Serializer serializer,
                             Function<MemberId, Address> addressProvider) {
  this.messagingService = messagingService;
  this.serializer = serializer;
  this.addressProvider = addressProvider;
}
 
Example #6
Source File: RaftMessagingProtocol.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public RaftMessagingProtocol(MessagingService messagingService,
                             Serializer serializer,
                             Function<MemberId, Address> addressProvider) {
  this.messagingService = messagingService;
  this.serializer = serializer;
  this.addressProvider = addressProvider;
}
 
Example #7
Source File: DefaultClusterCommunicationService.java    From atomix with Apache License 2.0 5 votes vote down vote up
public DefaultClusterCommunicationService(
    ClusterMembershipService membershipService,
    MessagingService messagingService,
    UnicastService unicastService) {
  this.membershipService = checkNotNull(membershipService, "clusterService cannot be null");
  this.messagingService = checkNotNull(messagingService, "messagingService cannot be null");
  this.unicastService = checkNotNull(unicastService, "unicastService cannot be null");
}
 
Example #8
Source File: TestMessagingService.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MessagingService> start() {
  services.put(address, this);
  started.set(true);
  return CompletableFuture.completedFuture(this);
}
 
Example #9
Source File: TestMessagingService.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MessagingService> start() {
  services.put(address, this);
  started.set(true);
  return CompletableFuture.completedFuture(this);
}
 
Example #10
Source File: TestBootstrapService.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public MessagingService getMessagingService() {
  return messagingService;
}
 
Example #11
Source File: TestBootstrapService.java    From atomix with Apache License 2.0 4 votes vote down vote up
public TestBootstrapService(MessagingService messagingService, UnicastService unicastService, BroadcastService broadcastService) {
  this.messagingService = messagingService;
  this.unicastService = unicastService;
  this.broadcastService = broadcastService;
}
 
Example #12
Source File: AtomixCluster.java    From atomix with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a cluster event service.
 */
protected static ManagedClusterEventService buildClusterEventService(
    ClusterMembershipService membershipService, MessagingService messagingService) {
  return new DefaultClusterEventService(membershipService, messagingService);
}
 
Example #13
Source File: AtomixCluster.java    From atomix with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a cluster messaging service.
 */
protected static ManagedClusterCommunicationService buildClusterMessagingService(
    ClusterMembershipService membershipService, MessagingService messagingService, UnicastService unicastService) {
  return new DefaultClusterCommunicationService(membershipService, messagingService, unicastService);
}
 
Example #14
Source File: DefaultClusterEventService.java    From atomix with Apache License 2.0 4 votes vote down vote up
public DefaultClusterEventService(ClusterMembershipService membershipService, MessagingService messagingService) {
  this.membershipService = membershipService;
  this.messagingService = messagingService;
  this.localMemberId = membershipService.getLocalMember().id();
}
 
Example #15
Source File: RaftServerMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
public RaftServerMessagingProtocol(MessagingService messagingService, Serializer serializer, Function<MemberId, Address> addressProvider) {
  super(messagingService, serializer, addressProvider);
}
 
Example #16
Source File: RaftClientMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
public RaftClientMessagingProtocol(MessagingService messagingService, Serializer serializer, Function<MemberId, Address> addressProvider) {
  super(messagingService, serializer, addressProvider);
}
 
Example #17
Source File: RaftMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
public RaftMessagingProtocol(MessagingService messagingService, Serializer serializer, Function<MemberId, Address> addressProvider) {
  this.messagingService = messagingService;
  this.serializer = serializer;
  this.addressProvider = addressProvider;
}
 
Example #18
Source File: RaftPerformanceTest.java    From atomix with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a Raft server.
 */
private RaftServer createServer(Member member, List<Node> members) {
  RaftServerProtocol protocol;
  ManagedMessagingService messagingService;
  if (USE_NETTY) {
    messagingService = (ManagedMessagingService) new NettyMessagingService("test", member.address(), new MessagingConfig())
        .start()
        .join();
    messagingServices.add(messagingService);
    protocol = new RaftServerMessagingProtocol(messagingService, PROTOCOL_SERIALIZER, addressMap::get);
  } else {
    protocol = protocolFactory.newServerProtocol(member.id());
  }

  BootstrapService bootstrapService = new BootstrapService() {
    @Override
    public MessagingService getMessagingService() {
      return messagingService;
    }

    @Override
    public UnicastService getUnicastService() {
      return new UnicastServiceAdapter();
    }

    @Override
    public BroadcastService getBroadcastService() {
      return new BroadcastServiceAdapter();
    }
  };

  RaftServer.Builder builder = RaftServer.builder(member.id())
      .withProtocol(protocol)
      .withThreadModel(ThreadModel.SHARED_THREAD_POOL)
      .withMembershipService(new DefaultClusterMembershipService(
          member,
          Version.from("1.0.0"),
          new DefaultNodeDiscoveryService(bootstrapService, member, new BootstrapDiscoveryProvider(members)),
          bootstrapService,
          new HeartbeatMembershipProtocol(new HeartbeatMembershipProtocolConfig())))
      .withStorage(RaftStorage.builder()
          .withStorageLevel(StorageLevel.DISK)
          .withDirectory(new File(String.format("target/perf-logs/%s", member.id())))
          .withNamespace(STORAGE_NAMESPACE)
          .withMaxSegmentSize(1024 * 1024 * 64)
          .withDynamicCompaction()
          .withFlushOnCommit(false)
          .build());

  RaftServer server = builder.build();
  servers.add(server);
  return server;
}
 
Example #19
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
public RaftServerMessagingProtocol(MessagingService messagingService,
                                   Serializer serializer,
                                   Function<MemberId, Address> addressProvider) {
  super(messagingService, serializer, addressProvider);
}
 
Example #20
Source File: RaftClientMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
public RaftClientMessagingProtocol(MessagingService messagingService,
                                   Serializer serializer,
                                   Function<MemberId, Address> addressProvider) {
  super(messagingService, serializer, addressProvider);
}
 
Example #21
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
public RaftServerMessagingProtocol(MessagingService messagingService,
                                   Serializer serializer,
                                   Function<MemberId, Address> addressProvider) {
  super(messagingService, serializer, addressProvider);
}
 
Example #22
Source File: RaftClientMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
public RaftClientMessagingProtocol(MessagingService messagingService,
                                   Serializer serializer,
                                   Function<MemberId, Address> addressProvider) {
  super(messagingService, serializer, addressProvider);
}
 
Example #23
Source File: BootstrapService.java    From atomix with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the cluster messaging service.
 *
 * @return the cluster messaging service
 */
MessagingService getMessagingService();
 
Example #24
Source File: AtomixCluster.java    From atomix with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the cluster messaging service.
 * <p>
 * The messaging service is used for direct point-to-point messaging between nodes by {@link Address}. This is a
 * low-level cluster communication API. For higher level messaging, use the
 * {@link #getCommunicationService() communication service} or {@link #getEventService() event service}.
 *
 * @return the cluster messaging service
 */
@Override
public MessagingService getMessagingService() {
  return messagingService;
}