X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fnetty-timer-config%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fnetty%2Ftimer%2FHashedWheelTimerModule.java;h=2564ef94fae8af20ebd0e123eed73f9ba51d0476;hp=e65a4d335eb952a53fb68c2fd1e5ac374b351d49;hb=71f19bb6cdb8fcbeec5bcb1e5258fa5c98a41085;hpb=cbdf09d099f297db7712c3dd4637475c88f92113 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 e65a4d335e..2564ef94fa 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,30 +17,30 @@ */ package org.opendaylight.controller.config.yang.netty.timer; -import io.netty.util.HashedWheelTimer; -import io.netty.util.Timeout; +import com.google.common.reflect.AbstractInvocationHandler; +import com.google.common.reflect.Reflection; import io.netty.util.Timer; -import io.netty.util.TimerTask; - -import java.util.Set; -import java.util.concurrent.TimeUnit; - +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; /** -* -*/ + * @deprecated Replaced by blueprint wiring + */ +@Deprecated 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) { + public HashedWheelTimerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); } - public HashedWheelTimerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, - org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, - HashedWheelTimerModule oldModule, java.lang.AutoCloseable oldInstance) { + public HashedWheelTimerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + final HashedWheelTimerModule oldModule, final java.lang.AutoCloseable oldInstance) { super(identifier, dependencyResolver, oldModule, oldInstance); } @@ -58,50 +58,29 @@ public final class HashedWheelTimerModule extends } @Override - public java.lang.AutoCloseable createInstance() { - TimeUnit unit = TimeUnit.MILLISECONDS; - if (getTickDuration() != null && getThreadFactoryDependency() == null && getTicksPerWheel() == null) { - return new HashedWheelTimerCloseable(new HashedWheelTimer(getTickDuration(), unit)); - } - if (getTickDuration() != null && getThreadFactoryDependency() == null && getTicksPerWheel() != null) { - return new HashedWheelTimerCloseable(new HashedWheelTimer(getTickDuration(), unit, getTicksPerWheel())); - } - if (getTickDuration() == null && getThreadFactoryDependency() != null && getTicksPerWheel() == null) { - return new HashedWheelTimerCloseable(new HashedWheelTimer(getThreadFactoryDependency())); - } - if (getTickDuration() != null && getThreadFactoryDependency() != null && getTicksPerWheel() == null) { - return new HashedWheelTimerCloseable(new HashedWheelTimer(getThreadFactoryDependency(), getTickDuration(), - unit)); - } - if (getTickDuration() != null && getThreadFactoryDependency() != null && getTicksPerWheel() != null) { - return new HashedWheelTimerCloseable(new HashedWheelTimer(getThreadFactoryDependency(), getTickDuration(), - unit, getTicksPerWheel())); - } - return new HashedWheelTimerCloseable(new HashedWheelTimer()); + 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(final Object proxy, final Method method, final Object[] args) throws Throwable { + if (method.getName().equals("close")) { + tracker.close(); + return null; + } else { + return method.invoke(timer, args); + } + } + }); } - static final private class HashedWheelTimerCloseable implements AutoCloseable, Timer { - - private final Timer timer; - - public HashedWheelTimerCloseable(Timer timer) { - this.timer = timer; - } - - @Override - public void close() throws Exception { - stop(); - } - - @Override - public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit) { - return this.timer.newTimeout(task, delay, unit); - } - - @Override - public Set stop() { - return this.timer.stop(); - } + public void setBundleContext(final BundleContext bundleContext) { + this.bundleContext = bundleContext; + } + private interface AutoCloseableTimerInterface extends Timer, AutoCloseable { } }