2012-08-24 46 views
0

我想在使用akka的java play2中創建一個工作。Java Play2- Akka找工作

我總是得到同樣的錯誤error: cannot find symbol

並將其指向system.actorOf()的IntelliJ和Eclipse不給我一個錯誤味精。

但我找不到這種方法。我使用以下進口

import play.libs.Akka; 
import akka.actor.ActorSystem; 
import akka.actor.ActorRef; 
import akka.actor.UntypedActorFactory; 
import akka.actor.UntypedActor; 
import akka.actor.Props; 
import akka.actor.ActorRefFactory; 

也許文檔已過時,他們已經刪除了system.actorOf()

public class Global extends GlobalSettings { 

    ActorRef tickActor = system.actorOf(new Props().withCreator(new UntypedActorFactory() { 
      public UntypedActor create() { 
      return new UntypedActor() { 
       public void onReceive(Object message) { 
       if (message.equals("Log")) { 
        controllers.Application.log(); 
       } else { 
        unhandled(message); 
       } 
       } 
      }; 
      } 
     })); 

    @Override 
    public void onStart(Application app) { 
     Cancellable cancellable = system.scheduler().schedule(Duration.Zero(), Duration.create(10, TimeUnit.SECONDS), 
       tickActor, "Log"); 

    } 
} 

編輯:

哦...谷歌重定向到過時的文檔。它現在是Akka.System() ..

  • 任何人都可以舉例說明如何使用up2date代碼創建tickActor嗎?

http://www.playframework.org/documentation/2.0.2/JavaAkka

回答

1

解決它。

順便說一句,在文檔中有一些錯別字。

import java.util.concurrent.TimeUnit; 

import play.*; 
import play.mvc.*; 
import play.mvc.Http.RequestHeader; 

import static play.mvc.Results.*; 
import play.libs.Akka; 
import akka.actor.ActorSystem; 
import akka.actor.ActorRef; 
import akka.actor.UntypedActorFactory; 
import akka.actor.UntypedActor; 
import akka.actor.Props; 
import akka.actor.ActorRefFactory; 

import akka.util.*; 
public class Global extends GlobalSettings { 

    ActorRef tickActor; 

    @Override 
    public void onStart(Application app) { 
     Logger.info("D"); 
     tickActor = Akka.system().actorOf((new Props().withCreator(new UntypedActorFactory() { 
       public UntypedActor create() { 
        return new UntypedActor() { 
         public void onReceive(Object message) { 
         if (message.equals("Log")) { 
           //Do something 
         // controllers.Application.log(); 
         } else { 
          unhandled(message); 
         } 
         } 
        }; 
        } 
       }))); 
     Akka.system().scheduler().schedule(
        Duration.create(0, TimeUnit.MILLISECONDS), 
        Duration.create(30, TimeUnit.MINUTES), 
        tickActor, 
        "Log" 
       ); 

    } 



}