Class NGSession

java.lang.Object
java.lang.Thread
com.martiansoftware.nailgun.NGSession
All Implemented Interfaces:
Runnable

public class NGSession extends Thread
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.
  • Field Details

    • LOG

      private static final Logger LOG
    • server

      private final NGServer server
      The server this NGSession is working for
    • sessionPool

      private final NGSessionPool sessionPool
      The pool this NGSession came from, and to which it will return itself
    • lock

      private final Object lock
      Synchronization object
    • nextSocket

      private Socket nextSocket
      The next socket this NGSession has been tasked with processing (by NGServer)
    • done

      private boolean done
      True if the server has been shutdown and this NGSession should terminate completely
    • instanceNumber

      private final long instanceNumber
      The instance number of this NGSession. That is, if this is the Nth NGSession to be created, then this is the value for N.
    • heartbeatTimeoutMillis

      private final int heartbeatTimeoutMillis
      The interval to wait between heartbeats before considering the client to have disconnected.
    • instanceCounter

      private static AtomicLong instanceCounter
      The instance counter shared among all NGSessions
    • mainSignature

      private static final Class[] mainSignature
      signature of main(String[]) for reflection operations
    • nailMainSignature

      private static final Class[] nailMainSignature
      signature of nailMain(NGContext) for reflection operations
    • classLoader

      public static volatile ClassLoader classLoader
      A ClassLoader that may be set by a client. Defaults to the classloader of this class.
  • Constructor Details

    • NGSession

      NGSession(NGSessionPool sessionPool, NGServer server)
      Creates a new NGSession running for the specified NGSessionPool and NGServer.
      Parameters:
      sessionPool - The NGSessionPool we're working for
      server - The NGServer we're working for
  • Method Details

    • shutdown

      void shutdown()
      Shuts down this NGSession gracefully
    • run

      public void run(Socket socket)
      Instructs this NGSession to process the specified socket, after which this NGSession will return itself to the pool from which it came.
      Parameters:
      socket - the socket (connected to a client) to process
    • nextSocket

      private Socket nextSocket()
      Returns the next socket to process. This will block the NGSession thread until there's a socket to process or the NGSession has been shut down.
      Returns:
      the next socket to process, or null if the NGSession has been shut down.
    • run

      public void run()
      The main NGSession loop. This gets the next socket to process, runs the nail for the socket, and loops until shut down.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • updateThreadName

      private void updateThreadName(String detail)
      Updates the current thread name (useful for debugging).