Close Bug:443 - Implement ImmediateEventExecutor wrapper to config-subsystem. 36/5436/4
authorTomas Olvecky <tolvecky@cisco.com>
Fri, 21 Feb 2014 10:46:42 +0000 (11:46 +0100)
committerTomas Olvecky <tolvecky@cisco.com>
Tue, 25 Feb 2014 14:37:27 +0000 (15:37 +0100)
Change-Id: I7b633407ce186507379c0008408deae3775fd0df
Signed-off-by: Tomas Olvecky <tolvecky@cisco.com>
opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/AutoCloseableEventExecutor.java [new file with mode: 0644]
opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/GlobalEventExecutorModule.java
opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModule.java [new file with mode: 0644]
opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModuleFactory.java [new file with mode: 0644]
opendaylight/config/netty-event-executor-config/src/main/yang/netty-event-executor.yang

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 (file)
index 0000000..69ea51f
--- /dev/null
@@ -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
index 2c4c2117840e89f74e98f1e2ef94e27a56f72424..8751a80b8d163838b08e8b014abc5371be777978 100644 (file)
  */
 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 (file)
index 0000000..27ca63f
--- /dev/null
@@ -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 (file)
index 0000000..b3ec67b
--- /dev/null
@@ -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);
+    }
+}
index e9d1da3f2dd6de1f0c80701a68b21227fadd8c72..8d812adc4d1231f4507c19a70c9d5df4a28e72d0 100644 (file)
@@ -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'";
         }
     }
 }