Bug 8055: use method references instead of lambdas
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / HwvtepConnectionInstance.java
index db05b9a1dbab1d8113dc70880a676274199c678b..c8c859a80d4f226e95eb509fe07e92c1f3570ce5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 Ericsson India Global Services Pvt Ltd. 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,
@@ -9,6 +9,7 @@
 package org.opendaylight.ovsdb.hwvtepsouthbound;
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -16,13 +17,13 @@ import java.util.concurrent.ExecutionException;
 
 import javax.annotation.Nonnull;
 
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.TransactCommand;
 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.TransactInvoker;
 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.TransactInvokerImpl;
 import org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md.TransactionInvoker;
-import org.opendaylight.ovsdb.lib.EchoServiceCallbackFilters;
 import org.opendaylight.ovsdb.lib.LockAquisitionCallback;
 import org.opendaylight.ovsdb.lib.LockStolenCallback;
 import org.opendaylight.ovsdb.lib.MonitorCallBack;
@@ -53,7 +54,7 @@ import org.slf4j.LoggerFactory;
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ListenableFuture;
 
-public class HwvtepConnectionInstance implements OvsdbClient{
+public class HwvtepConnectionInstance {
     private static final Logger LOG = LoggerFactory.getLogger(HwvtepConnectionInstance.class);
     private ConnectionInfo connectionInfo;
     private OvsdbClient client;
@@ -65,17 +66,22 @@ public class HwvtepConnectionInstance implements OvsdbClient{
     private Entity connectedEntity;
     private EntityOwnershipCandidateRegistration deviceOwnershipCandidateRegistration;
     private HwvtepGlobalAugmentation initialCreatedData = null;
+    private HwvtepDeviceInfo deviceInfo;
+    private DataBroker dataBroker;
+    private final HwvtepConnectionManager hwvtepConnectionManager;
 
-
-    HwvtepConnectionInstance (ConnectionInfo key,OvsdbClient client,
-                    InstanceIdentifier<Node> iid, TransactionInvoker txInvoker) {
+    HwvtepConnectionInstance (HwvtepConnectionManager hwvtepConnectionManager, ConnectionInfo key, OvsdbClient client,
+                              InstanceIdentifier<Node> iid, TransactionInvoker txInvoker, DataBroker dataBroker) {
+        this.hwvtepConnectionManager = hwvtepConnectionManager;
         this.connectionInfo = key;
         this.client = client;
         this.instanceIdentifier = iid;
         this.txInvoker = txInvoker;
+        this.deviceInfo = new HwvtepDeviceInfo(this);
+        this.dataBroker = dataBroker;
     }
 
-    public void transact(TransactCommand command) {
+    public synchronized void transact(TransactCommand command) {
         for (TransactInvoker transactInvoker: transactInvokers.values()) {
             transactInvoker.invoke(command);
         }
@@ -122,16 +128,21 @@ public class HwvtepConnectionInstance implements OvsdbClient{
         if (tables != null) {
             List<MonitorRequest> monitorRequests = Lists.newArrayList();
             for (String tableName : tables) {
-                LOG.debug("HwvtepSouthbound monitoring table {} in {}", tableName, dbSchema.getName());
-                GenericTableSchema tableSchema = dbSchema.table(tableName, GenericTableSchema.class);
-                Set<String> columns = tableSchema.getColumns();
-                MonitorRequestBuilder<GenericTableSchema> monitorBuilder = MonitorRequestBuilder.builder(tableSchema);
-                for (String column : columns) {
-                    monitorBuilder.addColumn(column);
+                if (!HwvtepSouthboundConstants.SKIP_HWVTEP_TABLE.containsKey(tableName)) {
+                    LOG.info("HwvtepSouthbound monitoring Hwvtep schema table {}", tableName);
+                    GenericTableSchema tableSchema = dbSchema.table(tableName, GenericTableSchema.class);
+                    Set<String> columns = new HashSet<>(tableSchema.getColumns());
+                    List<String> skipColumns = HwvtepSouthboundConstants.SKIP_COLUMN_FROM_HWVTEP_TABLE.get(tableName);
+                    if (skipColumns != null) {
+                        LOG.info("HwvtepSouthbound NOT monitoring columns {} in table {}", skipColumns, tableName);
+                        columns.removeAll(skipColumns);
+                    }
+                    monitorRequests.add(new MonitorRequestBuilder<>(tableSchema)
+                            .addColumns(columns)
+                            .with(new MonitorSelect(true, true, true, true)).build());
                 }
-                monitorRequests.add(monitorBuilder.with(new MonitorSelect(true, true, true, true)).build());
             }
-            this.callback.update(monitor(dbSchema, monitorRequests, callback),dbSchema);
+            this.callback.update(monitor(dbSchema, monitorRequests, callback), dbSchema);
         } else {
             LOG.warn("No tables for schema {} for database {} for key {}",dbSchema,database,connectionInfo);
         }
@@ -148,6 +159,10 @@ public class HwvtepConnectionInstance implements OvsdbClient{
          */
     }
 
+    public DataBroker getDataBroker() {
+        return dataBroker;
+    }
+
     public ListenableFuture<List<String>> getDatabases() {
         return client.getDatabases();
     }
@@ -169,7 +184,6 @@ public class HwvtepConnectionInstance implements OvsdbClient{
         return client.monitor(schema, monitorRequests, callback);
     }
 
-    @Override
     public <E extends TableSchema<E>> TableUpdates monitor(DatabaseSchema schema,
                     List<MonitorRequest> monitorRequests, MonitorHandle monitorHandle, MonitorCallBack callback) {
         return null;
@@ -191,19 +205,6 @@ public class HwvtepConnectionInstance implements OvsdbClient{
         return client.unLock(lockId);
     }
 
-    public void startEchoService(EchoServiceCallbackFilters callbackFilters) {
-        client.startEchoService(callbackFilters);
-    }
-
-    public void stopEchoService() {
-        client.stopEchoService();
-    }
-
-    @Override
-    public void echo() {
-        client.echo();
-    }
-
     public OvsdbConnectionInfo getConnectionInfo() {
         return client.getConnectionInfo();
     }
@@ -246,7 +247,7 @@ public class HwvtepConnectionInstance implements OvsdbClient{
 
     public NodeKey getNodeKey() {
         //TODO: What is the alternative here?
-        return getInstanceIdentifier().firstKeyOf(Node.class, NodeKey.class);
+        return getInstanceIdentifier().firstKeyOf(Node.class);
     }
 
     public NodeId getNodeId() {
@@ -255,6 +256,7 @@ public class HwvtepConnectionInstance implements OvsdbClient{
 
     public void setInstanceIdentifier(InstanceIdentifier<Node> iid) {
         this.instanceIdentifier = iid;
+        hwvtepConnectionManager.putConnectionInstance(instanceIdentifier, this);
     }
 
     public Entity getConnectedEntity() {
@@ -293,4 +295,15 @@ public class HwvtepConnectionInstance implements OvsdbClient{
     public void setHwvtepGlobalAugmentation(HwvtepGlobalAugmentation hwvtepGlobalData) {
         this.initialCreatedData = hwvtepGlobalData;
     }
+
+    public HwvtepGlobalAugmentation getHwvtepGlobalAugmentation() {
+        return this.initialCreatedData;
+    }
+    public HwvtepDeviceInfo getDeviceInfo() {
+        return this.deviceInfo;
+    }
+
+    public OvsdbClient getOvsdbClient() {
+        return client;
+    }
 }