*/
package org.opendaylight.controller.config.yang.netty.eventexecutor;
-import com.google.common.reflect.AbstractInvocationHandler;
-import com.google.common.reflect.Reflection;
import io.netty.util.concurrent.EventExecutor;
-import io.netty.util.concurrent.GlobalEventExecutor;
-
-import java.lang.reflect.Method;
-import java.util.concurrent.TimeUnit;
+import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
+import org.opendaylight.controller.config.yang.netty.eventexecutor.AutoCloseableEventExecutor.CloseableEventExecutorMixin;
+import org.osgi.framework.BundleContext;
+/**
+ * @deprecated Replaced by blueprint wiring
+ */
+@Deprecated
public final class GlobalEventExecutorModule extends
org.opendaylight.controller.config.yang.netty.eventexecutor.AbstractGlobalEventExecutorModule {
+ private BundleContext bundleContext;
- public GlobalEventExecutorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ public GlobalEventExecutorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
- public GlobalEventExecutorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
- GlobalEventExecutorModule oldModule, java.lang.AutoCloseable oldInstance) {
+ public GlobalEventExecutorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ final GlobalEventExecutorModule oldModule, final java.lang.AutoCloseable oldInstance) {
super(identifier, dependencyResolver, oldModule, oldInstance);
}
}
@Override
- public java.lang.AutoCloseable createInstance() {
- final CloseableGlobalEventExecutorMixin closeableGlobalEventExecutorMixin =
- new CloseableGlobalEventExecutorMixin(GlobalEventExecutor.INSTANCE);
- return Reflection.newProxy(AutoCloseableEventExecutor.class, new AbstractInvocationHandler() {
- @Override
- protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
- if (method.getName().equals("close")) {
- closeableGlobalEventExecutorMixin.close();
- return null;
- } else {
- return method.invoke(GlobalEventExecutor.INSTANCE, args);
- }
- }
- });
- }
-
- public static interface AutoCloseableEventExecutor extends EventExecutor, AutoCloseable {
-
+ public AutoCloseable createInstance() {
+ // The service is provided via blueprint so wait for and return it here for backwards compatibility.
+ final WaitingServiceTracker<EventExecutor> tracker = WaitingServiceTracker.create(
+ EventExecutor.class, bundleContext, "(type=global-event-executor)");
+ EventExecutor eventExecutor = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
+ return CloseableEventExecutorMixin.forwardingEventExecutor(eventExecutor, tracker);
}
- public static class CloseableGlobalEventExecutorMixin implements AutoCloseable {
- private final GlobalEventExecutor eventExecutor;
-
- public CloseableGlobalEventExecutorMixin(GlobalEventExecutor eventExecutor) {
- this.eventExecutor = eventExecutor;
- }
-
- @Override
- public void close() {
- eventExecutor.shutdownGracefully(0, 1, TimeUnit.SECONDS);
- }
+ public void setBundleContext(final BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
}
}