我尝试按照Typed Actors (Java)TypedActor
上的示例在 Java中实现 a 。但我在挣扎。我已添加, ,但还不够。我在 Eclipse 中遇到错误,所以我还添加了和到我的构建路径。akka-actor-1.1-M1.jar
akka-typed-actor-1.1-M1.jar
scala-library.jar
aspectwerkz-2.0.jar
aspectwerkz-core-2.0.jar
我尝试使用带有自定义构造函数的 TypedActor。
但是现在我在编译时遇到错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.codehaus.aspectwerkz.proxy.Proxy.newInstance([Ljava/lang/Class;[Ljava/lang/Object;ZZ)Ljava/lang/Object;
at akka.actor.TypedActor$.newInstance(TypedActor.scala:596)
at akka.actor.TypedActor$.newInstance(TypedActor.scala:634)
at akka.actor.TypedActor.newInstance(TypedActor.scala)
at com.example.actor.ActorTest.main(ActorTest.java:12)
这是我的代码BaseActor
:
import akka.actor.TypedActor;
public class BaseActor extends TypedActor implements BaseService {
private String str;
private int num;
public BaseActor(String str, int num) {
this.str = str;
this.num = num;
System.out.println("booted");
}
public void testData(String str, int num) {
System.out.println(this.str + " " + this.num);
System.out.println(str + " " + num);
}
}
我interface
的服务:
public interface BaseService {
public void testData(String str, int num);
}
和一个测试类:
import akka.actor.TypedActor;
import akka.actor.TypedActorFactory;
public class ActorTest {
public static void main(String[] args) {
BaseService service = TypedActor.newInstance(BaseService.class,
new TypedActorFactory() {
public TypedActor create() {
return new BaseActor("someString", 12);
}
});
service.testData("Hello", 6);
}
}
在示例中,他们写道:
Service service = TypedActor.newInstance(classOf[Service],
new TypedActorFactory() {
public TypedActor create() {
return new ServiceWithConstructorArgsImpl("someString", 500L));
});
但我不认为那classOf[Service]
是 Java,它看起来更像 Scala。
如何TypedActor
使用自定义构造函数实现一个?