From 8ee6ca2d2f1243a309959ca680d20211bffac58d Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Wed, 6 Jun 2018 09:38:37 -0400 Subject: [PATCH] Use ServiceTracker instead of WaitingServiceTracker WaitingServiceTracker is in config-api which is going away. WaitingServiceTracker is just a thin wrapper around ServiceTracker so just use ServiceTracker directly. Change-Id: I1a2742941db31ed98431fefee8310a4cb6735730 Signed-off-by: Tom Pantelis --- .../PCEPTunnelClusterSingletonService.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/pcep/tunnel/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/PCEPTunnelClusterSingletonService.java b/pcep/tunnel/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/PCEPTunnelClusterSingletonService.java index b7901e3205..1c23702c72 100644 --- a/pcep/tunnel/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/PCEPTunnelClusterSingletonService.java +++ b/pcep/tunnel/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/PCEPTunnelClusterSingletonService.java @@ -9,14 +9,15 @@ package org.opendaylight.bgpcep.pcep.tunnel.provider; import static java.util.Objects.requireNonNull; +import com.google.common.base.Preconditions; import com.google.common.util.concurrent.FluentFuture; import java.util.Dictionary; import java.util.Hashtable; +import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; import javax.annotation.concurrent.GuardedBy; import org.opendaylight.bgpcep.programming.spi.InstructionScheduler; import org.opendaylight.bgpcep.topology.DefaultTopologyReference; -import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService; @@ -29,7 +30,10 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.osgi.framework.Constants; +import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceRegistration; +import org.osgi.util.tracker.ServiceTracker; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,12 +61,24 @@ public final class PCEPTunnelClusterSingletonService implements ClusterSingleton this.tunnelTopologyId = requireNonNull(tunnelTopologyId); final TopologyId pcepTopologyId = pcepTopology.firstKeyOf(Topology.class).getTopologyId(); - final WaitingServiceTracker schedulerTracker = - WaitingServiceTracker.create(InstructionScheduler.class, - dependencies.getBundleContext(), "(" + InstructionScheduler.class.getName() - + "=" + pcepTopologyId.getValue() + ")"); - final InstructionScheduler scheduler = schedulerTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); - schedulerTracker.close(); + final InstructionScheduler scheduler; + ServiceTracker tracker = null; + try { + tracker = new ServiceTracker<>(dependencies.getBundleContext(), + dependencies.getBundleContext().createFilter(String.format("(&(%s=%s)%s)", Constants.OBJECTCLASS, + InstructionScheduler.class.getName(), "(" + InstructionScheduler.class.getName() + + "=" + pcepTopologyId.getValue() + ")")), null); + tracker.open(); + scheduler = (InstructionScheduler) tracker.waitForService( + TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES)); + Preconditions.checkState(scheduler != null, "InstructionScheduler service not found"); + } catch (InvalidSyntaxException | InterruptedException e) { + throw new IllegalStateException("Error retrieving InstructionScheduler service", e); + } finally { + if (tracker != null) { + tracker.close(); + } + } final InstanceIdentifier tunnelTopology = InstanceIdentifier.builder(NetworkTopology.class) .child(Topology.class, new TopologyKey(tunnelTopologyId)).build(); -- 2.36.6