From: Tomas Olvecky Date: Fri, 21 Feb 2014 10:46:42 +0000 (+0100) Subject: Close Bug:443 - Implement ImmediateEventExecutor wrapper to config-subsystem. X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~384^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=f6b5466e99888936c69e12d732162e9ee4e0e490;p=controller.git Close Bug:443 - Implement ImmediateEventExecutor wrapper to config-subsystem. Change-Id: I7b633407ce186507379c0008408deae3775fd0df Signed-off-by: Tomas Olvecky --- diff --git a/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/AutoCloseableEventExecutor.java b/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/AutoCloseableEventExecutor.java new file mode 100644 index 0000000000..69ea51f3a5 --- /dev/null +++ b/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/AutoCloseableEventExecutor.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +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 java.lang.reflect.Method; +import java.util.concurrent.TimeUnit; + +public interface AutoCloseableEventExecutor extends EventExecutor, AutoCloseable { + + + public static class CloseableEventExecutorMixin implements AutoCloseable { + public static final int DEFAULT_SHUTDOWN_SECONDS = 1; + private final EventExecutor eventExecutor; + + public CloseableEventExecutorMixin(EventExecutor eventExecutor) { + this.eventExecutor = eventExecutor; + } + + @Override + public void close() { + eventExecutor.shutdownGracefully(0, DEFAULT_SHUTDOWN_SECONDS, TimeUnit.SECONDS); + } + + + public static AutoCloseable createCloseableProxy(final EventExecutor eventExecutor) { + final CloseableEventExecutorMixin closeableGlobalEventExecutorMixin = + new CloseableEventExecutorMixin(eventExecutor); + 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(eventExecutor, args); + } + } + }); + } + + + } +} \ No newline at end of file diff --git a/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/GlobalEventExecutorModule.java b/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/GlobalEventExecutorModule.java index 2c4c211784..8751a80b8d 100644 --- a/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/GlobalEventExecutorModule.java +++ b/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/GlobalEventExecutorModule.java @@ -17,13 +17,9 @@ */ 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.yang.netty.eventexecutor.AutoCloseableEventExecutor.CloseableEventExecutorMixin; public final class GlobalEventExecutorModule extends org.opendaylight.controller.config.yang.netty.eventexecutor.AbstractGlobalEventExecutorModule { @@ -46,35 +42,10 @@ public final class GlobalEventExecutorModule extends @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); - } - } - }); + EventExecutor eventExecutor = GlobalEventExecutor.INSTANCE; + return CloseableEventExecutorMixin.createCloseableProxy(eventExecutor); } - public static interface AutoCloseableEventExecutor extends EventExecutor, AutoCloseable { - - } - 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); - } - } } diff --git a/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModule.java b/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModule.java new file mode 100644 index 0000000000..27ca63fe4a --- /dev/null +++ b/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModule.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.netty.eventexecutor; + +import io.netty.util.concurrent.EventExecutor; +import io.netty.util.concurrent.ImmediateEventExecutor; +import org.opendaylight.controller.config.yang.netty.eventexecutor.AutoCloseableEventExecutor.CloseableEventExecutorMixin; + +public final class ImmediateEventExecutorModule extends org.opendaylight.controller.config.yang.netty.eventexecutor.AbstractImmediateEventExecutorModule { + + public ImmediateEventExecutorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public ImmediateEventExecutorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + ImmediateEventExecutorModule oldModule, java.lang.AutoCloseable oldInstance) { + + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + protected void customValidation() { + // Add custom validation for module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + EventExecutor eventExecutor = ImmediateEventExecutor.INSTANCE; + return CloseableEventExecutorMixin.createCloseableProxy(eventExecutor); + } +} diff --git a/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModuleFactory.java b/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModuleFactory.java new file mode 100644 index 0000000000..b3ec67bbf5 --- /dev/null +++ b/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModuleFactory.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yang.netty.eventexecutor; + +import org.opendaylight.controller.config.api.DependencyResolver; +import org.osgi.framework.BundleContext; + +import static com.google.common.base.Preconditions.checkArgument; + +public class ImmediateEventExecutorModuleFactory extends org.opendaylight.controller.config.yang.netty.eventexecutor.AbstractImmediateEventExecutorModuleFactory { + public static final String SINGLETON_NAME = "singleton"; + + @Override + public ImmediateEventExecutorModule instantiateModule(String instanceName, DependencyResolver dependencyResolver, ImmediateEventExecutorModule oldModule, AutoCloseable oldInstance, BundleContext bundleContext) { + checkArgument(SINGLETON_NAME.equals(instanceName), "Illegal instance name '" + instanceName + "', only allowed name is " + SINGLETON_NAME); + return super.instantiateModule(instanceName, dependencyResolver, oldModule, oldInstance, bundleContext); + } + + @Override + public ImmediateEventExecutorModule instantiateModule(String instanceName, DependencyResolver dependencyResolver, BundleContext bundleContext) { + checkArgument(SINGLETON_NAME.equals(instanceName), "Illegal instance name '" + instanceName + "', only allowed name is " + SINGLETON_NAME); + return super.instantiateModule(instanceName, dependencyResolver, bundleContext); + } +} diff --git a/opendaylight/config/netty-event-executor-config/src/main/yang/netty-event-executor.yang b/opendaylight/config/netty-event-executor-config/src/main/yang/netty-event-executor.yang index e9d1da3f2d..8d812adc4d 100644 --- a/opendaylight/config/netty-event-executor-config/src/main/yang/netty-event-executor.yang +++ b/opendaylight/config/netty-event-executor-config/src/main/yang/netty-event-executor.yang @@ -36,7 +36,18 @@ module netty-event-executor { augment "/config:modules/config:module/config:configuration" { case netty-global-event-executor { when "/config:modules/config:module/config:type = 'netty-global-event-executor'"; + } + } + identity netty-immediate-event-executor { + base config:module-type; + config:provided-service netty:netty-event-executor; + config:java-name-prefix ImmediateEventExecutor; + } + + augment "/config:modules/config:module/config:configuration" { + case netty-immediate-event-executor { + when "/config:modules/config:module/config:type = 'netty-immediate-event-executor'"; } } }