FRM code cleanup.
[openflowplugin.git] / applications / forwardingrules-manager / src / main / java / org / opendaylight / openflowplugin / applications / frm / impl / FlowForwarder.java
index b8cc16736ac3d0692846e4db5735e8cba16b4aca..99935e4f1213bf28db965f7f18290a6a7c386ae3 100644 (file)
@@ -26,7 +26,6 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.ReadTransaction;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -85,25 +84,14 @@ public class FlowForwarder extends AbstractListeningCommiter<Flow> {
 
     private ListenerRegistration<FlowForwarder> listenerRegistration;
 
-    public FlowForwarder(final ForwardingRulesManager manager, final DataBroker db) {
-        super(manager, db);
-    }
+    private final BundleFlowForwarder bundleFlowForwarder;
 
-    @Override
-    @SuppressWarnings("IllegalCatch")
-    public void registerListener() {
-        final DataTreeIdentifier<Flow> treeId = DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
-                getWildCardPath());
-        try {
-            listenerRegistration = dataBroker.registerDataTreeChangeListener(treeId, FlowForwarder.this);
-        } catch (final Exception e) {
-            LOG.warn("FRM Flow DataTreeChange listener registration fail!");
-            LOG.debug("FRM Flow DataTreeChange listener registration fail ..", e);
-            throw new IllegalStateException("FlowForwarder startup fail! System needs restart.", e);
-        }
+    public FlowForwarder(final ForwardingRulesManager manager, final DataBroker db,
+                         final ListenerRegistrationHelper registrationHelper) {
+        super(manager, db, registrationHelper);
+        bundleFlowForwarder = new BundleFlowForwarder(manager);
     }
 
-
     @Override
     public  void deregisterListener() {
         close();
@@ -296,7 +284,7 @@ public class FlowForwarder extends AbstractListeningCommiter<Flow> {
         return true;
     }
 
-    private StaleFlow makeStaleFlow(InstanceIdentifier<Flow> identifier, Flow del,
+    private static StaleFlow makeStaleFlow(InstanceIdentifier<Flow> identifier, Flow del,
             InstanceIdentifier<FlowCapableNode> nodeIdent) {
         StaleFlowBuilder staleFlowBuilder = new StaleFlowBuilder(del);
         return staleFlowBuilder.setId(del.getId()).build();
@@ -305,13 +293,13 @@ public class FlowForwarder extends AbstractListeningCommiter<Flow> {
     private void persistStaleFlow(StaleFlow staleFlow, InstanceIdentifier<FlowCapableNode> nodeIdent) {
         WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
         writeTransaction.put(LogicalDatastoreType.CONFIGURATION, getStaleFlowInstanceIdentifier(staleFlow, nodeIdent),
-                staleFlow, false);
+                staleFlow);
 
         FluentFuture<?> submitFuture = writeTransaction.commit();
         handleStaleFlowResultFuture(submitFuture);
     }
 
-    private void handleStaleFlowResultFuture(FluentFuture<?> submitFuture) {
+    private static void handleStaleFlowResultFuture(FluentFuture<?> submitFuture) {
         submitFuture.addCallback(new FutureCallback<Object>() {
             @Override
             public void onSuccess(Object result) {
@@ -326,7 +314,7 @@ public class FlowForwarder extends AbstractListeningCommiter<Flow> {
 
     }
 
-    private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight
+    private static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight
         .flow.inventory.rev130819.tables.table.StaleFlow> getStaleFlowInstanceIdentifier(
             StaleFlow staleFlow, InstanceIdentifier<FlowCapableNode> nodeIdent) {
         return nodeIdent.child(Table.class, new TableKey(staleFlow.getTableId())).child(
@@ -466,4 +454,4 @@ public class FlowForwarder extends AbstractListeningCommiter<Flow> {
             resultFuture.setException(throwable);
         }
     }
-}
+}
\ No newline at end of file