Class NGSessionPool

java.lang.Object
com.martiansoftware.nailgun.NGSessionPool

class NGSessionPool extends Object
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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) boolean
    have we been shut down?
    private final Object
    synchronization object
    (package private) final NGSession[]
    the pool itself
    (package private) int
    The number of sessions currently in the pool
    (package private) final int
    number of sessions to store in the pool
    (package private) final NGServer
    reference to server we're working for
  • Constructor Summary

    Constructors
    Constructor
    Description
    NGSessionPool(NGServer server, int poolsize)
    Creates a new NGSessionRunner operating for the specified server, with the specified number of threads
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    give(NGSession session)
    Returns an NGSession to the pool.
    (package private) void
    Shuts down the pool.
    (package private) NGSession
    Returns an NGSession from the pool, or creates one if necessary

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • poolSize

      final int poolSize
      number of sessions to store in the pool
    • pool

      final NGSession[] pool
      the pool itself
    • poolEntries

      int poolEntries
      The number of sessions currently in the pool
    • server

      final NGServer server
      reference to server we're working for
    • done

      boolean done
      have we been shut down?
    • lock

      private final Object lock
      synchronization object
  • Constructor Details

    • NGSessionPool

      NGSessionPool(NGServer server, int poolsize)
      Creates a new NGSessionRunner operating for the specified server, with the specified number of threads
      Parameters:
      server - the server to work for
      poolsize - the maximum number of idle threads to allow
  • Method Details

    • take

      NGSession take()
      Returns an NGSession from the pool, or creates one if necessary
      Returns:
      an NGSession ready to work
    • give

      void give(NGSession session)
      Returns an NGSession to the pool. The pool may choose to shutdown the thread if the pool is full
      Parameters:
      session - the NGSession to return to the pool
    • shutdown

      void shutdown()
      Shuts down the pool. Running nails are allowed to finish.