Java Code Examples for akka.cluster.Cluster#get()

The following examples show how to use akka.cluster.Cluster#get() . 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: PubSubFactoryTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setUpCluster() throws Exception {
    final CountDownLatch latch = new CountDownLatch(2);
    system1 = ActorSystem.create("actorSystem", getTestConf());
    system2 = ActorSystem.create("actorSystem", getTestConf());
    cluster1 = Cluster.get(system1);
    cluster2 = Cluster.get(system2);
    cluster1.registerOnMemberUp(latch::countDown);
    cluster2.registerOnMemberUp(latch::countDown);
    cluster1.join(cluster1.selfAddress());
    cluster2.join(cluster1.selfAddress());
    factory1 = TestPubSubFactory.of(newContext(system1));
    factory2 = TestPubSubFactory.of(newContext(system2));
    // wait for both members to be UP
    latch.await();
}
 
Example 2
Source File: StatusResource.java    From flux with Apache License 2.0 6 votes vote down vote up
/**
 * Api to make a node leave the cluster.
 * @param host hostname/ip of the node.
 * @param port port
 */
@POST
@Path("/cluster/leave")
public Response leaveCluster(@QueryParam("host") String host, @QueryParam("port") Integer port) {
    if(StringUtils.isEmpty(host) || port == null) {
        return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).entity("empty hostname or port").build();
    }

    if(FluxInitializer.fluxRole.equals(FluxRuntimeRole.ORCHESTRATION)){
        return Response.status(Response.Status.FORBIDDEN.getStatusCode()).entity("Api not valid for Flux's" +
                " orchestraton nodes.").build();
    }

    Address akkAddress = new Address("akka.tcp", actorSystemManager.retrieveActorSystem().name(), host, port);
    Cluster cluster = Cluster.get(actorSystemManager.retrieveActorSystem());
    cluster.leave(akkAddress);

    return Response.status(Response.Status.OK.getStatusCode()).build();
}
 
Example 3
Source File: SimpleClusterMain.java    From akka-kubernetes-example with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
  ActorSystem actorSystem = ActorSystem.create(CLUSTER_NAME);
  actorSystem.actorOf(SimpleClusterListener.props());
  final ActorMaterializer materializer = ActorMaterializer.create(actorSystem);

  Cluster cluster = Cluster.get(actorSystem);
  List<Address> addresses = Arrays.asList(System.getenv().get("SEED_NODES").split(","))
      .stream()
      .map(ip -> new Address("akka.tcp", CLUSTER_NAME, ip, 2551))
      .collect(Collectors.toList());
  cluster.joinSeedNodes(addresses);
}
 
Example 4
Source File: ConciergeRootActor.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private static Route createRoute(final ActorSystem actorSystem, final ActorRef healthCheckingActor) {
    final StatusRoute statusRoute = new StatusRoute(new ClusterStatusSupplier(Cluster.get(actorSystem)),
            healthCheckingActor, actorSystem);

    return logRequest("http-request", () ->
            logResult("http-response", statusRoute::buildStatusRoute));
}
 
Example 5
Source File: StatisticsActor.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private StatisticsActor(final ActorRef pubSubMediator) {
    statisticsConfig = StatisticsConfig.forActor(getContext());

    this.pubSubMediator = pubSubMediator;
    this.gauges = initializeGaugesForHotEntities(statisticsConfig);

    final ActorSystem actorSystem = getContext().getSystem();
    final int numberOfShards = getNumberOfShards(actorSystem);
    clusterSharding = initClusterSharding(actorSystem, statisticsConfig, numberOfShards);
    clusterStatusSupplier = new ClusterStatusSupplier(Cluster.get(getContext().getSystem()));
    scheduleInternalRetrieveHotEntities();
    subscribeForStatisticsCommands();
}
 
Example 6
Source File: ConnectionPersistenceActorTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private void startSecondActorSystemAndJoinCluster() throws Exception {
    final CountDownLatch latch = new CountDownLatch(2);
    actorSystem2 = ActorSystem.create(getClass().getSimpleName(), TestConstants.CONFIG);
    final Cluster cluster1 = Cluster.get(actorSystem);
    final Cluster cluster2 = Cluster.get(actorSystem2);
    cluster1.registerOnMemberUp(latch::countDown);
    cluster2.registerOnMemberUp(latch::countDown);
    cluster1.join(cluster1.selfAddress());
    cluster2.join(cluster1.selfAddress());
    latch.await();
}
 
Example 7
Source File: ActorSystemManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void leaveCluster(){

    Cluster cluster = Cluster.get(clusterSystem);
    logger.info("Downing self: {} from cluster: {}", cluster.selfAddress(), clusterSystem.name());
    cluster.leave(cluster.selfAddress());
}
 
Example 8
Source File: SshClusterManagerActor.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
public SshClusterManagerActor(SshClusterManagerImpl sshClusterManager) {
    this.sshClusterManager = sshClusterManager;
    this.cluster = Cluster.get(getContext().system());
    sshClusterManager.setContext(getContext().system(), self(), cluster.selfAddress().toString());
}
 
Example 9
Source File: ClusterStatusObserverActor.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
public ClusterStatusObserverActor(ClusterStatusObserver clusterStatusObserver) {
    this.clusterStatusObserver = clusterStatusObserver;
    this.cluster = Cluster.get(getContext().system());
}
 
Example 10
Source File: Worker.java    From akka-tutorial with Apache License 2.0 4 votes vote down vote up
public Worker() {
	this.cluster = Cluster.get(this.context().system());
}
 
Example 11
Source File: GatewayRootActor.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private static Route createRoute(final ActorSystem actorSystem,
        final GatewayConfig gatewayConfig,
        final ActorRef proxyActor,
        final ActorRef streamingActor,
        final ActorRef healthCheckingActor,
        final ActorRef pubSubMediator,
        final HealthCheckConfig healthCheckConfig,
        final JwtAuthenticationFactory jwtAuthenticationFactory,
        final ProtocolAdapterProvider protocolAdapterProvider,
        final HeaderTranslator headerTranslator) {

    final AuthenticationConfig authConfig = gatewayConfig.getAuthenticationConfig();

    final MessageDispatcher authenticationDispatcher =
            actorSystem.dispatchers().lookup(AUTHENTICATION_DISPATCHER_NAME);

    final GatewayAuthenticationDirectiveFactory authenticationDirectiveFactory =
            new DittoGatewayAuthenticationDirectiveFactory(authConfig, jwtAuthenticationFactory,
                    authenticationDispatcher);

    final Supplier<ClusterStatus> clusterStateSupplier = new ClusterStatusSupplier(Cluster.get(actorSystem));
    final StatusAndHealthProvider statusAndHealthProvider =
            DittoStatusAndHealthProviderFactory.of(actorSystem, clusterStateSupplier, healthCheckConfig);

    final LimitsConfig limitsConfig = gatewayConfig.getLimitsConfig();
    final DittoHeadersSizeChecker dittoHeadersSizeChecker =
            DittoHeadersSizeChecker.of(limitsConfig.getHeadersMaxSize(), limitsConfig.getAuthSubjectsMaxCount());

    final HttpConfig httpConfig = gatewayConfig.getHttpConfig();
    final DevOpsConfig devOpsConfig = authConfig.getDevOpsConfig();

    final GatewaySignalEnrichmentConfig signalEnrichmentConfig =
            gatewayConfig.getStreamingConfig().getSignalEnrichmentConfig();
    final GatewaySignalEnrichmentProvider signalEnrichmentProvider =
            signalEnrichmentProvider(signalEnrichmentConfig, actorSystem);

    final StreamingConfig streamingConfig = gatewayConfig.getStreamingConfig();
    final CommandConfig commandConfig = gatewayConfig.getCommandConfig();

    return RootRoute.getBuilder(httpConfig)
            .statsRoute(new StatsRoute(proxyActor, actorSystem, httpConfig, commandConfig, devOpsConfig,
                    headerTranslator))
            .statusRoute(new StatusRoute(clusterStateSupplier, healthCheckingActor, actorSystem))
            .overallStatusRoute(new OverallStatusRoute(clusterStateSupplier, statusAndHealthProvider, devOpsConfig))
            .cachingHealthRoute(
                    new CachingHealthRoute(statusAndHealthProvider, gatewayConfig.getPublicHealthConfig()))
            .devopsRoute(new DevOpsRoute(proxyActor, actorSystem, httpConfig, commandConfig, devOpsConfig,
                    headerTranslator))
            .policiesRoute(new PoliciesRoute(proxyActor, actorSystem, httpConfig, commandConfig, headerTranslator))
            .sseThingsRoute(ThingsSseRouteBuilder.getInstance(streamingActor, streamingConfig, pubSubMediator)
                    .withSignalEnrichmentProvider(signalEnrichmentProvider))
            .thingsRoute(new ThingsRoute(proxyActor, actorSystem, httpConfig, commandConfig,
                    gatewayConfig.getMessageConfig(), gatewayConfig.getClaimMessageConfig(), headerTranslator))
            .thingSearchRoute(
                    new ThingSearchRoute(proxyActor, actorSystem, httpConfig, commandConfig, headerTranslator))
            .whoamiRoute(new WhoamiRoute(proxyActor, actorSystem, httpConfig, commandConfig, headerTranslator))
            .websocketRoute(WebSocketRoute.getInstance(streamingActor, streamingConfig)
                    .withSignalEnrichmentProvider(signalEnrichmentProvider)
                    .withHeaderTranslator(headerTranslator))
            .supportedSchemaVersions(httpConfig.getSupportedSchemaVersions())
            .protocolAdapterProvider(protocolAdapterProvider)
            .headerTranslator(headerTranslator)
            .httpAuthenticationDirective(authenticationDirectiveFactory.buildHttpAuthentication())
            .wsAuthenticationDirective(authenticationDirectiveFactory.buildWsAuthentication())
            .dittoHeadersSizeChecker(dittoHeadersSizeChecker)
            .build();
}
 
Example 12
Source File: ThingsRootActor.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private static Route createRoute(final ActorSystem actorSystem, final ActorRef healthCheckingActor) {
    final StatusRoute statusRoute = new StatusRoute(new ClusterStatusSupplier(Cluster.get(actorSystem)),
            healthCheckingActor, actorSystem);

    return logRequest("http-request", () -> logResult("http-response", statusRoute::buildStatusRoute));
}
 
Example 13
Source File: SearchRootActor.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private static Route createRoute(final ActorSystem actorSystem, final ActorRef healthCheckingActor) {
    final StatusRoute statusRoute = new StatusRoute(new ClusterStatusSupplier(Cluster.get(actorSystem)),
            healthCheckingActor, actorSystem);

    return logRequest("http-request", () -> logResult("http-response", statusRoute::buildStatusRoute));
}
 
Example 14
Source File: ConnectivityRootActor.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private static Route createRoute(final ActorSystem actorSystem, final ActorRef healthCheckingActor) {
    final StatusRoute statusRoute = new StatusRoute(new ClusterStatusSupplier(Cluster.get(actorSystem)),
            healthCheckingActor, actorSystem);

    return logRequest("http-request", () -> logResult("http-response", statusRoute::buildStatusRoute));
}
 
Example 15
Source File: PoliciesRootActor.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private static Route createRoute(final ActorSystem actorSystem, final ActorRef healthCheckingActor) {
    final StatusRoute statusRoute = new StatusRoute(new ClusterStatusSupplier(Cluster.get(actorSystem)),
            healthCheckingActor, actorSystem);

    return logRequest("http-request", () -> logResult("http-response", statusRoute::buildStatusRoute));
}