ovsdb enable checkstyle on error
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / ovsdb / transact / TransactCommandAggregator.java
index abdd696921ef5510a64ce218c0f14a3eb16c44c0..8bc4730704fe09947be5eb7911d887749b0fc345 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014, 2016 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -7,36 +7,65 @@
  */
 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
 
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+/**
+ * This transactional command aggregates all the Southbound commands.
+ */
 public class TransactCommandAggregator implements TransactCommand {
+    private static final Logger LOG = LoggerFactory.getLogger(TransactCommandAggregator.class);
 
-    private List<TransactCommand> commands = new ArrayList<TransactCommand>();
-    private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes;
-    private DataBroker db;
+    private static final Class<? extends TransactCommand>[] COMMAND_CLASSES =
+            new Class[] {
+                BridgeUpdateCommand.class,
+                OpenVSwitchBridgeAddCommand.class,
+                ControllerUpdateCommand.class,
+                ControllerRemovedCommand.class,
+                ProtocolUpdateCommand.class,
+                ProtocolRemovedCommand.class,
+                BridgeRemovedCommand.class,
+                TerminationPointCreateCommand.class,
+                TerminationPointDeleteCommand.class,
+                OvsdbNodeUpdateCommand.class,
+                AutoAttachUpdateCommand.class,
+                AutoAttachRemovedCommand.class,
+                QosUpdateCommand.class,
+                QosRemovedCommand.class,
+                QueueUpdateCommand.class,
+                QueueRemovedCommand.class,
+                TerminationPointUpdateCommand.class,
+            };
 
-    public TransactCommandAggregator(DataBroker db,AsyncDataChangeEvent<InstanceIdentifier<?>,
-            DataObject> changes) {
-        this.db = db;
-        this.changes = changes;
-        commands.add(new BridgeCreateCommand(changes));
-        commands.add(new BridgeRemovedCommand(db,changes));
-        commands.add(new TerminationPointCreateCommand(changes));
-        commands.add(new TerminationPointDeleteCommand(db, changes));
-        commands.add(new OvsdbNodeUpdateCommand(changes));
+    @Override
+    public void execute(TransactionBuilder transaction, BridgeOperationalState state,
+                        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
+        for (Class<? extends TransactCommand> commandClass : COMMAND_CLASSES) {
+            try {
+                commandClass.newInstance().execute(transaction, state, events);
+            } catch (InstantiationException | IllegalAccessException e) {
+                LOG.error("Error instantiating {}", commandClass, e);
+            }
+        }
     }
 
     @Override
-    public void execute(TransactionBuilder transaction) {
-        for (TransactCommand command:commands) {
-            command.execute(transaction);
+    public void execute(TransactionBuilder transaction, BridgeOperationalState state,
+                        Collection<DataTreeModification<Node>> modifications) {
+        for (Class<? extends TransactCommand> commandClass : COMMAND_CLASSES) {
+            try {
+                commandClass.newInstance().execute(transaction, state, modifications);
+            } catch (InstantiationException | IllegalAccessException e) {
+                LOG.error("Error instantiating {}", commandClass, e);
+            }
         }
     }
 }