Java Play2- Akka工作 [英] Java Play2- Akka for jobs

查看:100
本文介绍了Java Play2- Akka工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用akka在java play2中创建工作.

I am trying to create a job in java play2 using akka.

我总是遇到相同的错误error: cannot find symbol

I always get the same error error: cannot find symbol

它指向system.actorOf() Intellij和Eclipse不会给我一个错误消息msg.

And it points to system.actorOf() Intellij and Eclipse don't give me an error msg.

但是我找不到这种方法.我使用了以下导入

But I can not find this method. I used the following imports

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()吗?

Maybe the docs are outdated and they have removed the 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");

    }
}

.

哦... google将我重定向到了过时的文档.现在是Akka.System() ..

oh... google redirected me to the outdated documentation. It's Akka.System() now..

  • 任何人都可以给我一个有关如何使用up2date代码创建tickActor的示例吗?

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

推荐答案

已解决.

文档中还有一些错别字.

Btw there are some typos in the documentation.

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"
                );

    }



}

这篇关于Java Play2- Akka工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆