Package com.martiansoftware.nailgun
Class NGSession
- java.lang.Object
-
- java.lang.Thread
-
- com.martiansoftware.nailgun.NGSession
-
- All Implemented Interfaces:
java.lang.Runnable
class NGSession extends java.lang.ThreadReads 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 Summary
Fields Modifier and Type Field Description private booleandoneTrue if the server has been shutdown and this NGSession should terminate completelyprivate static longinstanceCounterThe instance counter shared among all NGSessionsprivate longinstanceNumberThe instance number of this NGSession.private java.lang.ObjectlockSynchronization objectprivate static java.lang.Class[]mainSignaturesignature of main(String[]) for reflection operationsprivate static java.lang.Class[]nailMainSignaturesignature of nailMain(NGContext) for reflection operationsprivate java.net.SocketnextSocketThe next socket this NGSession has been tasked with processing (by NGServer)private NGServerserverThe server this NGSession is working forprivate NGSessionPoolsessionPoolThe pool this NGSession came from, and to which it will return itselfprivate static java.lang.ObjectsharedLockA lock shared among all NGSessions
-
Constructor Summary
Constructors Constructor Description NGSession(NGSessionPool sessionPool, NGServer server)Creates a new NGSession running for the specified NGSessionPool and NGServer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.net.SocketnextSocket()Returns the next socket to process.voidrun()The main NGSession loop.voidrun(java.net.Socket socket)Instructs this NGSession to process the specified socket, after which this NGSession will return itself to the pool from which it came.(package private) voidshutdown()Shuts down this NGSession gracefullyprivate voidupdateThreadName(java.lang.String detail)Updates the current thread name (useful for debugging).-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
server
private NGServer server
The server this NGSession is working for
-
sessionPool
private NGSessionPool sessionPool
The pool this NGSession came from, and to which it will return itself
-
lock
private java.lang.Object lock
Synchronization object
-
nextSocket
private java.net.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 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.
-
sharedLock
private static java.lang.Object sharedLock
A lock shared among all NGSessions
-
instanceCounter
private static long instanceCounter
The instance counter shared among all NGSessions
-
mainSignature
private static java.lang.Class[] mainSignature
signature of main(String[]) for reflection operations
-
nailMainSignature
private static java.lang.Class[] nailMainSignature
signature of nailMain(NGContext) for reflection operations
-
-
Constructor Detail
-
NGSession
NGSession(NGSessionPool sessionPool, NGServer server)
Creates a new NGSession running for the specified NGSessionPool and NGServer.- Parameters:
sessionPool- The NGSessionPool we're working forserver- The NGServer we're working for
-
-
Method Detail
-
shutdown
void shutdown()
Shuts down this NGSession gracefully
-
run
public void run(java.net.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 java.net.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
nullif 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:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
updateThreadName
private void updateThreadName(java.lang.String detail)
Updates the current thread name (useful for debugging).
-
-