Formatting java codes with sbt-java-formatter.

This commit is contained in:
hepin1989 2019-01-12 04:00:53 +08:00
parent 27500001ea
commit 998c5a9285
401 changed files with 19750 additions and 17450 deletions

View file

@ -26,15 +26,15 @@ import akka.event.Logging;
import akka.event.LoggingAdapter;
import akka.routing.FromConfig;
//#frontend
// #frontend
public class FactorialFrontend extends AbstractActor {
final int upToN;
final boolean repeat;
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
ActorRef backend = getContext().actorOf(FromConfig.getInstance().props(),
"factorialBackendRouter");
ActorRef backend =
getContext().actorOf(FromConfig.getInstance().props(), "factorialBackendRouter");
public FactorialFrontend(int upToN, boolean repeat) {
this.upToN = upToN;
@ -50,20 +50,22 @@ public class FactorialFrontend extends AbstractActor {
@Override
public Receive createReceive() {
return receiveBuilder()
.match(FactorialResult.class, result -> {
if (result.n == upToN) {
log.debug("{}! = {}", result.n, result.factorial);
if (repeat)
sendJobs();
else
getContext().stop(getSelf());
}
})
.match(ReceiveTimeout.class, x -> {
log.info("Timeout");
sendJobs();
})
.build();
.match(
FactorialResult.class,
result -> {
if (result.n == upToN) {
log.debug("{}! = {}", result.n, result.factorial);
if (repeat) sendJobs();
else getContext().stop(getSelf());
}
})
.match(
ReceiveTimeout.class,
x -> {
log.info("Timeout");
sendJobs();
})
.build();
}
void sendJobs() {
@ -72,38 +74,46 @@ public class FactorialFrontend extends AbstractActor {
backend.tell(n, getSelf());
}
}
}
//#frontend
// #frontend
//not used, only for documentation
// not used, only for documentation
abstract class FactorialFrontend2 extends AbstractActor {
//#router-lookup-in-code
// #router-lookup-in-code
int totalInstances = 100;
Iterable<String> routeesPaths = Arrays.asList("/user/factorialBackend", "");
boolean allowLocalRoutees = true;
Set<String> useRoles = new HashSet<>(Arrays.asList("backend"));
ActorRef backend = getContext().actorOf(
new ClusterRouterGroup(new AdaptiveLoadBalancingGroup(
HeapMetricsSelector.getInstance(), Collections.<String> emptyList()),
new ClusterRouterGroupSettings(totalInstances, routeesPaths,
allowLocalRoutees, useRoles)).props(), "factorialBackendRouter2");
ActorRef backend =
getContext()
.actorOf(
new ClusterRouterGroup(
new AdaptiveLoadBalancingGroup(
HeapMetricsSelector.getInstance(), Collections.<String>emptyList()),
new ClusterRouterGroupSettings(
totalInstances, routeesPaths, allowLocalRoutees, useRoles))
.props(),
"factorialBackendRouter2");
//#router-lookup-in-code
// #router-lookup-in-code
}
//not used, only for documentation
// not used, only for documentation
abstract class FactorialFrontend3 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("backend"));
ActorRef backend = getContext().actorOf(
new ClusterRouterPool(new AdaptiveLoadBalancingPool(
SystemLoadAverageMetricsSelector.getInstance(), 0),
new ClusterRouterPoolSettings(totalInstances, maxInstancesPerNode,
allowLocalRoutees, useRoles)).props(Props
.create(FactorialBackend.class)), "factorialBackendRouter3");
//#router-deploy-in-code
ActorRef backend =
getContext()
.actorOf(
new ClusterRouterPool(
new AdaptiveLoadBalancingPool(
SystemLoadAverageMetricsSelector.getInstance(), 0),
new ClusterRouterPoolSettings(
totalInstances, maxInstancesPerNode, allowLocalRoutees, useRoles))
.props(Props.create(FactorialBackend.class)),
"factorialBackendRouter3");
// #router-deploy-in-code
}