2012-02-02 09:40:17 +01:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
2012-05-22 11:37:09 +02:00
|
|
|
package docs.remoting;
|
2012-02-02 09:40:17 +01:00
|
|
|
|
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
//#import
|
|
|
|
|
import akka.actor.ActorRef;
|
|
|
|
|
import akka.actor.Address;
|
2012-02-27 10:28:20 +01:00
|
|
|
import akka.actor.AddressFromURIString;
|
2012-02-02 09:40:17 +01:00
|
|
|
import akka.actor.Deploy;
|
|
|
|
|
import akka.actor.Props;
|
|
|
|
|
import akka.actor.ActorSystem;
|
|
|
|
|
import akka.remote.RemoteScope;
|
|
|
|
|
//#import
|
|
|
|
|
|
2012-09-21 15:08:56 +02:00
|
|
|
import akka.actor.UntypedActor;
|
|
|
|
|
|
2012-02-02 09:40:17 +01:00
|
|
|
public class RemoteDeploymentDocTestBase {
|
2012-09-21 15:08:56 +02:00
|
|
|
|
2012-09-21 17:08:36 +02:00
|
|
|
public static class SampleActor extends UntypedActor {
|
2012-09-21 15:08:56 +02:00
|
|
|
public void onReceive(Object message) {
|
|
|
|
|
getSender().tell(getSelf(), getSelf());
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-02 09:40:17 +01:00
|
|
|
|
|
|
|
|
static ActorSystem system;
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
|
public static void init() {
|
|
|
|
|
system = ActorSystem.create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void cleanup() {
|
|
|
|
|
system.shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void demonstrateDeployment() {
|
|
|
|
|
//#make-address
|
|
|
|
|
Address addr = new Address("akka", "sys", "host", 1234);
|
2012-02-27 10:28:20 +01:00
|
|
|
addr = AddressFromURIString.parse("akka://sys@host:1234"); // the same
|
2012-02-02 09:40:17 +01:00
|
|
|
//#make-address
|
|
|
|
|
//#deploy
|
2012-10-01 20:35:19 +02:00
|
|
|
ActorRef ref = system.actorOf(new Props(SampleActor.class).withDeploy(
|
|
|
|
|
new Deploy(new RemoteScope(addr))));
|
2012-02-02 09:40:17 +01:00
|
|
|
//#deploy
|
|
|
|
|
assert ref.path().address().equals(addr);
|
|
|
|
|
}
|
2012-09-21 15:08:56 +02:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void demonstrateSampleActor() {
|
|
|
|
|
//#sample-actor
|
|
|
|
|
|
2012-09-21 17:08:36 +02:00
|
|
|
ActorRef actor = system.actorOf(new Props(SampleActor.class), "sampleActor");
|
2012-09-21 15:08:56 +02:00
|
|
|
actor.tell("Pretty slick", null);
|
|
|
|
|
//#sample-actor
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-02 09:40:17 +01:00
|
|
|
|
|
|
|
|
}
|