Modernize AutoCloseableEventExecutor 95/101395/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 31 May 2022 21:47:23 +0000 (23:47 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Jun 2022 21:32:21 +0000 (23:32 +0200)
Remove unneeded indirection through a class, so that we can eliminate
a suppression.

Change-Id: I52710d8a85a2081afe4b325d57acef70d434acce
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/AutoCloseableEventExecutor.java

index b12fc67..a7b931b 100644 (file)
@@ -9,7 +9,6 @@ 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;
@@ -17,43 +16,26 @@ import java.lang.reflect.Method;
 import java.util.concurrent.TimeUnit;
 
 public interface AutoCloseableEventExecutor extends EventExecutor, AutoCloseable {
-
     static AutoCloseableEventExecutor globalEventExecutor() {
-        return CloseableEventExecutorMixin.createCloseableProxy(GlobalEventExecutor.INSTANCE);
+        return createCloseableProxy(GlobalEventExecutor.INSTANCE);
     }
 
     static AutoCloseableEventExecutor immediateEventExecutor() {
-        return CloseableEventExecutorMixin.createCloseableProxy(ImmediateEventExecutor.INSTANCE);
+        return createCloseableProxy(ImmediateEventExecutor.INSTANCE);
     }
 
-    class CloseableEventExecutorMixin implements AutoCloseable {
-        public static final int DEFAULT_SHUTDOWN_SECONDS = 1;
-        private final 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);
-        }
-
-        static AutoCloseableEventExecutor createCloseableProxy(final EventExecutor eventExecutor) {
-            final CloseableEventExecutorMixin closeableEventExecutor = new CloseableEventExecutorMixin(eventExecutor);
-            return Reflection.newProxy(AutoCloseableEventExecutor.class, new AbstractInvocationHandler() {
-                @Override
-                protected Object handleInvocation(final Object proxy, final Method method, final Object[] args)
-                        throws Throwable {
-                    if (method.getName().equals("close")) {
-                        closeableEventExecutor.close();
-                        return null;
-                    } else {
-                        return method.invoke(closeableEventExecutor.eventExecutor, args);
-                    }
+    private static AutoCloseableEventExecutor createCloseableProxy(final EventExecutor eventExecutor) {
+        return Reflection.newProxy(AutoCloseableEventExecutor.class, new AbstractInvocationHandler() {
+            @Override
+            protected Object handleInvocation(final Object proxy, final Method method, final Object[] args)
+                throws Throwable {
+                if (method.getName().equals("close")) {
+                    eventExecutor.shutdownGracefully(0, 1, TimeUnit.SECONDS);
+                    return null;
+                } else {
+                    return method.invoke(eventExecutor, args);
                 }
-            });
-        }
+            }
+        });
     }
 }