public class JobAgentConnection
extends java.lang.Object
implements java.lang.AutoCloseable
start
, stop
and info
commands.JobAgentServerConnection
Modifier and Type | Field and Description |
---|---|
private static java.util.regex.Pattern |
HEADER_REGEXP
Regexp used to parse a typical answer.
|
private int |
port |
private java.lang.String |
server |
private int |
timeout |
Constructor and Description |
---|
JobAgentConnection(int port,
int timeout)
Create a connection to the local job agent running on the specified port.
|
JobAgentConnection(java.lang.String server,
int port,
int timeout)
Create a connection to the job agent running on the specified server
and listening on the specified port.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the connection to the job agent.
|
private java.net.Socket |
connect()
Create a socket connection to the job agent.
|
JobAgentInfo |
getInfo(boolean full)
Send an
info or status request to the job agent. |
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
parseAnswer(java.lang.String answer)
Utility method for parsing a 'typical' answer from a job agent.
|
static java.util.Map<java.lang.String,java.lang.String> |
parseSimpleAnswer(java.lang.String answer)
Utility method for parsing a 'typical' answer from a job agent.
|
java.lang.String |
send(java.lang.String cmd)
Send a remote control command to the job agent.
|
private java.lang.String |
sendCmd(java.net.Socket socket,
java.lang.String cmd)
Send a command to the job agent and return the answer.
|
java.lang.String |
sendPause() |
java.lang.String |
sendPing()
Send the
ping command to the job agent. |
java.lang.String |
sendStart()
Send a
start request to the job agent. |
java.lang.String |
sendStop() |
private static final java.util.regex.Pattern HEADER_REGEXP
private final java.lang.String server
private final int port
private final int timeout
public JobAgentConnection(int port, int timeout)
port
- The port the job agent is listening ontimeout
- The timeout in millisecondspublic JobAgentConnection(java.lang.String server, int port, int timeout)
server
- The server the job agent is running on, or null
to connect to the local hostport
- The port the job agent is listening ontimeout
- The timeout in millisecondspublic static java.util.Map<java.lang.String,java.util.List<java.lang.String>> parseAnswer(java.lang.String answer)
answer
- The answerpublic static java.util.Map<java.lang.String,java.lang.String> parseSimpleAnswer(java.lang.String answer)
answer
- The answerpublic java.lang.String sendPing() throws java.io.IOException
ping
command to the job agent. The only
answer to this command is OK
.java.io.IOException
- If there is an errorpublic java.lang.String sendStart() throws java.io.IOException
start
request to the job agent.java.io.IOException
- If there is an errorpublic java.lang.String sendStop() throws java.io.IOException
java.io.IOException
public java.lang.String sendPause() throws java.io.IOException
java.io.IOException
public JobAgentInfo getInfo(boolean full) throws java.io.IOException
info
or status
request to the job agent.
The difference is that a status
request doesn't return
information about cpu, memory or executing jobs.full
- If TRUE a info
request is sent, othwerwise
a status
request is sentJobAgentInfo
object containing the
informationjava.io.IOException
- If there is an errorpublic void close()
close
in interface java.lang.AutoCloseable
public java.lang.String send(java.lang.String cmd) throws java.io.IOException
cmd
- The command to sendjava.io.IOException
- If there is an errorprivate java.net.Socket connect() throws java.io.IOException
java.io.IOException
private java.lang.String sendCmd(java.net.Socket socket, java.lang.String cmd) throws java.io.IOException
FAILED
an exception will be thrown.socket
- The socket used for communicating with the job agentcmd
- The command to sendjava.io.IOException
- If there is a communications error