Skip to content

Commit

Permalink
added new files
Browse files Browse the repository at this point in the history
  • Loading branch information
write2munish committed Mar 3, 2012
1 parent bc8ade4 commit ebb6bc5
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tutorial-first-akka/pom.xml
@@ -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>
@@ -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);

}
}
@@ -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);
}

}
@@ -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));

}

}

0 comments on commit ebb6bc5

Please sign in to comment.