Skip to content

Commit

Permalink
make explicit the accidental non-pooling behaviour of NGSessionPool
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoroka committed Jun 18, 2015
1 parent 47801bc commit 948cb26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public class NGServer implements Runnable {
private Class defaultNailClass = null;

/**
* A pool of NGSessions ready to handle client connections
* A source of NGSessions ready to handle client connections
*/
private NGSessionPool sessionPool = null;
private NGSessionCreator sessionCreator = null;

/**
* <code>System.out</code> at the time of the NGServer's creation
Expand Down Expand Up @@ -116,23 +116,22 @@ public class NGServer implements Runnable {

/**
* Creates a new NGServer that will listen at the specified address and on
* the specified port with the specified session pool size. This does
* the specified port. This does
* <b>not</b> cause the server to start listening. To do so, create a new
* <code>Thread</code> wrapping this
* <code>NGServer</code> and start it.
*
* @param addr the address at which to listen, or
* <code>null</code> to bind to all local addresses
* @param port the port on which to listen.
* pool
*/
public NGServer(InetAddress addr, int port, int timeoutMillis) {
init(addr, port, timeoutMillis);
}

/**
* Creates a new NGServer that will listen at the specified address and on
* the specified port with the default session pool size. This does
* the specified port. This does
* <b>not</b> cause the server to start listening. To do so, create a new
* <code>Thread</code> wrapping this
* <code>NGServer</code> and start it.
Expand Down Expand Up @@ -161,7 +160,6 @@ public NGServer() {
*
* @param addr the InetAddress to bind to
* @param port the port on which to listen
* pool
*/
private void init(InetAddress addr, int port, int timeoutMillis) {
this.addr = addr;
Expand All @@ -171,7 +169,7 @@ private void init(InetAddress addr, int port, int timeoutMillis) {
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);
sessionCreator = new NGSessionCreator(this);
this.heartbeatTimeoutMillis = timeoutMillis;
}

Expand Down Expand Up @@ -405,7 +403,7 @@ public void run() {
}

while (!shutdown) {
sessionOnDeck = sessionPool.take();
sessionOnDeck = sessionCreator.take();
Socket socket = serversocket.accept();
sessionOnDeck.run(socket);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* Reads the NailGun stream from the client through the command, then hands off
* processing to the appropriate class. The NGSession obtains its sockets from
* an NGSessionPool, which created this NGSession.
* an NGSessionCreator, which created this NGSession.
*
* @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
*/
Expand All @@ -41,9 +41,9 @@ public class NGSession extends Thread {
*/
private NGServer server = null;
/**
* The pool this NGSession came from, and to which it will return itself
* The creator this NGSession came from, and which will shut it down
*/
private NGSessionPool sessionPool = null;
private NGSessionCreator sessionCreator = null;
/**
* Synchronization object
*/
Expand Down Expand Up @@ -108,15 +108,15 @@ public class NGSession extends Thread {
}

/**
* Creates a new NGSession running for the specified NGSessionPool and
* Creates a new NGSession running for the specified NGSessionCreator and
* NGServer.
*
* @param sessionPool The NGSessionPool we're working for
* @param sessionCreator The NGSessionCreator we're working for
* @param server The NGServer we're working for
*/
NGSession(NGSessionPool sessionPool, NGServer server) {
NGSession(NGSessionCreator sessionCreator, NGServer server) {
super();
this.sessionPool = sessionPool;
this.sessionCreator = sessionCreator;
this.server = server;
this.heartbeatTimeoutMillis = server.getHeartbeatTimeout();

Expand All @@ -139,7 +139,7 @@ void shutdown() {

/**
* Instructs this NGSession to process the specified socket, after which
* this NGSession will return itself to the pool from which it came.
* this NGSession will shut itsef down.
*
* @param socket the socket (connected to a client) to process
*/
Expand Down Expand Up @@ -375,7 +375,7 @@ public void run() {
((ThreadLocalPrintStream) System.err).init(null);

updateThreadName(null);
sessionPool.give(this);
sessionCreator.give(this);
socket = nextSocket();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
*/
class NGSessionPool {
class NGSessionCreator {

/**
* reference to server we're working for
Expand All @@ -40,12 +40,12 @@ class NGSessionPool {
* the specified number of threads
* @param server the server to work for
*/
NGSessionPool(NGServer server) {
NGSessionCreator(NGServer server) {
this.server = server;
}

/**
* Returns an NGSession from the pool, or creates one if necessary
* Returns a new NGSession
* @return an NGSession ready to work
*/
NGSession take() {
Expand All @@ -58,9 +58,8 @@ NGSession take() {
}

/**
* Returns an NGSession to the pool. The pool may choose to shutdown
* the thread if the pool is full
* @param session the NGSession to return to the pool
* Returns an NGSession to the creator. The creator calls shutdown immediately
* @param session the NGSession to shutdown
*/
void give(NGSession session) {
session.shutdown();
Expand Down

0 comments on commit 948cb26

Please sign in to comment.