Added remote active object example
This commit is contained in:
parent
46b7cc8c72
commit
ed4303af88
4 changed files with 48 additions and 9 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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")))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue