ovsdb enable checkstyle on error
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / OvsdbConnectionInstance.java
index d2565bb41d0a37fb28797e89d9dfe0ffba69a9a5..b3378861d71f673cde913f8ce60e08e4dfc417d0 100644 (file)
@@ -9,17 +9,20 @@ package org.opendaylight.ovsdb.southbound;
 
 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
 
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
-
 import javax.annotation.Nonnull;
-
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.ovsdb.lib.EchoServiceCallbackFilters;
 import org.opendaylight.ovsdb.lib.LockAquisitionCallback;
 import org.opendaylight.ovsdb.lib.LockStolenCallback;
@@ -43,6 +46,7 @@ import org.opendaylight.ovsdb.lib.schema.TableSchema;
 import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+import org.opendaylight.ovsdb.southbound.ovsdb.transact.BridgeOperationalState;
 import org.opendaylight.ovsdb.southbound.ovsdb.transact.TransactCommand;
 import org.opendaylight.ovsdb.southbound.ovsdb.transact.TransactInvoker;
 import org.opendaylight.ovsdb.southbound.ovsdb.transact.TransactInvokerImpl;
@@ -56,13 +60,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.ListenableFuture;
-
 public class OvsdbConnectionInstance implements OvsdbClient {
     private static final Logger LOG = LoggerFactory.getLogger(OvsdbConnectionInstance.class);
     private OvsdbClient client;
@@ -85,12 +87,39 @@ public class OvsdbConnectionInstance implements OvsdbClient {
         this.instanceIdentifier = iid;
     }
 
-    public void transact(TransactCommand command) {
-        for (TransactInvoker transactInvoker: transactInvokers.values()) {
-            transactInvoker.invoke(command);
+    /**
+     * Apply the given command to the given events, based on the given bridge state.
+     *
+     * @param command The command to run.
+     * @param state The current bridge state.
+     * @param events The events to process.
+     */
+    public void transact(TransactCommand command, BridgeOperationalState state,
+                 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
+        for (TransactInvoker transactInvoker : transactInvokers.values()) {
+            transactInvoker.invoke(command, state, events);
+        }
+    }
+
+    /**
+     * Apply the given command to the given modifications, based on the given bridge state.
+     *
+     * @param command The command to run.
+     * @param state The current bridge state.
+     * @param modifications The modifications to process.
+     */
+    public void transact(TransactCommand command, BridgeOperationalState state,
+                 Collection<DataTreeModification<Node>> modifications) {
+        for (TransactInvoker transactInvoker : transactInvokers.values()) {
+            transactInvoker.invoke(command, state, modifications);
         }
     }
 
+    public ListenableFuture<List<OperationResult>> transact(
+            DatabaseSchema dbSchema, List<Operation> operations) {
+        return client.transact(dbSchema, operations);
+    }
+
     public void registerCallbacks() {
         if ( this.callback == null) {
             if (this.initialCreateData != null ) {
@@ -117,12 +146,9 @@ public class OvsdbConnectionInstance implements OvsdbClient {
         if (transactInvokers == null) {
             try {
                 transactInvokers = new HashMap<>();
-                List<String> databases = getDatabases().get();
-                for (String database : databases) {
-                    DatabaseSchema dbSchema = getSchema(database).get();
-                    if (dbSchema != null) {
-                        transactInvokers.put(dbSchema, new TransactInvokerImpl(this,dbSchema));
-                    }
+                DatabaseSchema dbSchema = getSchema(SouthboundConstants.OPEN_V_SWITCH).get();
+                if (dbSchema != null) {
+                    transactInvokers.put(dbSchema, new TransactInvokerImpl(this,dbSchema));
                 }
             } catch (InterruptedException | ExecutionException e) {
                 LOG.warn("Exception attempting to createTransactionInvokers {}", connectionInfo, e);
@@ -234,9 +260,11 @@ public class OvsdbConnectionInstance implements OvsdbClient {
         return client.transactBuilder(dbSchema);
     }
 
-    public ListenableFuture<List<OperationResult>> transact(
-            DatabaseSchema dbSchema, List<Operation> operations) {
-        return client.transact(dbSchema, operations);
+    @Override
+    public <E extends TableSchema<E>> TableUpdates monitor(
+            DatabaseSchema schema, List<MonitorRequest> monitorRequests,
+            MonitorHandle monitorHandle, MonitorCallBack callback) {
+        return null;
     }
 
     public <E extends TableSchema<E>> TableUpdates monitor(
@@ -324,13 +352,6 @@ public class OvsdbConnectionInstance implements OvsdbClient {
         this.instanceIdentifier = iid;
     }
 
-    @Override
-    public <E extends TableSchema<E>> TableUpdates monitor(
-            DatabaseSchema schema, List<MonitorRequest> monitorRequests,
-            MonitorHandle monitorHandle, MonitorCallBack callback) {
-        return null;
-    }
-
     public Entity getConnectedEntity() {
         return this.connectedEntity;
     }
@@ -367,7 +388,13 @@ public class OvsdbConnectionInstance implements OvsdbClient {
     public OvsdbNodeAugmentation getOvsdbNodeAugmentation() {
         return this.initialCreateData;
     }
+
     public void setOvsdbNodeAugmentation(OvsdbNodeAugmentation ovsdbNodeCreateData) {
         this.initialCreateData = ovsdbNodeCreateData;
     }
+
+    @Override
+    public void echo() {
+        client.echo();
+    }
 }