From: Tom Pantelis Date: Tue, 8 Mar 2016 01:04:28 +0000 (-0500) Subject: Add blueprint wiring for netty configs X-Git-Tag: release/boron~219 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=9832745f5d61833705269a0004a83b39e81bddce;hp=44b5dbe52783a3a558b3eae619b01baf613f82e0 Add blueprint wiring for netty configs Wiring for netty-threadgroup-config, netty-timer-config, and netty-event-executor-config. Change-Id: I759b222c6f3fcad1cacbc4aeb1af4cec19faff0d Signed-off-by: Tom Pantelis --- 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 index d3f43da4bf..cb721db67d 100644 --- 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 @@ -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 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 8751a80b8d..caca6b1b64 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,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(); } 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 index 27ca63fe4a..9178452a3e 100644 --- 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 @@ -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 index 0000000000..66b22b52f8 --- /dev/null +++ b/opendaylight/config/netty-event-executor-config/src/main/resources/org/opendaylight/blueprint/netty-event-executor.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/opendaylight/config/netty-threadgroup-config/pom.xml b/opendaylight/config/netty-threadgroup-config/pom.xml index 5a0e483727..223eca1d38 100644 --- a/opendaylight/config/netty-threadgroup-config/pom.xml +++ b/opendaylight/config/netty-threadgroup-config/pom.xml @@ -68,6 +68,7 @@ ${project.groupId}.${project.artifactId} org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.netty.threadgroup.rev131107.*, + *,io.netty.channel diff --git a/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModule.java b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModule.java index c5b726cd3c..54266f4e84 100644 --- a/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModule.java +++ b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NettyThreadgroupModule.java @@ -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 index 0000000000..372cf0ecb7 --- /dev/null +++ b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NioEventLoopGroupCloseable.java @@ -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 index 0000000000..f9ad6a4da3 --- /dev/null +++ b/opendaylight/config/netty-threadgroup-config/src/main/resources/org/opendaylight/blueprint/netty-threadgroup.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + 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 index 0000000000..4b23af11a7 --- /dev/null +++ b/opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerCloseable.java @@ -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 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 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 60ad4c8a96..7114ed6025 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,12 +17,6 @@ */ 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 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 index 0000000000..60822d504e --- /dev/null +++ b/opendaylight/config/netty-timer-config/src/main/resources/org/opendaylight/blueprint/netty-timer.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + +