Bump MRI upstreams
[openflowplugin.git] / applications / forwardingrules-manager / src / main / java / org / opendaylight / openflowplugin / applications / frm / impl / AbstractListeningCommiter.java
index 77390a7cc34342da7a7b65c8b7db99556374e7e7..731232da9a71f552e1fa6ffca14518d5cafc4b88 100644 (file)
@@ -7,10 +7,12 @@
  */
 package org.opendaylight.openflowplugin.applications.frm.impl;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Collection;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.binding.api.DataBroker;
@@ -43,22 +45,23 @@ public abstract class AbstractListeningCommiter<T extends DataObject>
     protected final ListenerRegistrationHelper registrationHelper;
     protected ListenerRegistration<AbstractListeningCommiter> listenerRegistration;
 
-    public AbstractListeningCommiter(final ForwardingRulesManager provider, final DataBroker dataBroker,
+    @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "See FIXME below")
+    protected AbstractListeningCommiter(final ForwardingRulesManager provider, final DataBroker dataBroker,
                                      final ListenerRegistrationHelper registrationHelper) {
-        this.provider = Preconditions.checkNotNull(provider, "ForwardingRulesManager can not be null!");
-        this.nodeConfigurator = Preconditions.checkNotNull(provider.getNodeConfigurator(),
-                "NodeConfigurator can not be null!");
-        this.dataBroker = Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!");
-        this.registrationHelper = Preconditions.checkNotNull(registrationHelper, "registrationHelper can not be null!");
+        this.provider = requireNonNull(provider, "ForwardingRulesManager can not be null!");
+        this.nodeConfigurator = requireNonNull(provider.getNodeConfigurator(), "NodeConfigurator can not be null!");
+        this.dataBroker = requireNonNull(dataBroker, "DataBroker can not be null!");
+        this.registrationHelper = requireNonNull(registrationHelper, "registrationHelper can not be null!");
+
+        // FIXME: this may start listening on an uninitialized object: clean up the lifecycle here
         registerListener();
         provider.addRecoverableListener(this);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
-        Preconditions.checkNotNull(changes, "Changes may not be null!");
-        LOG.trace("Received data changes :{}", changes);
+    public void onDataTreeChanged(final Collection<DataTreeModification<T>> changes) {
+        LOG.trace("Received data changes :{}", requireNonNull(changes, "Changes may not be null!"));
 
         for (DataTreeModification<T> change : changes) {
             final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
@@ -113,20 +116,20 @@ public abstract class AbstractListeningCommiter<T extends DataObject>
     }
 
     @Override
-    public void registerListener() {
+    public final void registerListener() {
         final DataTreeIdentifier<T> treeId =
                 DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, getWildCardPath());
         Futures.addCallback(registrationHelper.checkedRegisterListener(treeId, this),
                 new FutureCallback<ListenerRegistration<AbstractListeningCommiter>>() {
                     @Override
                     public void onSuccess(
-                            @Nullable ListenerRegistration<AbstractListeningCommiter> flowListenerRegistration) {
+                            @Nullable final ListenerRegistration<AbstractListeningCommiter> flowListenerRegistration) {
                         LOG.info("{} registered successfully", flowListenerRegistration.getInstance());
                         listenerRegistration = flowListenerRegistration;
                     }
 
                     @Override
-                    public void onFailure(Throwable throwable) {
+                    public void onFailure(final Throwable throwable) {
                         LOG.error("Registration failed ", throwable);
                     }
                 }, MoreExecutors.directExecutor());
@@ -139,7 +142,7 @@ public abstract class AbstractListeningCommiter<T extends DataObject>
     protected abstract InstanceIdentifier<T> getWildCardPath();
 
     private boolean preConfigurationCheck(final InstanceIdentifier<FlowCapableNode> nodeIdent) {
-        Preconditions.checkNotNull(nodeIdent, "FlowCapableNode identifier can not be null!");
+        requireNonNull(nodeIdent, "FlowCapableNode identifier can not be null!");
         // In single node cluster, node should be in local cache before we get any flow/group/meter
         // data change event from data store. So first check should pass.
         // In case of 3-node cluster, when shard leader changes, clustering will send blob of data