X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fnetty-timer-config%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fnetty%2Ftimer%2FHashedWheelTimerModule.java;fp=opendaylight%2Fconfig%2Fnetty-timer-config%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fnetty%2Ftimer%2FHashedWheelTimerModule.java;h=76d75e83728ca6aa86ec0fc903c14c163bc33e7c;hb=dceb9db7853dabfbd4abdfb3d886a79871097831;hp=7114ed6025833be1343505caa6706a16c2a88efb;hpb=2608b7032d0d019f5125704609eaaa0590c4598a;p=controller.git diff --git a/opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerModule.java b/opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerModule.java index 7114ed6025..76d75e8372 100644 --- a/opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerModule.java +++ b/opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerModule.java @@ -17,13 +17,20 @@ */ package org.opendaylight.controller.config.yang.netty.timer; +import com.google.common.reflect.AbstractInvocationHandler; +import com.google.common.reflect.Reflection; +import io.netty.util.Timer; +import java.lang.reflect.Method; import org.opendaylight.controller.config.api.JmxAttributeValidationException; +import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker; +import org.osgi.framework.BundleContext; /** * */ public final class HashedWheelTimerModule extends org.opendaylight.controller.config.yang.netty.timer.AbstractHashedWheelTimerModule { + private BundleContext bundleContext; public HashedWheelTimerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { @@ -50,7 +57,29 @@ public final class HashedWheelTimerModule extends } @Override - public java.lang.AutoCloseable createInstance() { - return HashedWheelTimerCloseable.newInstance(getThreadFactoryDependency(), getTickDuration(), getTicksPerWheel()); + public AutoCloseable createInstance() { + // The service is provided via blueprint so wait for and return it here for backwards compatibility. + final WaitingServiceTracker tracker = WaitingServiceTracker.create( + Timer.class, bundleContext, "(type=global-timer)"); + final Timer timer = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); + + return Reflection.newProxy(AutoCloseableTimerInterface.class, new AbstractInvocationHandler() { + @Override + protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { + if (method.getName().equals("close")) { + tracker.close(); + return null; + } else { + return method.invoke(timer, args); + } + } + }); + } + + public void setBundleContext(BundleContext bundleContext) { + this.bundleContext = bundleContext; + } + + private static interface AutoCloseableTimerInterface extends Timer, AutoCloseable { } }