Formatting java codes with sbt-java-formatter.
This commit is contained in:
parent
27500001ea
commit
998c5a9285
401 changed files with 19750 additions and 17450 deletions
|
|
@ -22,66 +22,74 @@ import java.util.Collections;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
//#service
|
||||
// #service
|
||||
public class StatsService extends AbstractActor {
|
||||
|
||||
// This router is used both with lookup and deploy of routees. If you
|
||||
// have a router with only lookup of routees you can use Props.empty()
|
||||
// instead of Props.create(StatsWorker.class).
|
||||
ActorRef workerRouter = getContext().actorOf(
|
||||
FromConfig.getInstance().props(Props.create(StatsWorker.class)),
|
||||
"workerRouter");
|
||||
ActorRef workerRouter =
|
||||
getContext()
|
||||
.actorOf(FromConfig.getInstance().props(Props.create(StatsWorker.class)), "workerRouter");
|
||||
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(StatsJob.class, job -> !job.getText().isEmpty(), job -> {
|
||||
String[] words = job.getText().split(" ");
|
||||
ActorRef replyTo = getSender();
|
||||
.match(
|
||||
StatsJob.class,
|
||||
job -> !job.getText().isEmpty(),
|
||||
job -> {
|
||||
String[] words = job.getText().split(" ");
|
||||
ActorRef replyTo = getSender();
|
||||
|
||||
// create actor that collects replies from workers
|
||||
ActorRef aggregator = getContext().actorOf(
|
||||
Props.create(StatsAggregator.class, words.length, replyTo));
|
||||
// create actor that collects replies from workers
|
||||
ActorRef aggregator =
|
||||
getContext().actorOf(Props.create(StatsAggregator.class, words.length, replyTo));
|
||||
|
||||
// send each word to a worker
|
||||
for (String word : words) {
|
||||
workerRouter.tell(new ConsistentHashableEnvelope(word, word),
|
||||
aggregator);
|
||||
}
|
||||
|
||||
})
|
||||
.build();
|
||||
// send each word to a worker
|
||||
for (String word : words) {
|
||||
workerRouter.tell(new ConsistentHashableEnvelope(word, word), aggregator);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
}
|
||||
//#service
|
||||
// #service
|
||||
|
||||
//not used, only for documentation
|
||||
// not used, only for documentation
|
||||
abstract class StatsService2 extends AbstractActor {
|
||||
//#router-lookup-in-code
|
||||
// #router-lookup-in-code
|
||||
int totalInstances = 100;
|
||||
Iterable<String> routeesPaths = Collections
|
||||
.singletonList("/user/statsWorker");
|
||||
Iterable<String> routeesPaths = Collections.singletonList("/user/statsWorker");
|
||||
boolean allowLocalRoutees = true;
|
||||
Set<String> useRoles = new HashSet<>(Arrays.asList("compute"));
|
||||
ActorRef workerRouter = getContext().actorOf(
|
||||
new ClusterRouterGroup(new ConsistentHashingGroup(routeesPaths),
|
||||
new ClusterRouterGroupSettings(totalInstances, routeesPaths,
|
||||
allowLocalRoutees, useRoles)).props(), "workerRouter2");
|
||||
//#router-lookup-in-code
|
||||
ActorRef workerRouter =
|
||||
getContext()
|
||||
.actorOf(
|
||||
new ClusterRouterGroup(
|
||||
new ConsistentHashingGroup(routeesPaths),
|
||||
new ClusterRouterGroupSettings(
|
||||
totalInstances, routeesPaths, allowLocalRoutees, useRoles))
|
||||
.props(),
|
||||
"workerRouter2");
|
||||
// #router-lookup-in-code
|
||||
}
|
||||
|
||||
//not used, only for documentation
|
||||
// not used, only for documentation
|
||||
abstract class StatsService3 extends AbstractActor {
|
||||
//#router-deploy-in-code
|
||||
// #router-deploy-in-code
|
||||
int totalInstances = 100;
|
||||
int maxInstancesPerNode = 3;
|
||||
boolean allowLocalRoutees = false;
|
||||
Set<String> useRoles = new HashSet<>(Arrays.asList("compute"));
|
||||
ActorRef workerRouter = getContext().actorOf(
|
||||
new ClusterRouterPool(new ConsistentHashingPool(0),
|
||||
new ClusterRouterPoolSettings(totalInstances, maxInstancesPerNode,
|
||||
allowLocalRoutees, useRoles)).props(Props
|
||||
.create(StatsWorker.class)), "workerRouter3");
|
||||
//#router-deploy-in-code
|
||||
ActorRef workerRouter =
|
||||
getContext()
|
||||
.actorOf(
|
||||
new ClusterRouterPool(
|
||||
new ConsistentHashingPool(0),
|
||||
new ClusterRouterPoolSettings(
|
||||
totalInstances, maxInstancesPerNode, allowLocalRoutees, useRoles))
|
||||
.props(Props.create(StatsWorker.class)),
|
||||
"workerRouter3");
|
||||
// #router-deploy-in-code
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue