|
Akka/Scala example source code file (Main.java)
The Main.java Akka example source codepackage supervision; import akka.actor.ActorRef; import akka.actor.Props; import akka.actor.ActorSystem; import akka.util.Timeout; import scala.concurrent.Await; import scala.concurrent.duration.Duration; import scala.concurrent.duration.FiniteDuration; import java.util.concurrent.TimeUnit; import static supervision.Expression.*; import static akka.pattern.Patterns.ask; import static akka.japi.Util.classTag; public class Main { public static void main(String[] args) throws Exception { ActorSystem system = ActorSystem.create("calculator-system"); ActorRef calculatorService = system.actorOf(Props.create(ArithmeticService.class), "arithmetic-service"); // (3 + 5) / (2 * (1 + 1)) Expression task = new Divide( new Add(new Const(3), new Const(5)), new Multiply( new Const(2), new Add(new Const(1), new Const(1)) ) ); FiniteDuration duration = Duration.create(1, TimeUnit.SECONDS); Integer result = Await.result(ask(calculatorService, task, new Timeout(duration)).mapTo(classTag(Integer.class)), duration); System.out.println("Got result: " + result); system.shutdown(); system.awaitTermination(); } } Other Akka source code examplesHere is a short list of links related to this Akka Main.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.