Use ServiceTracker instead of WaitingServiceTracker 52/72752/2
authorTom Pantelis <tompantelis@gmail.com>
Thu, 7 Jun 2018 12:14:46 +0000 (08:14 -0400)
committerStephen Kitt <skitt@redhat.com>
Thu, 7 Jun 2018 14:03:33 +0000 (14:03 +0000)
WaitingServiceTracker is in config-api which is going away.
WaitingServiceTracker is just a thin wrapper around ServiceTracker
anyway so just use ServiceTracker directly.

Change-Id: I213550d6f82004905578a2f86865cb6288f411b0
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
bgpmanager/impl/src/main/java/org/opendaylight/netvirt/bgpmanager/BgpConfigurationManager.java
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/FibManagerImpl.java

index 4ccdca2cdf9ae5b247eeefa2fdffd165fb37c558..989f1ffa14a68b809e58cb0fff49ed0f87d03102 100755 (executable)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.bgpmanager;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.net.InetAddresses;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import io.netty.util.concurrent.GlobalEventExecutor;
@@ -47,7 +48,6 @@ import javax.inject.Singleton;
 import org.apache.thrift.TApplicationException;
 import org.apache.thrift.TException;
 import org.apache.thrift.transport.TTransport;
-import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -132,6 +132,7 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
 import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -258,9 +259,20 @@ public class BgpConfigurationManager {
         initer.countDown();
 
         GlobalEventExecutor.INSTANCE.execute(() -> {
-            final WaitingServiceTracker<IBgpManager> tracker = WaitingServiceTracker.create(
-                    IBgpManager.class, bundleContext);
-            bgpManager = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
+            ServiceTracker<IBgpManager, ?> tracker = null;
+            try {
+                tracker = new ServiceTracker<>(bundleContext, IBgpManager.class, null);
+                tracker.open();
+                bgpManager = (IBgpManager) tracker.waitForService(TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES));
+                Preconditions.checkState(bgpManager != null, "IBgpManager service not found");
+            } catch (InterruptedException e) {
+                throw new IllegalStateException("Error retrieving IBgpManager service", e);
+            } finally {
+                if (tracker != null) {
+                    tracker.close();
+                }
+            }
+
             if (InetAddresses.isInetAddress(getBgpSdncMipIp())) {
                 InetSocketAddress bgpThriftServerSocketAddr = new InetSocketAddress(getBgpSdncMipIp(),
                         Integer.parseInt(updatePort));
@@ -409,7 +421,7 @@ public class BgpConfigurationManager {
             } else {
                 LOG.debug("Not owner: hasOwner: {}, isOwner: {}", ownershipChange.getState().hasOwner(),
                         ownershipChange.getState().isOwner());
-                if ((bgpThriftService != null) && (bgpThriftService.isBgpThriftServiceStarted())) {
+                if (bgpThriftService != null && bgpThriftService.isBgpThriftServiceStarted()) {
                     //close the bgp Thrift Update-SERVER port opened on non-Entity Owner
                     bgpThriftService.stop();
                     bgpThriftService = null;
index cd4beb335ca2b5d5239629ec7ee7f7861d790e64..ec005fab647161be798c8ba7aa3ee252704680cb 100755 (executable)
@@ -8,13 +8,14 @@
 package org.opendaylight.netvirt.fibmanager;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import java.math.BigInteger;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
 import org.opendaylight.netvirt.fibmanager.api.RouteOrigin;
@@ -24,6 +25,7 @@ import org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComp
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry;
 import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -48,10 +50,20 @@ public class FibManagerImpl implements IFibManager {
         this.interVpnLinkCache = interVpnLinkCache;
 
         GlobalEventExecutor.INSTANCE.execute(() -> {
-            final WaitingServiceTracker<IVpnManager> tracker = WaitingServiceTracker.create(
-                IVpnManager.class, bundleContext);
-            vpnmanager = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
-            LOG.info("FibManagerImpl initialized. IVpnManager={}", vpnmanager);
+            ServiceTracker<IVpnManager, ?> tracker = null;
+            try {
+                tracker = new ServiceTracker<>(bundleContext, IVpnManager.class, null);
+                tracker.open();
+                vpnmanager = (IVpnManager) tracker.waitForService(TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES));
+                Preconditions.checkState(vpnmanager != null, "IVpnManager service not found");
+                LOG.info("FibManagerImpl initialized. IVpnManager={}", vpnmanager);
+            } catch (IllegalStateException | InterruptedException e) {
+                LOG.error("Error retrieving IVpnManager service", e);
+            } finally {
+                if (tracker != null) {
+                    tracker.close();
+                }
+            }
         });
     }