Actor programming Model--akka

Source: Internet
Author: User

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 ());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.