public class NGServer extends Object implements Runnable
This class can be run as a standalone server or can be embedded within larger applications as a means of providing command-line interaction with the application.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SESSIONPOOLSIZE
Default size for thread pool
|
PrintStream |
err
System.err at the time of the NGServer's creation |
InputStream |
in
System.in at the time of the NGServer's creation |
PrintStream |
out
System.out at the time of the NGServer's creation |
Constructor and Description |
---|
NGServer()
Creates a new NGServer that will listen on the default port (defined in
NGConstants.DEFAULT_PORT ). |
NGServer(InetAddress addr,
int port)
Creates a new NGServer that will listen at the specified address and on the specified port with
the default session pool size.
|
NGServer(InetAddress addr,
int port,
int sessionPoolSize,
int timeoutMillis)
Creates a new NGServer that will listen at the specified address and on the specified port with
the specified session pool size.
|
NGServer(NGListeningAddress listeningAddress,
int sessionPoolSize,
int timeoutMillis)
Creates a new NGServer that will listen at the specified address and on the specified port with
the specified session pool size.
|
Modifier and Type | Method and Description |
---|---|
boolean |
allowsNailsByClassName()
Returns a flag that indicates whether Nail lookups by classname are allowed.
|
AliasManager |
getAliasManager()
Returns the AliasManager in use by this NGServer.
|
Class |
getDefaultNailClass()
Returns the default class that will be used if no Nails can be found via alias or classname.
|
int |
getHeartbeatTimeout() |
Map<String,NailStats> |
getNailStats()
Returns a snapshot of this NGServer's nail statistics.
|
int |
getPort()
Returns the port on which this server is (or will be) listening.
|
boolean |
isRunning()
Returns true iff the server is currently running.
|
static void |
main(String[] args)
Creates and starts a new
NGServer . |
void |
run()
Listens for new connections and launches NGSession threads to process them.
|
void |
setAllowNailsByClassName(boolean allowNailsByClassName)
Sets a flag that determines whether Nails can be executed by class name.
|
void |
setDefaultNailClass(Class defaultNailClass)
Sets the default class to use for the Nail if no Nails can be found via alias or classname.
|
void |
shutdown()
Shuts down the server.
|
void |
signalExit()
Signal Nailgun server that it needs to stop listening to incoming nail requests and shut down
itself after it processes all current nails The function returns immediately, actual shutdown
will happen later
|
public static final int DEFAULT_SESSIONPOOLSIZE
public final PrintStream out
System.out
at the time of the NGServer's creationpublic final PrintStream err
System.err
at the time of the NGServer's creationpublic final InputStream in
System.in
at the time of the NGServer's creationpublic NGServer(InetAddress addr, int port, int sessionPoolSize, int timeoutMillis)
Thread
wrapping this NGServer
and start it.addr
- the address at which to listen, or null
to bind to all local addressesport
- the port on which to listen.sessionPoolSize
- the max number of idle sessions allowed by the poolpublic NGServer(InetAddress addr, int port)
Thread
wrapping this NGServer
and start it.addr
- the address at which to listen, or null
to bind to all local addressesport
- the port on which to listen.public NGServer()
NGConstants.DEFAULT_PORT
). This does not cause the server to start listening. To
do so, create a new Thread
wrapping this NGServer
and start it.public NGServer(NGListeningAddress listeningAddress, int sessionPoolSize, int timeoutMillis)
Thread
wrapping this NGServer
and start it.listeningAddress
- the address at which to listensessionPoolSize
- the max number of idle sessions allowed by the pooltimeoutMillis
- timeout in millis to wait for a heartbeat from the client before
disconnecting thempublic void setAllowNailsByClassName(boolean allowNailsByClassName)
allowNailsByClassName
- true iff Nail lookups by classname are allowedpublic boolean allowsNailsByClassName()
public void setDefaultNailClass(Class defaultNailClass)
null
, in which case NailGun will use its own default)defaultNailClass
- the default class to use for the Nail if no Nails can be found via
alias or classname. (may be null
, in which case NailGun will use its own
default)public Class getDefaultNailClass()
public Map<String,NailStats> getNailStats()
java.util.Map
, keyed by class name, with NailStats objects as values.public AliasManager getAliasManager()
public void signalExit()
public void shutdown()
Any nails that provide a
public static void nailShutdown(NGServer)
method will have this method called with this NGServer as its sole parameter.public boolean isRunning()
public int getPort()
public void run()
public static void main(String[] args) throws NumberFormatException, UnknownHostException
NGServer
. A single optional argument is valid, specifying
the port on which this NGServer
should listen. If omitted,
NGServer.DEFAULT_PORT
will be used.args
- a single optional argument specifying the port on which to listen.NumberFormatException
- if a non-numeric port is specifiedUnknownHostException
public int getHeartbeatTimeout()
Copyright © 2024. All rights reserved.