Package net.sf.basedb.util.jobagent
Class JobAgentConnection
java.lang.Object
net.sf.basedb.util.jobagent.JobAgentConnection
- All Implemented Interfaces:
AutoCloseable
This class is used by client applications to communicate with job agents.
It used to send commands to job agents. For example, it can send
start
, stop
and info
commands.- Version:
- 2.0
- Author:
- nicklas
- See Also:
- Last modified
- $Date: 2018-12-12 15:41:10 +0100 (on, 12 dec 2018) $
-
Field Summary
-
Constructor Summary
ConstructorDescriptionJobAgentConnection
(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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the connection to the job agent.private Socket
connect()
Create a socket connection to the job agent.getInfo
(boolean full) Send aninfo
orstatus
request to the job agent.parseAnswer
(String answer) Utility method for parsing a 'typical' answer from a job agent.parseSimpleAnswer
(String answer) Utility method for parsing a 'typical' answer from a job agent.Send a remote control command to the job agent.private String
Send a command to the job agent and return the answer.sendPing()
Send theping
command to the job agent.Send astart
request to the job agent.sendStop()
-
Field Details
-
HEADER_REGEXP
Regexp used to parse a typical answer. -
server
-
port
private final int port -
timeout
private final int timeout
-
-
Constructor Details
-
JobAgentConnection
public JobAgentConnection(int port, int timeout) Create a connection to the local job agent running on the specified port.- Parameters:
port
- The port the job agent is listening ontimeout
- The timeout in milliseconds
-
JobAgentConnection
Create a connection to the job agent running on the specified server and listening on the specified port.- Parameters:
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 milliseconds
-
-
Method Details
-
parseAnswer
Utility method for parsing a 'typical' answer from a job agent. The typical answer is a string that contains a key-value pair on each line, separated by a colon. This method allows multiple entries for the same key.- Parameters:
answer
- The answer- Returns:
- A map with the key as index and a list with all values
- Since:
- 2.16
-
parseSimpleAnswer
Utility method for parsing a 'typical' answer from a job agent. The typical answer is a string that contains a key-value pair on each line, separated by a colon. This method allows only a single entry for the same key.- Parameters:
answer
- The answer- Returns:
- A map with the key as index to the value
- Since:
- 2.16
-
sendPing
Send theping
command to the job agent. The only answer to this command isOK
.- Returns:
- OK if successful
- Throws:
IOException
- If there is an error
-
sendStart
Send astart
request to the job agent.- Returns:
- OK if successful
- Throws:
IOException
- If there is an error
-
sendStop
- Throws:
IOException
-
sendPause
- Throws:
IOException
-
getInfo
Send aninfo
orstatus
request to the job agent. The difference is that astatus
request doesn't return information about cpu, memory or executing jobs.- Parameters:
full
- If TRUE ainfo
request is sent, othwerwise astatus
request is sent- Returns:
- A
JobAgentInfo
object containing the information - Throws:
IOException
- If there is an error
-
close
public void close()Close the connection to the job agent. In the current implementation all connections are stateless and this method does nothing. This might change in the future if a more advanced protocol is implemented. Clients should always call this method.- Specified by:
close
in interfaceAutoCloseable
-
send
Send a remote control command to the job agent.- Parameters:
cmd
- The command to send- Returns:
- The answer
- Throws:
IOException
- If there is an error- Since:
- 2.16 (was private before that)
-
connect
Create a socket connection to the job agent.- Returns:
- The socket
- Throws:
IOException
-
sendCmd
Send a command to the job agent and return the answer. If the answer isFAILED
an exception will be thrown.- Parameters:
socket
- The socket used for communicating with the job agentcmd
- The command to send- Returns:
- The answer from the job server
- Throws:
IOException
- If there is a communications error
-