alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Akka/Scala example source code file (Extra.java)

This example Akka source code file (Extra.java) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Akka and Scala source code examples by using tags.

All credit for the original source code belongs to akka.io; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Akka tags/keywords

actor, actorref, akka, cluster, clusterroutergroup, clusterroutergroupsettings, clusterrouterpool, consistenthashinggroup, consistenthashingpool, iterable, route, router, routing, statsservice2, statsservice3, string, untypedactor

The Extra.java Akka example source code

package sample.cluster.stats;

import java.util.Collections;

import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.cluster.routing.ClusterRouterGroup;
import akka.cluster.routing.ClusterRouterGroupSettings;
import akka.cluster.routing.ClusterRouterPool;
import akka.cluster.routing.ClusterRouterPoolSettings;
import akka.routing.ConsistentHashingGroup;
import akka.routing.ConsistentHashingPool;

//not used, only for documentation
abstract class StatsService2 extends UntypedActor {
  //#router-lookup-in-code
  int totalInstances = 100;
  Iterable<String> routeesPaths = Collections
      .singletonList("/user/statsWorker");
  boolean allowLocalRoutees = true;
  String useRole = "compute";
  ActorRef workerRouter = getContext().actorOf(
      new ClusterRouterGroup(new ConsistentHashingGroup(routeesPaths),
          new ClusterRouterGroupSettings(totalInstances, routeesPaths,
              allowLocalRoutees, useRole)).props(), "workerRouter2");
  //#router-lookup-in-code
}

//not used, only for documentation
abstract class StatsService3 extends UntypedActor {
  //#router-deploy-in-code
  int totalInstances = 100;
  int maxInstancesPerNode = 3;
  boolean allowLocalRoutees = false;
  String useRole = "compute";
  ActorRef workerRouter = getContext().actorOf(
      new ClusterRouterPool(new ConsistentHashingPool(0),
          new ClusterRouterPoolSettings(totalInstances, maxInstancesPerNode,
              allowLocalRoutees, useRole)).props(Props
          .create(StatsWorker.class)), "workerRouter3");
  //#router-deploy-in-code
}

Other Akka source code examples

Here is a short list of links related to this Akka Extra.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.