Add blueprint wiring for netty configs 35/35935/25
authorTom Pantelis <tpanteli@brocade.com>
Tue, 8 Mar 2016 01:04:28 +0000 (20:04 -0500)
committerTom Pantelis <tpanteli@brocade.com>
Thu, 14 Apr 2016 03:05:03 +0000 (03:05 +0000)
Wiring for netty-threadgroup-config, netty-timer-config, and
netty-event-executor-config.

Change-Id: I759b222c6f3fcad1cacbc4aeb1af4cec19faff0d
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/AutoCloseableEventExecutor.java
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
opendaylight/config/netty-event-executor-config/src/main/resources/org/opendaylight/blueprint/netty-event-executor.xml [new file with mode: 0644]
opendaylight/config/netty-threadgroup-config/pom.xml
opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModule.java
opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NioEventLoopGroupCloseable.java [new file with mode: 0644]
opendaylight/config/netty-threadgroup-config/src/main/resources/org/opendaylight/blueprint/netty-threadgroup.xml [new file with mode: 0644]
opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerCloseable.java [new file with mode: 0644]
opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerModule.java
opendaylight/config/netty-timer-config/src/main/resources/org/opendaylight/blueprint/netty-timer.xml [new file with mode: 0644]

index d3f43da..cb721db 100644 (file)
@@ -10,6 +10,8 @@ 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 io.netty.util.concurrent.ImmediateEventExecutor;
 import java.lang.reflect.Method;
 import java.util.concurrent.TimeUnit;
 
@@ -30,7 +32,7 @@ public interface AutoCloseableEventExecutor extends EventExecutor, AutoCloseable
         }
 
 
-        public static AutoCloseable createCloseableProxy(final EventExecutor eventExecutor) {
+        private static AutoCloseableEventExecutor createCloseableProxy(final EventExecutor eventExecutor) {
             final CloseableEventExecutorMixin closeableGlobalEventExecutorMixin =
                     new CloseableEventExecutorMixin(eventExecutor);
             return Reflection.newProxy(AutoCloseableEventExecutor.class, new AbstractInvocationHandler() {
@@ -46,6 +48,12 @@ public interface AutoCloseableEventExecutor extends EventExecutor, AutoCloseable
             });
         }
 
+        public static AutoCloseableEventExecutor globalEventExecutor() {
+            return createCloseableProxy(GlobalEventExecutor.INSTANCE);
+        }
 
+        public static AutoCloseableEventExecutor immediateEventExecutor() {
+            return createCloseableProxy(ImmediateEventExecutor.INSTANCE);
+        }
     }
 }
\ No newline at end of file
index 8751a80..caca6b1 100644 (file)
@@ -17,8 +17,6 @@
  */
 package org.opendaylight.controller.config.yang.netty.eventexecutor;
 
-import io.netty.util.concurrent.EventExecutor;
-import io.netty.util.concurrent.GlobalEventExecutor;
 import org.opendaylight.controller.config.yang.netty.eventexecutor.AutoCloseableEventExecutor.CloseableEventExecutorMixin;
 
 public final class GlobalEventExecutorModule extends
@@ -42,8 +40,7 @@ public final class GlobalEventExecutorModule extends
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        EventExecutor eventExecutor = GlobalEventExecutor.INSTANCE;
-        return CloseableEventExecutorMixin.createCloseableProxy(eventExecutor);
+        return CloseableEventExecutorMixin.globalEventExecutor();
     }
 
 
index 27ca63f..9178452 100644 (file)
@@ -7,8 +7,6 @@
  */
 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 {
@@ -30,7 +28,6 @@ public final class ImmediateEventExecutorModule extends org.opendaylight.control
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        EventExecutor eventExecutor = ImmediateEventExecutor.INSTANCE;
-        return CloseableEventExecutorMixin.createCloseableProxy(eventExecutor);
+        return CloseableEventExecutorMixin.immediateEventExecutor();
     }
 }
diff --git a/opendaylight/config/netty-event-executor-config/src/main/resources/org/opendaylight/blueprint/netty-event-executor.xml b/opendaylight/config/netty-event-executor-config/src/main/resources/org/opendaylight/blueprint/netty-event-executor.xml
new file mode 100644 (file)
index 0000000..66b22b5
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
+
+  <bean id="executor" class="org.opendaylight.controller.config.yang.netty.eventexecutor.AutoCloseableEventExecutor.CloseableEventExecutorMixin"
+          factory-method="globalEventExecutor"/>
+
+  <service ref="executor" interface="io.netty.util.concurrent.EventExecutor"
+        odl:type="global-event-executor"/>
+
+</blueprint>
index 5a0e483..223eca1 100644 (file)
@@ -68,6 +68,7 @@
           <instructions>
             <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
             <Export-Package>org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.netty.threadgroup.rev131107.*,</Export-Package>
+            <Import-Package>*,io.netty.channel</Import-Package>
           </instructions>
         </configuration>
       </plugin>
index c5b726c..54266f4 100644 (file)
@@ -17,8 +17,6 @@
 */
 package org.opendaylight.controller.config.yang.netty.threadgroup;
 
-import io.netty.channel.nio.NioEventLoopGroup;
-import java.util.concurrent.TimeUnit;
 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
 
 /**
@@ -44,24 +42,6 @@ public final class NettyThreadgroupModule extends org.opendaylight.controller.co
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        return getThreadCount()==null ? new NioEventLoopGroupCloseable() : new NioEventLoopGroupCloseable(getThreadCount());
-    }
-
-
-    private class NioEventLoopGroupCloseable extends NioEventLoopGroup implements AutoCloseable {
-
-
-        public NioEventLoopGroupCloseable(int threadCount) {
-            super(threadCount);
-        }
-
-        public NioEventLoopGroupCloseable() {
-            super();
-        }
-
-        @Override
-        public void close() throws Exception {
-            shutdownGracefully(0, 1, TimeUnit.SECONDS);
-        }
+        return NioEventLoopGroupCloseable.newInstance(getThreadCount());
     }
 }
diff --git a/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NioEventLoopGroupCloseable.java b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NioEventLoopGroupCloseable.java
new file mode 100644 (file)
index 0000000..372cf0e
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.threadgroup;
+
+import io.netty.channel.nio.NioEventLoopGroup;
+import java.util.concurrent.TimeUnit;
+
+public class NioEventLoopGroupCloseable extends NioEventLoopGroup implements AutoCloseable {
+    private NioEventLoopGroupCloseable(int threadCount) {
+        super(threadCount);
+    }
+
+    private NioEventLoopGroupCloseable() {
+        super();
+    }
+
+    @Override
+    public void close() throws Exception {
+        shutdownGracefully(0, 1, TimeUnit.SECONDS);
+    }
+
+    public static NioEventLoopGroupCloseable newInstance(Integer threadCount) {
+        if(threadCount == null || threadCount <= 0) {
+            return new NioEventLoopGroupCloseable();
+        }
+
+        return new NioEventLoopGroupCloseable(threadCount);
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/config/netty-threadgroup-config/src/main/resources/org/opendaylight/blueprint/netty-threadgroup.xml b/opendaylight/config/netty-threadgroup-config/src/main/resources/org/opendaylight/blueprint/netty-threadgroup.xml
new file mode 100644 (file)
index 0000000..f9ad6a4
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
+    odl:restart-dependents-on-updates="true">
+
+  <cm:property-placeholder persistent-id="org.opendaylight.netty.threadgroup" update-strategy="none">
+    <cm:default-properties>
+      <cm:property name="global-boss-group-thread-count" value="0"/>
+      <cm:property name="global-worker-group-thread-count" value="0"/>
+    </cm:default-properties>
+  </cm:property-placeholder>
+
+  <bean id="globalBossGroup" class="org.opendaylight.controller.config.yang.netty.threadgroup.NioEventLoopGroupCloseable"
+          factory-method="newInstance">
+    <argument value="${global-boss-group-thread-count}"/>
+  </bean>
+
+  <service ref="globalBossGroup" interface="io.netty.channel.EventLoopGroup" odl:type="global-boss-group"/>
+
+  <bean id="globalWorkerGroup" class="org.opendaylight.controller.config.yang.netty.threadgroup.NioEventLoopGroupCloseable"
+          factory-method="newInstance">
+    <argument value="${global-worker-group-thread-count}"/>
+  </bean>
+
+  <service ref="globalWorkerGroup" interface="io.netty.channel.EventLoopGroup" odl:type="global-worker-group"/>
+
+</blueprint>
diff --git a/opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerCloseable.java b/opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerCloseable.java
new file mode 100644 (file)
index 0000000..4b23af1
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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.timer;
+
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.Timeout;
+import io.netty.util.Timer;
+import io.netty.util.TimerTask;
+import java.util.Set;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.Nullable;
+
+public final class HashedWheelTimerCloseable implements AutoCloseable, Timer {
+
+    private final Timer timer;
+
+    private 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<Timeout> stop() {
+        return this.timer.stop();
+    }
+
+    public static HashedWheelTimerCloseable newInstance(@Nullable ThreadFactory threadFactory,
+            @Nullable Long duration, @Nullable Integer ticksPerWheel) {
+        TimeUnit unit = TimeUnit.MILLISECONDS;
+        if(!nullOrNonZero(duration) && threadFactory == null && nullOrNonZero(ticksPerWheel)) {
+            return new HashedWheelTimerCloseable(new HashedWheelTimer(duration, unit));
+        }
+
+        if(!nullOrNonZero(duration) && threadFactory == null && !nullOrNonZero(ticksPerWheel)) {
+            return new HashedWheelTimerCloseable(new HashedWheelTimer(duration, unit, ticksPerWheel));
+        }
+
+        if(nullOrNonZero(duration) && threadFactory != null && nullOrNonZero(ticksPerWheel)) {
+            return new HashedWheelTimerCloseable(new HashedWheelTimer(threadFactory));
+        }
+
+        if(!nullOrNonZero(duration) && threadFactory != null && nullOrNonZero(ticksPerWheel)) {
+            return new HashedWheelTimerCloseable(
+                    new HashedWheelTimer(threadFactory, duration, unit));
+        }
+
+        if(!nullOrNonZero(duration) && threadFactory != null && !nullOrNonZero(ticksPerWheel)) {
+            return new HashedWheelTimerCloseable(
+                    new HashedWheelTimer(threadFactory, duration, unit, ticksPerWheel));
+        }
+
+        return new HashedWheelTimerCloseable(new HashedWheelTimer());
+    }
+
+    private static boolean nullOrNonZero(Number n) {
+        return n == null || n.longValue() <= 0;
+    }
+}
\ No newline at end of file
index 60ad4c8..7114ed6 100644 (file)
  */
 package org.opendaylight.controller.config.yang.netty.timer;
 
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.Timeout;
-import io.netty.util.Timer;
-import io.netty.util.TimerTask;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
 
 /**
@@ -57,49 +51,6 @@ 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());
-    }
-
-    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<Timeout> stop() {
-            return this.timer.stop();
-        }
-
+        return HashedWheelTimerCloseable.newInstance(getThreadFactoryDependency(), getTickDuration(), getTicksPerWheel());
     }
 }
diff --git a/opendaylight/config/netty-timer-config/src/main/resources/org/opendaylight/blueprint/netty-timer.xml b/opendaylight/config/netty-timer-config/src/main/resources/org/opendaylight/blueprint/netty-timer.xml
new file mode 100644 (file)
index 0000000..60822d5
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
+    odl:restart-dependents-on-updates="true">
+
+  <cm:property-placeholder persistent-id="org.opendaylight.netty.timer" update-strategy="none">
+    <cm:default-properties>
+      <cm:property name="tick-duration" value="0"/>
+      <cm:property name="ticks-per-wheel" value="0"/>
+    </cm:default-properties>
+  </cm:property-placeholder>
+
+  <bean id="timer" class="org.opendaylight.controller.config.yang.netty.timer.HashedWheelTimerCloseable"
+          factory-method="newInstance">
+    <argument><null/></argument> <!-- ThreadFactory -->
+    <argument value="${tick-duration}"/>
+    <argument value="${ticks-per-wheel}"/>
+  </bean>
+
+  <service ref="timer" interface="io.netty.util.Timer" odl:type="global-timer"/>
+
+</blueprint>