Fix mdsal-netconf-ssh shutdown 84/102584/6
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Fri, 7 Oct 2022 18:32:15 +0000 (20:32 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 31 Oct 2022 16:37:48 +0000 (17:37 +0100)
Initialize AsynchronousChannelGroup thread pool with
ForwardingExecutorService with NO-OP shutdown method
in order to prevent throwing UnsupportedOperationException
from OSGiGlobalEventExecutor.

JIRA: NETCONF-900
Change-Id: Ibedb95413bf5476f5d22ae899e71496951fb6ed7
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/ExecutorServiceFacade.java [new file with mode: 0644]
netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java

diff --git a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/ExecutorServiceFacade.java b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/ExecutorServiceFacade.java
new file mode 100644 (file)
index 0000000..6b7ef39
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.netconf.ssh;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.util.concurrent.ForwardingExecutorService;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Facade for guarding against {@link #shutdown()} invocations. This is necessary as SSHD wants to shutdown the executor
+ * when the server shuts down.
+ */
+final class ExecutorServiceFacade extends ForwardingExecutorService {
+    private final ExecutorService delegate;
+
+    ExecutorServiceFacade(final ExecutorService delegate) {
+        this.delegate = requireNonNull(delegate);
+    }
+
+    @Override
+    protected ExecutorService delegate() {
+        return delegate;
+    }
+
+    @Override
+    public void shutdown() {
+        // NO-OP
+    }
+}
\ No newline at end of file
index cdc730fc17370d6c57a034d31aefadebd3bb20cf..c429620d2ea1f64e1868bc6b9bfc7023a6866426 100644 (file)
@@ -52,8 +52,8 @@ public class SshProxyServer implements AutoCloseable {
             final IoServiceFactoryFactory serviceFactory) {
         this.minaTimerExecutor = minaTimerExecutor;
         this.clientGroup = clientGroup;
-        this.nioServiceWithPoolFactoryFactory = serviceFactory;
-        this.sshServer = SshServer.setUpDefaultServer();
+        nioServiceWithPoolFactoryFactory = serviceFactory;
+        sshServer = SshServer.setUpDefaultServer();
     }
 
     public SshProxyServer(final ScheduledExecutorService minaTimerExecutor,
@@ -179,10 +179,10 @@ public class SshProxyServer implements AutoCloseable {
     }
 
     private static final class NioServiceWithPoolFactoryFactory extends Nio2ServiceFactoryFactory {
-        private final ExecutorService nioExecutor;
+        private final ExecutorServiceFacade nioExecutor;
 
         NioServiceWithPoolFactoryFactory(final ExecutorService nioExecutor) {
-            this.nioExecutor = nioExecutor;
+            this.nioExecutor = new ExecutorServiceFacade(nioExecutor);
         }
 
         @Override