Remove JournalWriter.getLastEntry()
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / ActionRegistry.java
index 73a471c5b2f9c6daac9a496c57097231b5f48b88..2a91b5ab614c84fb8c1c8c37771513fa82b8af51 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.controller.remote.rpc.registry;
 
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorRef;
 import akka.actor.Address;
 import akka.actor.Props;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
@@ -36,14 +37,13 @@ import org.opendaylight.mdsal.dom.api.DOMActionInstance;
  */
 public class ActionRegistry extends BucketStoreActor<ActionRoutingTable> {
     private final ActorRef rpcRegistrar;
-    private final RemoteActionRegistryMXBeanImpl mxBean;
+
+    private RemoteActionRegistryMXBeanImpl mxBean;
 
     public ActionRegistry(final RemoteOpsProviderConfig config, final ActorRef rpcInvoker,
                           final ActorRef rpcRegistrar) {
         super(config, config.getRpcRegistryPersistenceId(), new ActionRoutingTable(rpcInvoker, ImmutableSet.of()));
-        this.rpcRegistrar = Preconditions.checkNotNull(rpcRegistrar);
-        this.mxBean = new RemoteActionRegistryMXBeanImpl(new BucketStoreAccess(self(), getContext().dispatcher(),
-                config.getAskDuration()), config.getAskDuration());
+        this.rpcRegistrar = requireNonNull(rpcRegistrar);
     }
 
     /**
@@ -60,16 +60,26 @@ public class ActionRegistry extends BucketStoreActor<ActionRoutingTable> {
     }
 
     @Override
-    public void postStop() {
+    public void preStart() {
+        super.preStart();
+        mxBean = new RemoteActionRegistryMXBeanImpl(new BucketStoreAccess(self(), getContext().dispatcher(),
+            getConfig().getAskDuration()), getConfig().getAskDuration());
+    }
+
+    @Override
+    public void postStop() throws Exception {
+        if (mxBean != null) {
+            mxBean.unregister();
+            mxBean = null;
+        }
         super.postStop();
-        this.mxBean.unregister();
     }
 
     @Override
     protected void handleCommand(final Object message) throws Exception {
-        if (message instanceof ActionRegistry.Messages.UpdateActions) {
+        if (message instanceof ActionRegistry.Messages.UpdateActions updateActions) {
             LOG.debug("handling updatesActionRoutes message");
-            updatesActionRoutes((Messages.UpdateActions) message);
+            updatesActionRoutes(updateActions);
         } else {
             super.handleCommand(message);
         }
@@ -111,7 +121,7 @@ public class ActionRegistry extends BucketStoreActor<ActionRoutingTable> {
 
         @VisibleForTesting
         public RemoteActionEndpoint(final ActorRef router, final Collection<DOMActionInstance> actions) {
-            this.router = Preconditions.checkNotNull(router);
+            this.router = requireNonNull(router);
             this.actions = ImmutableSet.copyOf(actions);
         }
 
@@ -139,11 +149,11 @@ public class ActionRegistry extends BucketStoreActor<ActionRoutingTable> {
             }
 
             Collection<DOMActionInstance> getAddedActions() {
-                return this.addedActions;
+                return addedActions;
             }
 
             Collection<DOMActionInstance> getRemovedActions() {
-                return this.removedActions;
+                return removedActions;
             }