From c6e5364caf21e458b84142cfbd51ecc393b0e838 Mon Sep 17 00:00:00 2001 From: Joe Soroka Date: Wed, 17 Jun 2015 22:59:59 -0700 Subject: [PATCH] make explicit the accidental non-pooling behaviour of NGSessionPool --- .../com/martiansoftware/nailgun/NGServer.java | 23 ++----- .../nailgun/NGSessionPool.java | 65 ++----------------- 2 files changed, 12 insertions(+), 76 deletions(-) diff --git a/nailgun-server/src/main/java/com/martiansoftware/nailgun/NGServer.java b/nailgun-server/src/main/java/com/martiansoftware/nailgun/NGServer.java index d4ed379f..0e69d3f8 100644 --- a/nailgun-server/src/main/java/com/martiansoftware/nailgun/NGServer.java +++ b/nailgun-server/src/main/java/com/martiansoftware/nailgun/NGServer.java @@ -42,11 +42,6 @@ */ public class NGServer implements Runnable { - /** - * Default size for thread pool - */ - public static final int DEFAULT_SESSIONPOOLSIZE = 10; - /** * The address on which to listen, or null to listen on all local addresses */ @@ -129,11 +124,10 @@ public class NGServer implements Runnable { * @param addr the address at which to listen, or * null to bind to all local addresses * @param port the port on which to listen. - * @param sessionPoolSize the max number of idle sessions allowed by the * pool */ - public NGServer(InetAddress addr, int port, int sessionPoolSize, int timeoutMillis) { - init(addr, port, sessionPoolSize, timeoutMillis); + public NGServer(InetAddress addr, int port, int timeoutMillis) { + init(addr, port, timeoutMillis); } /** @@ -148,7 +142,7 @@ public NGServer(InetAddress addr, int port, int sessionPoolSize, int timeoutMill * @param port the port on which to listen. */ public NGServer(InetAddress addr, int port) { - init(addr, port, DEFAULT_SESSIONPOOLSIZE, NGConstants.HEARTBEAT_TIMEOUT_MILLIS); + init(addr, port, NGConstants.HEARTBEAT_TIMEOUT_MILLIS); } /** @@ -159,7 +153,7 @@ public NGServer(InetAddress addr, int port) { * NGServer and start it. */ public NGServer() { - init(null, NGConstants.DEFAULT_PORT, DEFAULT_SESSIONPOOLSIZE, NGConstants.HEARTBEAT_TIMEOUT_MILLIS); + init(null, NGConstants.DEFAULT_PORT, NGConstants.HEARTBEAT_TIMEOUT_MILLIS); } /** @@ -167,10 +161,9 @@ public NGServer() { * * @param addr the InetAddress to bind to * @param port the port on which to listen - * @param sessionPoolSize the max number of idle sessions allowed by the * pool */ - private void init(InetAddress addr, int port, int sessionPoolSize, int timeoutMillis) { + private void init(InetAddress addr, int port, int timeoutMillis) { this.addr = addr; this.port = port; @@ -178,7 +171,7 @@ private void init(InetAddress addr, int port, int sessionPoolSize, int timeoutMi allNailStats = new java.util.HashMap(); // allow a maximum of 10 idle threads. probably too high a number // and definitely should be configurable in the future - sessionPool = new NGSessionPool(this, sessionPoolSize); + sessionPool = new NGSessionPool(this); this.heartbeatTimeoutMillis = timeoutMillis; } @@ -325,8 +318,6 @@ public void shutdown(boolean exitVM) { } catch (Throwable toDiscard) { } - sessionPool.shutdown(); - Class[] argTypes = new Class[1]; argTypes[0] = NGServer.class; Object[] argValues = new Object[1]; @@ -495,7 +486,7 @@ public static void main(String[] args) throws NumberFormatException, UnknownHost } } - NGServer server = new NGServer(serverAddress, port, DEFAULT_SESSIONPOOLSIZE, timeoutMillis); + NGServer server = new NGServer(serverAddress, port, timeoutMillis); Thread t = new Thread(server); t.setName("NGServer(" + serverAddress + ", " + port + ")"); t.start(); diff --git a/nailgun-server/src/main/java/com/martiansoftware/nailgun/NGSessionPool.java b/nailgun-server/src/main/java/com/martiansoftware/nailgun/NGSessionPool.java index 96120709..29adf477 100644 --- a/nailgun-server/src/main/java/com/martiansoftware/nailgun/NGSessionPool.java +++ b/nailgun-server/src/main/java/com/martiansoftware/nailgun/NGSessionPool.java @@ -19,41 +19,17 @@ package com.martiansoftware.nailgun; /** - * Provides NGSession pooling functionality. One parameter, "maxIdle", - * governs its behavior by setting the maximum number of idle NGSession - * threads it will allow. It creates a pool of size maxIdle - 1, because - * one NGSession is kept "on deck" by the NGServer in order to eke out - * a little extra responsiveness. + * Provides NGSession creation functionality. * * @author Marty Lamb */ class NGSessionPool { - /** - * number of sessions to store in the pool - */ - int poolSize = 0; - - /** - * the pool itself - */ - NGSession[] pool = null; - - /** - * The number of sessions currently in the pool - */ - int poolEntries = 0; - /** * reference to server we're working for */ NGServer server = null; - /** - * have we been shut down? - */ - boolean done = false; - /** * synchronization object */ @@ -63,14 +39,9 @@ class NGSessionPool { * Creates a new NGSessionRunner operating for the specified server, with * the specified number of threads * @param server the server to work for - * @param poolsize the maximum number of idle threads to allow */ - NGSessionPool(NGServer server, int poolsize) { + NGSessionPool(NGServer server) { this.server = server; - this.poolSize = Math.min(0, poolsize); - - pool = new NGSession[poolSize]; - poolEntries = 0; } /** @@ -80,13 +51,8 @@ class NGSessionPool { NGSession take() { NGSession result; synchronized(lock) { - if (poolEntries == 0) { - result = new NGSession(this, server); - result.start(); - } else { - --poolEntries; - result = pool[poolEntries]; - } + result = new NGSession(this, server); + result.start(); } return (result); } @@ -97,28 +63,7 @@ NGSession take() { * @param session the NGSession to return to the pool */ void give(NGSession session) { - boolean shutdown = false; - synchronized(lock) { - if (done || poolEntries == poolSize) { - shutdown = true; - } else { - pool[poolEntries] = session; - ++poolEntries; - } - } - if (shutdown) session.shutdown(); - } - - /** - * Shuts down the pool. Running nails are allowed to finish. - */ - void shutdown() { - done = true; - synchronized(lock) { - while (poolEntries > 0) { - take().shutdown(); - } - } + session.shutdown(); } }