X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fnetty-event-executor-config%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fnetty%2Feventexecutor%2FAutoCloseableEventExecutor.java;h=b12fc67609af8d10095475d2d6ac449f735294b5;hb=3b3733ab6cd51e95079b7a4b814aa5f6a49e75f5;hp=d3f43da4bfc42535c7b35da350414470c985f814;hpb=191ad68d71f30f6ad6258ac458c60c663e5b1b85;p=controller.git 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..b12fc67609 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 @@ -9,43 +9,51 @@ package org.opendaylight.controller.config.yang.netty.eventexecutor; import com.google.common.reflect.AbstractInvocationHandler; import com.google.common.reflect.Reflection; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 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; public interface AutoCloseableEventExecutor extends EventExecutor, AutoCloseable { + static AutoCloseableEventExecutor globalEventExecutor() { + return CloseableEventExecutorMixin.createCloseableProxy(GlobalEventExecutor.INSTANCE); + } + + static AutoCloseableEventExecutor immediateEventExecutor() { + return CloseableEventExecutorMixin.createCloseableProxy(ImmediateEventExecutor.INSTANCE); + } - public static class CloseableEventExecutorMixin implements AutoCloseable { + class CloseableEventExecutorMixin implements AutoCloseable { public static final int DEFAULT_SHUTDOWN_SECONDS = 1; private final EventExecutor eventExecutor; - public CloseableEventExecutorMixin(EventExecutor eventExecutor) { + public CloseableEventExecutorMixin(final EventExecutor eventExecutor) { this.eventExecutor = eventExecutor; } @Override + @SuppressFBWarnings(value = "UC_USELESS_VOID_METHOD", justification = "False positive") public void close() { eventExecutor.shutdownGracefully(0, DEFAULT_SHUTDOWN_SECONDS, TimeUnit.SECONDS); } - - public static AutoCloseable createCloseableProxy(final EventExecutor eventExecutor) { - final CloseableEventExecutorMixin closeableGlobalEventExecutorMixin = - new CloseableEventExecutorMixin(eventExecutor); + static AutoCloseableEventExecutor createCloseableProxy(final EventExecutor eventExecutor) { + final CloseableEventExecutorMixin closeableEventExecutor = new CloseableEventExecutorMixin(eventExecutor); return Reflection.newProxy(AutoCloseableEventExecutor.class, new AbstractInvocationHandler() { @Override - protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { + protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) + throws Throwable { if (method.getName().equals("close")) { - closeableGlobalEventExecutorMixin.close(); + closeableEventExecutor.close(); return null; } else { - return method.invoke(eventExecutor, args); + return method.invoke(closeableEventExecutor.eventExecutor, args); } } }); } - - } -} \ No newline at end of file +}