diff --git a/src/main/java/net/floodlightcontroller/core/util/NettyUtils.java b/src/main/java/net/floodlightcontroller/core/util/NettyUtils.java deleted file mode 100644 index e45188df50cb2325124e6eeed9b7bc34c7cd7bcc..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/core/util/NettyUtils.java +++ /dev/null @@ -1,105 +0,0 @@ -package net.floodlightcontroller.core.util; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.netty.channel.EventLoopGroup; -import io.netty.util.concurrent.Future; - -/** Collection of static utility functions for netty. - * - * @author Andreas Wundsam <andreas.wundsam@bigswitch.com> - */ -public class NettyUtils { - private static final Logger logger = LoggerFactory.getLogger(NettyUtils.class); - - private static final long SHUTDOWN_TIMEOUT = 20; - private static final TimeUnit SHUTDOWN_TIMEOUT_UNIT = TimeUnit.SECONDS; - - private NettyUtils() {} - - /** - * Shuts down an event group gracefully and waits for the corresponding Future to complete. Logs - * any exceptions. - * - * TODO: may want to force a shutdown if the graceful shutdown fails - * - * @param name - name of the even group to be shut down (for logging) - * @param group to be shut down - * @throws InterruptedException - if the thread is interrupted while shutting down - */ - public static void shutdownAndWait(String name, EventLoopGroup group) throws InterruptedException { - try { - logger.debug("Shutting down {}", name); - Future<?> shutdownFuture = group.shutdownGracefully(); - shutdownFuture.get(SHUTDOWN_TIMEOUT, SHUTDOWN_TIMEOUT_UNIT); - logger.debug("Done shutting down {}", name); - } catch (ExecutionException e) { - /*** - * @id NETTYUTIL4001 - * @desc A netty event loop group failed to shutdown - * @action #support if encountered repeatedly - * @param name the name of the event loop group - * @param e the exception - */ - logger.warn("NETTYUTIL4001: Error during shutdown of {}: {}", name, e); - } catch (TimeoutException e) { - /*** - * @id NETTYUTIL4002 - * @desc A netty event loop group failed to shutdown - * @action #support if encountered repeatedly - * @param name the name of the event loop group - * @param e the exception - */ - logger.warn("NETTYUTIL4002: Graceful shutdown of {} timed out: {}", name, e); - } - } - - /** Wait for the supplied set of futures to complete. Logs any exceptions occur. - * - * @param name name of futures to wait on for logging - * @param shutdownFutures futures to wait on - * @throws InterruptedException if process is interrupted - */ - public static void waitOrLog(String name, Future<?>... shutdownFutures) - throws InterruptedException { - logger.debug("Shutting down {}", name); - long limit = System.nanoTime() + SHUTDOWN_TIMEOUT_UNIT.toNanos(SHUTDOWN_TIMEOUT); - - for(Future<?> f: shutdownFutures) { - try { - long wait = limit - System.nanoTime(); - if(wait > 0) { - f.get(wait, TimeUnit.NANOSECONDS); - logger.debug("Done shutting down {}", name); - } else { - throw new TimeoutException("timed out waiting for shutdown"); - } - } catch (ExecutionException e) { - /*** - * @id NETTYUTIL4003 - * @desc An error was encountered waiting for completion of future. - * @action #support if encountered repeatedly - * @param name the name of the future - * @param e the exception - */ - logger.warn("Error during completion of {}: {}", name, e); - } catch (TimeoutException e) { - /*** - * @id NETTYUTIL4004 - * @desc A timeout was encountered waiting for completion of future. - * @action #support if encountered repeatedly - * @param name the name of the future - * @param e the exception - */ - logger.warn("Graceful shutdown of {} timed out: {}", name, e); - break; - } - - } - } -} \ No newline at end of file diff --git a/src/main/java/org/sdnplatform/sync/internal/config/bootstrap/BootstrapClient.java b/src/main/java/org/sdnplatform/sync/internal/config/bootstrap/BootstrapClient.java index af6965210f81d253a9d96bdabec825ab69532767..8133635241d5ce9e954c345d565d7a5e300f9f14 100644 --- a/src/main/java/org/sdnplatform/sync/internal/config/bootstrap/BootstrapClient.java +++ b/src/main/java/org/sdnplatform/sync/internal/config/bootstrap/BootstrapClient.java @@ -17,7 +17,6 @@ import io.netty.handler.timeout.TimeoutException; import io.netty.util.HashedWheelTimer; import io.netty.util.Timer; import io.netty.util.concurrent.GlobalEventExecutor; -import net.floodlightcontroller.core.util.NettyUtils; import org.sdnplatform.sync.error.SyncException; import org.sdnplatform.sync.internal.SyncManager; @@ -103,8 +102,8 @@ public class BootstrapClient { pipelineFactory = null; if (workerExecutor != null) { try { - NettyUtils.shutdownAndWait("Sync BootstrapClient", workerExecutor); - } catch (InterruptedException | TimeoutException e) { + workerExecutor.shutdownGracefully(); + } catch (TimeoutException e) { logger.warn("Error waiting for gracefull shutdown of BootstrapClient {}", e); } workerExecutor = null; diff --git a/src/main/java/org/sdnplatform/sync/internal/remote/RemoteSyncManager.java b/src/main/java/org/sdnplatform/sync/internal/remote/RemoteSyncManager.java index 89491128d30ea75d1a4f653eb47613390871bfbe..23b8e7bc24b93d37d565081c5da17252be97a95f 100644 --- a/src/main/java/org/sdnplatform/sync/internal/remote/RemoteSyncManager.java +++ b/src/main/java/org/sdnplatform/sync/internal/remote/RemoteSyncManager.java @@ -44,7 +44,6 @@ import org.slf4j.LoggerFactory; import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.module.FloodlightModuleException; import net.floodlightcontroller.core.module.IFloodlightService; -import net.floodlightcontroller.core.util.NettyUtils; /** * Implementation of a sync service that passes its functionality off to a @@ -165,7 +164,7 @@ public class RemoteSyncManager extends AbstractSyncManager { clientBootstrap = null; pipelineFactory = null; if (workerExecutor != null) { - NettyUtils.shutdownAndWait("worker group", workerExecutor); + workerExecutor.shutdownGracefully(); workerExecutor = null; } if (timer != null) { diff --git a/src/main/java/org/sdnplatform/sync/internal/rpc/RPCService.java b/src/main/java/org/sdnplatform/sync/internal/rpc/RPCService.java index e7f30d9cd4f80d04481bf566c0b2b20d34672c34..962e355437fd946335f5f56c7a2c95977ca75670 100644 --- a/src/main/java/org/sdnplatform/sync/internal/rpc/RPCService.java +++ b/src/main/java/org/sdnplatform/sync/internal/rpc/RPCService.java @@ -16,7 +16,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.LinkedTransferQueue; -import net.floodlightcontroller.core.util.NettyUtils; import net.floodlightcontroller.core.util.SingletonTask; import net.floodlightcontroller.debugcounter.IDebugCounterService; import io.netty.bootstrap.Bootstrap; @@ -235,10 +234,10 @@ public class RPCService { clientBootstrap = null; channelInitializer = null; if (bossGroup != null) - NettyUtils.shutdownAndWait("Sync RPC Service boss group", bossGroup); + bossGroup.shutdownGracefully(); bossGroup = null; if (workerGroup != null) - NettyUtils.shutdownAndWait("Sync RPC Service worker group", workerGroup); + workerGroup.shutdownGracefully(); workerGroup = null; } catch (InterruptedException e) { logger.warn("Interrupted while shutting down RPC server");