public class JobAgentConnection extends Object
start
, stop
and info
commands.JobAgentServerConnection
Modifier and Type | Field and Description |
---|---|
private static Pattern |
HEADER_REGEXP
Regexp used to parse a typical answer.
|
private int |
port |
private 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(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 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 Map<String,List<String>> |
parseAnswer(String answer)
Utility method for parsing a 'typical' answer from a job agent.
|
static Map<String,String> |
parseSimpleAnswer(String answer)
Utility method for parsing a 'typical' answer from a job agent.
|
String |
send(String cmd)
Send a remote control command to the job agent.
|
private String |
sendCmd(Socket socket,
String cmd)
Send a command to the job agent and return the answer.
|
String |
sendPause() |
String |
sendPing()
Send the
ping command to the job agent. |
String |
sendStart()
Send a
start request to the job agent. |
String |
sendStop() |
private static final Pattern HEADER_REGEXP
private final 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(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 Map<String,List<String>> parseAnswer(String answer)
answer
- The answerpublic static Map<String,String> parseSimpleAnswer(String answer)
answer
- The answerpublic String sendPing() throws IOException
ping
command to the job agent. The only
answer to this command is OK
.IOException
- If there is an errorpublic String sendStart() throws IOException
start
request to the job agent.IOException
- If there is an errorpublic String sendStop() throws IOException
IOException
public String sendPause() throws IOException
IOException
public JobAgentInfo getInfo(boolean full) throws 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
informationIOException
- If there is an errorpublic void close()
public String send(String cmd) throws IOException
cmd
- The command to sendIOException
- If there is an errorprivate Socket connect() throws IOException
IOException
private String sendCmd(Socket socket, String cmd) throws IOException
FAILED
an exception will be thrown.socket
- The socket used for communicating with the job agentcmd
- The command to sendIOException
- If there is a communications error