Class NGContext
java.lang.Object
com.martiansoftware.nailgun.NGContext
Provides quite a bit of potentially useful information to classes specifically written for NailGun. The NailGun server itself, its AliasManager, the remote client's environment variables, and other information is available via this class. For all intents and purposes, the NGContext represents a single connection from a NailGun client.
If a class is written with apublic static void nailMain(NGContext context)
method, that method will be called by NailGun instead of the traditional
main(String[]) method normally used for programs. A fully populated NGContext
object will then be provided to nailMain().-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String[]Command line arguments for the nailprivate StringThe command that was issued for this connectionThe client's stderrprivate PrintStreamA stream to which a client exit code can be printedThe client's stdinThe client's stdoutprivate PropertiesThe remote host's environment variablesprivate InetAddressThe remote host's addressprivate intThe port on the remote host that is communicating with NailGunprivate NGServerThe NGServer that accepted this connectionprivate String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClientListener(NGClientListener listener) voidaddHeartbeatListener(NGHeartbeatListener listener) voidThrows ajava.lang.SecurityExceptionif the client is not connected from the local machine.voidThrows ajava.lang.SecurityExceptionif the client is not connected via the loopback address.voidexit(int exitCode) Sends an exit command with the specified exit code to the client.String[]getArgs()Returns the command line arguments for the command implementation (nail) on the server.Returns the command that was issued by the client (either an alias or the name of a class).getEnv()Returns ajava.util.Propertiesobject containing a copy of the client's environment variablesReturns the file separator ('/' or '\\') used by the client's os.Returns the address of the client at the other side of this connection.private NGInputStreamReturns the NGServer that accepted this connectionReturns the path separator (':' or ';') used by the client's os.intgetPort()Returns the port on the client connected to the NailGun server.Returns the current working directory of the client, as reported by the client.booleanvoidDo not notify about client exitvoidremoveClientListener(NGClientListener listener) voidremoveHeartbeatListener(NGHeartbeatListener listener) voidvoidsetCommand(String command) (package private) voidsetEnv(Properties remoteEnvironment) voidsetExitStream(PrintStream exitStream) (package private) voidsetInetAddress(InetAddress remoteHost) (package private) voidsetNGServer(NGServer server) voidsetPort(int remotePort) (package private) voidsetWorkingDirectory(String workingDirectory)
-
Field Details
-
remoteEnvironment
The remote host's environment variables -
remoteHost
The remote host's address -
remotePort
private int remotePortThe port on the remote host that is communicating with NailGun -
args
Command line arguments for the nail -
exitStream
A stream to which a client exit code can be printed -
server
The NGServer that accepted this connection -
command
The command that was issued for this connection -
workingDirectory
-
in
The client's stdin -
out
The client's stdout -
err
The client's stderr
-
-
Constructor Details
-
NGContext
public NGContext()Creates a new, empty NGContext
-
-
Method Details
-
setExitStream
-
setPort
public void setPort(int remotePort) -
setCommand
-
getCommand
Returns the command that was issued by the client (either an alias or the name of a class). This allows multiple aliases to point to the same class but result in different behaviors.- Returns:
- the command issued by the client
-
setWorkingDirectory
-
getWorkingDirectory
Returns the current working directory of the client, as reported by the client. This is a String that will use the client'sFile.separator('/' or '\'), which may differ from the separator on the server.- Returns:
- the current working directory of the client
-
setEnv
-
setInetAddress
-
setArgs
-
setNGServer
-
getEnv
Returns ajava.util.Propertiesobject containing a copy of the client's environment variables- Returns:
- a
java.util.Propertiesobject containing a copy of the client's environment variables - See Also:
-
getFileSeparator
Returns the file separator ('/' or '\\') used by the client's os.- Returns:
- the file separator ('/' or '\\') used by the client's os.
-
getPathSeparator
Returns the path separator (':' or ';') used by the client's os.- Returns:
- the path separator (':' or ';') used by the client's os.
-
getInetAddress
Returns the address of the client at the other side of this connection.- Returns:
- the address of the client at the other side of this connection.
-
getArgs
Returns the command line arguments for the command implementation (nail) on the server.- Returns:
- the command line arguments for the command implementation (nail) on the server.
-
getNGServer
Returns the NGServer that accepted this connection- Returns:
- the NGServer that accepted this connection
-
exit
public void exit(int exitCode) Sends an exit command with the specified exit code to the client. The client will exit immediately with the specified exit code; you probably want to return from nailMain immediately after calling this.- Parameters:
exitCode- the exit code with which the client should exit
-
getPort
public int getPort()Returns the port on the client connected to the NailGun server.- Returns:
- the port on the client connected to the NailGun server.
-
assertLoopbackClient
public void assertLoopbackClient()Throws ajava.lang.SecurityExceptionif the client is not connected via the loopback address. -
assertLocalClient
public void assertLocalClient()Throws ajava.lang.SecurityExceptionif the client is not connected from the local machine. -
getInputStream
- Returns:
- the
NGInputStreamfor this session.
-
isClientConnected
public boolean isClientConnected()- Returns:
- true if client is connected, false if a client exit has been detected.
-
addClientListener
- Parameters:
listener- theNGClientListenerto be notified of client events.
-
removeClientListener
- Parameters:
listener- theNGClientListenerto no longer be notified of client events.
-
removeAllClientListeners
public void removeAllClientListeners()Do not notify about client exit -
addHeartbeatListener
- Parameters:
listener- theNGHeartbeatListenerto be notified of client events.
-
removeHeartbeatListener
- Parameters:
listener- theNGHeartbeatListenerto no longer be notified of client events.
-