Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc8ade4
commit ebb6bc5
Showing
4 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<project xmlns="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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>tutorial.first.akka</groupId> | ||
<artifactId>tutorial-first-akka</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>tutorial-first-akka</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>se.scalablesolutions.akka</groupId> | ||
<artifactId>akka-actor</artifactId> | ||
<version>1.3.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>se.scalablesolutions.akka</groupId> | ||
<artifactId>akka-remote</artifactId> | ||
<version>1.3.1</version> | ||
</dependency> | ||
</dependencies> | ||
<repositories> | ||
<repository> | ||
<id>typesafe</id> | ||
<name>Typesafe Repository</name> | ||
<url>http://repo.typesafe.com/typesafe/releases/</url> | ||
</repository> | ||
</repositories> | ||
</project> |
35 changes: 35 additions & 0 deletions
35
tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorld.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package tutorial.first.akka; | ||
|
||
import akka.actor.ActorRef; | ||
import akka.actor.UntypedActor; | ||
import static akka.actor.Actors.*; | ||
|
||
/** | ||
* Hello Munish! | ||
* | ||
*/ | ||
public class HelloWorld extends UntypedActor | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
//create and start the actor | ||
ActorRef actor = actorOf(HelloWorld.class).start(); | ||
|
||
//send the message to the actor and wait for response | ||
Object response = actor.ask("Munish").get(); | ||
|
||
//print the response | ||
System.out.println(response); | ||
|
||
//stop the actor | ||
actor.stop(); | ||
} | ||
|
||
@Override | ||
public void onReceive(Object message) throws Exception { | ||
|
||
//recieve and reply to the message recieved | ||
getContext().tryReply("Hello " + message); | ||
|
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorldClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package tutorial.first.akka; | ||
|
||
import akka.actor.ActorRef; | ||
import static akka.actor.Actors.*; | ||
|
||
public class HelloWorldClient { | ||
|
||
/** | ||
* @param args | ||
*/ | ||
public static void main(String[] args) { | ||
// client code | ||
ActorRef actor = remote().actorFor( | ||
"hello-service", "localhost", 2552); | ||
Object response = actor.ask("Munish").get(); | ||
System.out.println(response); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorldServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package tutorial.first.akka; | ||
|
||
import akka.actor.UntypedActor; | ||
import static akka.actor.Actors.*; | ||
|
||
public class HelloWorldServer extends UntypedActor { | ||
|
||
public void onReceive(Object msg) { | ||
getContext().tryReply("Hello " + msg); | ||
} | ||
|
||
/** | ||
* @param args | ||
*/ | ||
public static void main(String[] args) { | ||
// start the service | ||
remote().start("localhost", 2552).register("hello-service", | ||
actorOf(HelloWorldServer.class)); | ||
|
||
} | ||
|
||
} |