From 4e9f42a80ed33914b17c5dc8b1d982fe8d10a81b Mon Sep 17 00:00:00 2001 From: Gary Wu Date: Thu, 18 Dec 2014 16:08:58 -0800 Subject: [PATCH] Fix Akka exception: cannot use non-static local Creator to create actors Fix Akka exception "cannot use non-static local Creator to create actors; make it static or top-level" running JUnit tests in Eclipse. Allows Eclipse JUnit tests to complete in: sal-akka-raft sal-clustering-common sal-distributed-datastore sal-remoterpc-connector Change-Id: I64b83c12ed44773bbe7dee5666872209f3346b15 Signed-off-by: Gary Wu --- .../cluster/example/ClientActor.java | 11 ++--------- .../cluster/example/ExampleActor.java | 10 ++-------- .../example/ExampleRoleChangeListener.java | 9 +-------- .../notifications/RoleChangeNotifier.java | 9 +-------- .../actor/MeteredBoundedMailboxTest.java | 9 +-------- .../controller/remote/rpc/RpcManager.java | 19 +++++-------------- 6 files changed, 12 insertions(+), 55 deletions(-) diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ClientActor.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ClientActor.java index 59bec91511..8022e72157 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ClientActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ClientActor.java @@ -13,7 +13,6 @@ import akka.actor.Props; import akka.actor.UntypedActor; import akka.event.Logging; import akka.event.LoggingAdapter; -import akka.japi.Creator; import org.opendaylight.controller.cluster.example.messages.KeyValue; import org.opendaylight.controller.cluster.example.messages.KeyValueSaved; @@ -27,14 +26,8 @@ public class ClientActor extends UntypedActor { this.target = target; } - public static Props props(final ActorRef target){ - return Props.create(new Creator(){ - private static final long serialVersionUID = 1L; - - @Override public ClientActor create() throws Exception { - return new ClientActor(target); - } - }); + public static Props props(final ActorRef target) { + return Props.create(ClientActor.class, target); } @Override public void onReceive(Object message) throws Exception { diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java index 6c65021d86..684c3ac30e 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java @@ -10,7 +10,6 @@ package org.opendaylight.controller.cluster.example; import akka.actor.ActorRef; import akka.actor.Props; -import akka.japi.Creator; import com.google.common.base.Optional; import com.google.protobuf.ByteString; import java.io.ByteArrayInputStream; @@ -53,13 +52,8 @@ public class ExampleActor extends RaftActor { } public static Props props(final String id, final Map peerAddresses, - final Optional configParams){ - return Props.create(new Creator(){ - - @Override public ExampleActor create() throws Exception { - return new ExampleActor(id, peerAddresses, configParams); - } - }); + final Optional configParams) { + return Props.create(ExampleActor.class, id, peerAddresses, configParams); } @Override public void onReceiveCommand(Object message) throws Exception{ diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ExampleRoleChangeListener.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ExampleRoleChangeListener.java index c0ee095367..1676a41c56 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ExampleRoleChangeListener.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/ExampleRoleChangeListener.java @@ -1,10 +1,8 @@ package org.opendaylight.controller.cluster.example; -import akka.actor.Actor; import akka.actor.ActorRef; import akka.actor.Cancellable; import akka.actor.Props; -import akka.japi.Creator; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -46,12 +44,7 @@ public class ExampleRoleChangeListener extends AbstractUntypedActor implements A } public static Props getProps(final String memberName) { - return Props.create(new Creator() { - @Override - public Actor create() throws Exception { - return new ExampleRoleChangeListener(memberName); - } - }); + return Props.create(ExampleRoleChangeListener.class, memberName); } @Override diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java index a9aa56174d..d065f6d211 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/notifications/RoleChangeNotifier.java @@ -8,11 +8,9 @@ package org.opendaylight.controller.cluster.notifications; -import akka.actor.Actor; import akka.actor.ActorPath; import akka.actor.ActorRef; import akka.actor.Props; -import akka.japi.Creator; import akka.serialization.Serialization; import com.google.common.collect.Maps; import java.util.Map; @@ -35,12 +33,7 @@ public class RoleChangeNotifier extends AbstractUntypedActor implements AutoClos } public static Props getProps(final String memberId) { - return Props.create(new Creator() { - @Override - public Actor create() throws Exception { - return new RoleChangeNotifier(memberId); - } - }); + return Props.create(RoleChangeNotifier.class, memberId); } @Override diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java index 60efb9d7ca..b706d20d1a 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java @@ -12,7 +12,6 @@ import akka.actor.ActorSystem; import akka.actor.DeadLetter; import akka.actor.Props; import akka.actor.UntypedActor; -import akka.japi.Creator; import akka.testkit.JavaTestKit; import org.junit.After; import org.junit.Before; @@ -80,13 +79,7 @@ public class MeteredBoundedMailboxTest { } public static Props props(final ReentrantLock lock){ - return Props.create(new Creator(){ - private static final long serialVersionUID = 1L; - @Override - public PingPongActor create() throws Exception { - return new PingPongActor(lock); - } - }); + return Props.create(PingPongActor.class, lock); } @Override diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcManager.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcManager.java index a840712999..34c4401f50 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcManager.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcManager.java @@ -13,8 +13,8 @@ import akka.actor.ActorRef; import akka.actor.OneForOneStrategy; import akka.actor.Props; import akka.actor.SupervisorStrategy; -import akka.japi.Creator; import akka.japi.Function; +import java.util.Set; import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor; import org.opendaylight.controller.remote.rpc.messages.UpdateSchemaContext; import org.opendaylight.controller.remote.rpc.registry.RpcRegistry; @@ -26,8 +26,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.duration.Duration; -import java.util.Set; - /** * This class acts as a supervisor, creates all the actors, resumes them, if an exception is thrown. * @@ -61,17 +59,10 @@ public class RpcManager extends AbstractUntypedActor { } - public static Props props(final SchemaContext schemaContext, - final Broker.ProviderSession brokerSession, - final RpcProvisionRegistry rpcProvisionRegistry) { - return Props.create(new Creator() { - private static final long serialVersionUID = 1L; - @Override - public RpcManager create() throws Exception { - return new RpcManager(schemaContext, brokerSession, rpcProvisionRegistry); - } - }); - } + public static Props props(final SchemaContext schemaContext, final Broker.ProviderSession brokerSession, + final RpcProvisionRegistry rpcProvisionRegistry) { + return Props.create(RpcManager.class, schemaContext, brokerSession, rpcProvisionRegistry); + } private void createRpcActors() { LOG.debug("Create rpc registry and broker actors"); -- 2.36.6