diff --git a/tutorial-first-akka/pom.xml b/tutorial-first-akka/pom.xml new file mode 100644 index 0000000..fbe346d --- /dev/null +++ b/tutorial-first-akka/pom.xml @@ -0,0 +1,42 @@ + + 4.0.0 + + tutorial.first.akka + tutorial-first-akka + 0.0.1-SNAPSHOT + jar + + tutorial-first-akka + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + se.scalablesolutions.akka + akka-actor + 1.3.1 + + + se.scalablesolutions.akka + akka-remote + 1.3.1 + + + + + typesafe + Typesafe Repository + http://repo.typesafe.com/typesafe/releases/ + + + diff --git a/tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorld.java b/tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorld.java new file mode 100644 index 0000000..06e4ec3 --- /dev/null +++ b/tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorld.java @@ -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); + + } +} diff --git a/tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorldClient.java b/tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorldClient.java new file mode 100644 index 0000000..8e80ea9 --- /dev/null +++ b/tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorldClient.java @@ -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); + } + +} \ No newline at end of file diff --git a/tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorldServer.java b/tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorldServer.java new file mode 100644 index 0000000..7826eb1 --- /dev/null +++ b/tutorial-first-akka/src/main/java/tutorial/first/akka/HelloWorldServer.java @@ -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)); + + } + +} \ No newline at end of file