diff --git a/akka-samples/akka-sample-camel/src/main/java/sample/camel/RemoteActiveObject1.java b/akka-samples/akka-sample-camel/src/main/java/sample/camel/RemoteActiveObject1.java new file mode 100644 index 0000000000..695aa148f4 --- /dev/null +++ b/akka-samples/akka-sample-camel/src/main/java/sample/camel/RemoteActiveObject1.java @@ -0,0 +1,18 @@ +package sample.camel; + +import org.apache.camel.Body; +import org.apache.camel.Header; + +import se.scalablesolutions.akka.actor.annotation.consume; + +/** + * @author Martin Krasser + */ +public class RemoteActiveObject1 { + + @consume("jetty:http://localhost:6644/remote-active-object-1") + public String foo(@Body String body, @Header("name") String header) { + return String.format("remote1: body=%s header=%s", body, header); + } + +} diff --git a/akka-samples/akka-sample-camel/src/main/java/sample/camel/RemoteActiveObject2.java b/akka-samples/akka-sample-camel/src/main/java/sample/camel/RemoteActiveObject2.java new file mode 100644 index 0000000000..210a72d2f8 --- /dev/null +++ b/akka-samples/akka-sample-camel/src/main/java/sample/camel/RemoteActiveObject2.java @@ -0,0 +1,17 @@ +package sample.camel; + +import org.apache.camel.Body; +import org.apache.camel.Header; +import se.scalablesolutions.akka.actor.annotation.consume; + +/** + * @author Martin Krasser + */ +public class RemoteActiveObject2 { + + @consume("jetty:http://localhost:6644/remote-active-object-2") + public String foo(@Body String body, @Header("name") String header) { + return String.format("remote2: body=%s header=%s", body, header); + } + +} \ No newline at end of file diff --git a/akka-samples/akka-sample-camel/src/main/scala/Actors.scala b/akka-samples/akka-sample-camel/src/main/scala/Actors.scala index 157ae195ea..25f7986730 100644 --- a/akka-samples/akka-sample-camel/src/main/scala/Actors.scala +++ b/akka-samples/akka-sample-camel/src/main/scala/Actors.scala @@ -9,10 +9,10 @@ import se.scalablesolutions.akka.util.Logging * Client-initiated remote actor. */ class RemoteActor1 extends RemoteActor("localhost", 7777) with Consumer { - def endpointUri = "jetty:http://localhost:6644/remote1" + def endpointUri = "jetty:http://localhost:6644/remote-actor-1" protected def receive = { - case msg: Message => self.reply(Message("hello %s" format msg.body, Map("sender" -> "remote1"))) + case msg: Message => self.reply(Message("hello %s" format msg.bodyAs[String], Map("sender" -> "remote1"))) } } @@ -20,10 +20,10 @@ class RemoteActor1 extends RemoteActor("localhost", 7777) with Consumer { * Server-initiated remote actor. */ class RemoteActor2 extends Actor with Consumer { - def endpointUri = "jetty:http://localhost:6644/remote2" + def endpointUri = "jetty:http://localhost:6644/remote-actor-2" protected def receive = { - case msg: Message => self.reply(Message("hello %s" format msg.body, Map("sender" -> "remote2"))) + case msg: Message => self.reply(Message("hello %s" format msg.bodyAs[String], Map("sender" -> "remote2"))) } } diff --git a/akka-samples/akka-sample-camel/src/main/scala/Application1.scala b/akka-samples/akka-sample-camel/src/main/scala/Application1.scala index 6dcb437992..2b3c7b5db5 100644 --- a/akka-samples/akka-sample-camel/src/main/scala/Application1.scala +++ b/akka-samples/akka-sample-camel/src/main/scala/Application1.scala @@ -1,9 +1,9 @@ package sample.camel -import se.scalablesolutions.akka.actor.{Actor, ActorRef} import se.scalablesolutions.akka.actor.Actor._ import se.scalablesolutions.akka.camel.Message import se.scalablesolutions.akka.remote.RemoteClient +import se.scalablesolutions.akka.actor.{ActiveObject, Actor, ActorRef} /** * @author Martin Krasser @@ -15,15 +15,19 @@ object Application1 { // def main(args: Array[String]) { - implicit val sender: Option[ActorRef] = None - val actor1 = actorOf[RemoteActor1] val actor2 = RemoteClient.actorFor("remote2", "localhost", 7777) + val actobj1 = ActiveObject.newRemoteInstance(classOf[RemoteActiveObject1], "localhost", 7777) + //val actobj2 = TODO: create reference to server-managed active object (RemoteActiveObject2) + actor1.start - println(actor1 !! Message("actor1")) - println(actor2 !! Message("actor2")) + println(actor1 !! Message("actor1")) // activates and publishes actor remotely + println(actor2 !! Message("actor2")) // actor already activated and published remotely + + println(actobj1.foo("x", "y")) // activates and publishes active object methods remotely + // ... } }