Introduction Akka Before you need to say a little bit scala,scala claims to be the next generation JVM language,
The integration of the object-oriented Java, as well as functional programming in one, unusually powerful, but also complex, this article is not controversial, let's briefly introduce.
The Akka framework is based on Scala and a small amount of Java code, and Scala replaces its own underlying actor library with Akka from its 2.11.0 version, which is visible akka powerful.
Akka official website of boast:
Akka is a toolkit and runtime for building highly concurrent, distributed, and fault tolerant Event-driven applications on The JVM.
Akka also provides Java and Scala two API interface, the following Java interface as an example of a brief introduction.
Øactor says
²public class Greeting implements Serializable {
²public final String who;
²public greeting (String who) {this.who = who;}
² }
²
²public class Greetingactor extends Untypedactor {
²loggingadapter log = Logging.getlogger (GetContext (). System (), this);
²
²public void OnReceive (Object message) throws Exception {
²IF (Message instanceof Greeting)
²log.info ("Hello" + ((greeting) message).
² }
² }
²
²actorsystem system = actorsystem.create ("Mysystem");
²actorref greeter = system.actorof (Props.create (Greetingactor.class), "greeter");
²greeter.tell (New greeting ("Charlie Parker"), Actorref.nosender ());
Inheriting untypeactor can define a class for an actor role, where the OnReceive method can accept messages passed from other actors.
The Actorsystem class is responsible for creating the topmost actor, which manages the actors monitoring tree throughout the system.
Ø distributed
Actorsystem system = actorsystem.create ("Mysystem");
Get a actor:greeter on machine 2
Actorselection greeter = system.actorselection ("Akka.tcp://mysystem@machine2:2552/user/greeter");
Send a message to the actor above, greeting represents the message
Greeter.tell (New greeting ("Sonny Rollins"), Actorref.nosender ());