3
我試圖將遠程akka系統連接到播放框架,它看起來像我有一個配置問題。連接Play 2框架與Akka遠程系統
我有一個遊戲框架控制器類和阿卡演員如低於當地對象是代碼:
當我運行顯示以下信息網頁
[ClassNotFoundException: akka.remote.RemoteActorRefProvider]
In C:\Users\FAISAL\workspace\Rakka\app\controllers\Application.java at line 21.
17 public static Result index() throws InterruptedException {
18
19 System.out.println(" Local Node Called0");
20
21 ActorSystem csystem = ActorSystem.create("Application", ConfigFactory.load().getConfig("LocalNode"));
22 ActorRef localNode = csystem.actorOf(new Props(LocalNode.class));
23
24 System.out.println(" Local Node Called1");
25 localNode.tell("Hello");
上是這樣的控制器:
public class Application extends Controller {
public static Result index() throws InterruptedException {
System.out.println(" Local Node Called0");
ActorSystem csystem = ActorSystem.create("Application", ConfigFactory.load().getConfig("LocalNode"));
ActorRef localNode = csystem.actorOf(new Props(LocalNode.class));
System.out.println(" Local Node Called1");
localNode.tell("Hello World");
System.out.println(" Local Node Called2");
Thread.sleep(5000);
csystem.shutdown();
return ok(index.render("I am OK"));
}
}
這是當地阿卡演員
public class LocalNode extends UntypedActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
Timeout timeout = new Timeout(Duration.parse("5 seconds"));
ActorRef master;
public void preStart()
{
/* Get reference to Master Node*/
master = getContext().actorFor("akka://[email protected]:2552/user/master");
}
@Override
public void onReceive(Object message) throws Exception {
System.out.println(" Future called ");
Future<Object> future = Patterns.ask(master , message.toString(), timeout);
String result = (String) Await.result(future, timeout.duration());
log.info("Messagefrom Server", result);
}
}
這是本地播放的conf文件
#confige the remote connection
LocalNode {
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
transport = "akka.remote.netty.NettyRemoteTransport"
netty {
hostname = "127.0.0.1"
port = 0
}
}
}
}
下面的代碼是從遠程系統阿卡。
這是遠程主
public class MasterNode implements Bootable
{
final ActorSystem system;
public MasterNode() {
system = ActorSystem.create("MasterNode", ConfigFactory.load()
.getConfig("master"));
ActorRef actor = system.actorOf(new Props(MasterActor.class),"master");
System.out.println(" Master Node is called ");
}
public void startup() {
}
public void shutdown() {
system.shutdown();
}
}
這是遠程阿卡演員系統
public class MasterActor extends UntypedActor {
@Override
public void onReceive(Object message) throws Exception {
if (message instanceof String) {
// Get reference to the message sender and reply back
getSender().tell(message + " got something");
}
}
}
這是從遠程阿卡配置
master {
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
transport = "akka.remote.netty.NettyRemoteTransport"
netty {
hostname = "127.0.0.1"
port = 2552
}
}
}}
要運行系統,我首先啓動Akka遠程系統,然後 啓動Play 2框架
運行播放framewrok後,我收到以下錯誤
[info] play - Application started (Dev)
Local Node Called0
[error] application -
! @6bol84j48 - Internal server error, for request [GET /] ->
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[ClassN
otFoundException: akka.remote.RemoteActorRefProvider]]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [
play_2.9.1.jar:2.0.2]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [
play_2.9.1.jar:2.0.2]
at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.
2]
at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.
2]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.j
ar:2.0.2]
Caused by: java.lang.ClassNotFoundException: akka.remote.RemoteActorRefProvider
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.7.0_01]
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.7.0_01]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0
_01]
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.7.0_01]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.7.0_01]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.7.0_01]
看起來像我沒有得到正確的事情取悅任何建議或幫助將受到歡迎。
感謝哥們剛剛添加的依賴,其確定。 –
感謝您的第一個suggestioj。但現在我有另一個問題,並且當我運行系統時,系統回覆留下1條消息。這裏是錯誤:Future稱爲[INFO] [09/30/2012 16:47:25.669] [Application-akka.actor.default-dispatcher-1] [akka:// Application/user/$ a] Messagefrom Server警告剩下的論點:1你有什麼建議嗎?我正在嘗試使用未來檢索簡單的消息 - faisal abdulai 1小時前 –
但是如果我不想綁定到任何可用端口,該怎麼辦?如果我使用port =,則會出現綁定失敗錯誤。 –
Ashesh