Akka Development (i) HelloWorld

Source: Internet
Author: User

 PackageCom.hfi.helloakka;ImportAkka.actor.ActorRef;ImportAkka.actor.Props;ImportAkka.actor.UntypedActor; Public classHelloWorldextendsUntypedactor {@Override Public voidPrestart () {//Create the greeter actor        FinalActorref greeter =GetContext (). Actorof (Props.create (Greeter.class), "Greeter"); //Tell it to perform the greetingGreeter.tell (Greeter.Msg.GREET, getself ()); } @Override Public voidonreceive (Object msg) {if(msg = =Greeter.Msg.DONE) {//When the greeter is do, stop this actor and with it the applicationGetContext (). Stop (Getself ()); } Elseunhandled (msg); }    }
 PackageCom.hfi.helloakka;ImportAkka.actor.UntypedActor; Public classGreeterextendsUntypedactor { Public Static enumMSG {GREET, done; } @Override Public voidonreceive (Object msg) {if(msg = =msg.greet) {System.out.println ("Hello world!");        Getsender (). Tell (Msg.done, getself ()); } Elseunhandled (msg); }          }

Pom.xml

<Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  <modelversion>4.0.0</modelversion>  <groupId>Com.hfi</groupId>  <Artifactid>Helloakka</Artifactid>  <Packaging>War</Packaging>  <version>0.0.1-snapshot</version>  <name>Helloakka Maven Webapp</name>  <URL>http://maven.apache.org</URL>  <Dependencies>    <Dependency>      <groupId>Junit</groupId>      <Artifactid>Junit</Artifactid>      <version>3.8.1</version>      <Scope>Test</Scope>    </Dependency>    <Dependency>        <groupId>Org.scala-lang</groupId>        <Artifactid>Scala-library</Artifactid>        <version>2.10.2</version>    </Dependency>    <Dependency>          <groupId>Com.typesafe.akka</groupId>          <Artifactid>akka-actor_2.10</Artifactid>          <version>2.2.5</version>    </Dependency>  </Dependencies>  <Build>    <Finalname>Helloakka</Finalname>  </Build></Project>

Problems you may encounter:

Java.lang.noclassdeffounderror:scala/collection/gentraversableonce$class

With the Akka package with the dependency of the Scala package version inconsistent led (seemingly Scala is not compatible with its old version), the author began to use the 2.11.7 error, in the Pom 2.10.2 (to akka-2.2.5.zip version number) program ran up. Referenced by: http://www.jianshu.com/p/59733597d448

Akka Development (i) HelloWorld

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.