Enable checkstyle for neutronvpn
[netvirt.git] / vpnservice / neutronvpn / neutronvpn-impl / src / main / java / org / opendaylight / netvirt / neutronvpn / InterfaceStateToTransportZoneListener.java
index 627f1cb02ac7f410616ca51d23463629137f1618..aeec7e58d59e45707fa44be61cf14ab6f99f4a50 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 HPE and others.  All rights reserved.
+ * Copyright (c) 2016 HPE 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,38 +9,33 @@ package org.opendaylight.netvirt.neutronvpn;
 
 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
-import org.opendaylight.genius.mdsalutil.MDSALDataStoreUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.config.rev160806.NeutronvpnConfig;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-
-public class InterfaceStateToTransportZoneListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceStateToTransportZoneListener> implements ClusteredDataTreeChangeListener<Interface>, AutoCloseable{
+public class InterfaceStateToTransportZoneListener
+    extends AsyncDataTreeChangeListenerBase<Interface, InterfaceStateToTransportZoneListener>
+    implements ClusteredDataTreeChangeListener<Interface>, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(InterfaceStateToTransportZoneListener.class);
-    private InterfaceStateManager ism;
+    private TransportZoneNotificationUtil ism;
+    private DataBroker dbx;
 
     public InterfaceStateToTransportZoneListener(DataBroker dbx, NeutronvpnManager nvManager) {
         super(Interface.class, InterfaceStateToTransportZoneListener.class);
-        ism = new InterfaceStateManager(dbx, nvManager);
-        Optional<NeutronvpnConfig> nvsConfig = MDSALDataStoreUtils.read(dbx,
-                LogicalDatastoreType.CONFIGURATION, InstanceIdentifier
-                .create(NeutronvpnConfig.class));
-        Boolean useTZ = true;
-        if (nvsConfig.isPresent()) {
-            useTZ = nvsConfig.get().isUseTransportZone() == null ? true : nvsConfig.get().isUseTransportZone();
-        }
-        if (isAutoTunnelConfigEnabled(useTZ)) {
-            registerListener(LogicalDatastoreType.OPERATIONAL, dbx);
-        }       
+        ism = new TransportZoneNotificationUtil(dbx, nvManager);
+        this.dbx = dbx;
+    }
 
+    public void start() {
+        LOG.info("{} start", getClass().getSimpleName());
+        if (ism.isAutoTunnelConfigEnabled()) {
+            registerListener(LogicalDatastoreType.OPERATIONAL, dbx);
+        }
     }
 
     @Override
@@ -51,8 +46,7 @@ public class InterfaceStateToTransportZoneListener extends AsyncDataTreeChangeLi
 
     @Override
     protected void remove(InstanceIdentifier<Interface> identifier, Interface del) {
-        // FIXME: once the TZ is declared it will stay forever
-
+        // once the TZ is declared it will stay forever
     }
 
     @Override
@@ -65,19 +59,10 @@ public class InterfaceStateToTransportZoneListener extends AsyncDataTreeChangeLi
     protected void add(InstanceIdentifier<Interface> identifier, Interface add) {
         ism.updateTrasportZone(add);
     }
-    
+
     @Override
     protected InterfaceStateToTransportZoneListener getDataTreeChangeListener() {
         return InterfaceStateToTransportZoneListener.this;
     }
-    
-    private boolean isAutoTunnelConfigEnabled(Boolean useTZ) {
-        if (useTZ) {
-            LOG.info("using automatic tunnel configuration");
-        } else {
-            LOG.info("don't use automatic tunnel configuration");
-        }
-        return useTZ;
-    }
 
-}
\ No newline at end of file
+}