Package com.martiansoftware.nailgun
Class NGSession
java.lang.Object
java.lang.Thread
com.martiansoftware.nailgun.NGSession
- All Implemented Interfaces:
Runnable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic ClassLoader
A ClassLoader that may be set by a client.private boolean
True if the server has been shutdown and this NGSession should terminate completelyprivate final int
The interval to wait between heartbeats before considering the client to have disconnected.private static AtomicLong
The instance counter shared among all NGSessionsprivate final long
The instance number of this NGSession.private final Object
Synchronization objectprivate static final Logger
private static final Class[]
signature of main(String[]) for reflection operationsprivate static final Class[]
signature of nailMain(NGContext) for reflection operationsprivate Socket
The next socket this NGSession has been tasked with processing (by NGServer)private final NGServer
The server this NGSession is working forprivate final NGSessionPool
The pool this NGSession came from, and to which it will return itselfFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionNGSession
(NGSessionPool sessionPool, NGServer server) Creates a new NGSession running for the specified NGSessionPool and NGServer. -
Method Summary
Modifier and TypeMethodDescriptionprivate Socket
Returns the next socket to process.void
run()
The main NGSession loop.void
Instructs this NGSession to process the specified socket, after which this NGSession will return itself to the pool from which it came.(package private) void
shutdown()
Shuts down this NGSession gracefullyprivate void
updateThreadName
(String detail) Updates the current thread name (useful for debugging).Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
Field Details
-
LOG
-
server
The server this NGSession is working for -
sessionPool
The pool this NGSession came from, and to which it will return itself -
lock
Synchronization object -
nextSocket
The next socket this NGSession has been tasked with processing (by NGServer) -
done
private boolean doneTrue if the server has been shutdown and this NGSession should terminate completely -
instanceNumber
private final long instanceNumberThe 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 heartbeatTimeoutMillisThe interval to wait between heartbeats before considering the client to have disconnected. -
instanceCounter
The instance counter shared among all NGSessions -
mainSignature
signature of main(String[]) for reflection operations -
nailMainSignature
signature of nailMain(NGContext) for reflection operations -
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 forserver
- The NGServer we're working for
-
-
Method Details
-
shutdown
void shutdown()Shuts down this NGSession gracefully -
run
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
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. -
updateThreadName
Updates the current thread name (useful for debugging).
-