Package com.martiansoftware.nailgun
Class NGContext
- java.lang.Object
-
- com.martiansoftware.nailgun.NGContext
-
public class NGContext extends Object
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 a
method, that method will be called by NailGun instead of the traditionalpublic static void nailMain(NGContext context)
main(String[])
method normally used for programs. A fully populatedNGContext
object will then be provided tonailMain()
.- Author:
- Marty Lamb
-
-
Field Summary
Fields Modifier and Type Field Description PrintStream
err
The client's stderrInputStream
in
The client's stdinPrintStream
out
The client's stdout
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertLocalClient()
Throws ajava.lang.SecurityException
if the client is not connected from the local machine.void
assertLoopbackClient()
Throws ajava.lang.SecurityException
if the client is not connected via the loopback address.void
exit(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.String
getCommand()
Returns the command that was issued by the client (either an alias or the name of a class).Properties
getEnv()
Returns ajava.util.Properties
object containing a copy of the client's environment variablesString
getFileSeparator()
Returns the file separator ('/' or '\\') used by the client's os.InetAddress
getInetAddress()
Returns the address of the client at the other side of this connection.NGServer
getNGServer()
Returns the NGServer that accepted this connectionString
getPathSeparator()
Returns the path separator (':' or ';') used by the client's os.int
getPort()
Returns the port on the client connected to the NailGun server.String
getWorkingDirectory()
Returns the current working directory of the client, as reported by the client.
-
-
-
Field Detail
-
in
public InputStream in
The client's stdin
-
out
public PrintStream out
The client's stdout
-
err
public PrintStream err
The client's stderr
-
-
Method Detail
-
getCommand
public String 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
-
getWorkingDirectory
public String 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
-
getEnv
public Properties getEnv()
Returns ajava.util.Properties
object containing a copy of the client's environment variables- Returns:
- a
java.util.Properties
object containing a copy of the client's environment variables - See Also:
Properties
-
getFileSeparator
public String getFileSeparator()
Returns the file separator ('/' or '\\') used by the client's os.- Returns:
- the file separator ('/' or '\\') used by the client's os.
-
getPathSeparator
public String getPathSeparator()
Returns the path separator (':' or ';') used by the client's os.- Returns:
- the path separator (':' or ';') used by the client's os.
-
getInetAddress
public InetAddress 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
public String[] 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
public NGServer 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.SecurityException
if the client is not connected via the loopback address.
-
assertLocalClient
public void assertLocalClient()
Throws ajava.lang.SecurityException
if the client is not connected from the local machine.
-
-