Class CommandClient
- java.lang.Object
-
- org.apache.zookeeper.server.controller.CommandClient
-
public class CommandClient extends Object
A convenient helper to send controller command to ControllerService.
-
-
Constructor Summary
Constructors Constructor Description CommandClient(int localhostPort)
CommandClient(int localHostPort, int requestTimeoutInMs)
Instantiate a client configured to send requests to localhost.CommandClient(InetSocketAddress hostAddress, int requestTimeoutInMs)
Instantiate a client configured to send requests to the specified host address.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
org.eclipse.jetty.client.api.ContentResponse
sendCommand(ControlCommand.Action action, String commandParameter)
Send a command and optional command parameter to the server and block until receiving a response.boolean
trySendCommand(ControlCommand.Action action)
Send a command with no parameters to the server and wait for a response.boolean
trySendCommand(ControlCommand.Action action, String commandParameter)
Send a command with an optional command parameter to the server and wait for a response.
-
-
-
Constructor Detail
-
CommandClient
public CommandClient(int localHostPort, int requestTimeoutInMs)
Instantiate a client configured to send requests to localhost.- Parameters:
localHostPort
- Port that the localhost CommandListener is listening on.requestTimeoutInMs
- Timeout in ms for synchronous requests to timeout.
-
CommandClient
public CommandClient(InetSocketAddress hostAddress, int requestTimeoutInMs)
Instantiate a client configured to send requests to the specified host address.- Parameters:
hostAddress
- The host address of the listening server.requestTimeoutInMs
- Timeout in ms for synchronous requests to timeout.
-
CommandClient
public CommandClient(int localhostPort)
-
-
Method Detail
-
close
public void close()
-
trySendCommand
public boolean trySendCommand(ControlCommand.Action action)
Send a command with no parameters to the server and wait for a response. Returns true if we received a good (200) response and false otherwise.
-
trySendCommand
public boolean trySendCommand(ControlCommand.Action action, String commandParameter)
Send a command with an optional command parameter to the server and wait for a response.- Parameters:
action
- The command Action to send.commandParameter
- The command parameter, in the form of command/action/parameter.- Returns:
- true if we received a good (200) response and false otherwise.
-
sendCommand
public org.eclipse.jetty.client.api.ContentResponse sendCommand(ControlCommand.Action action, String commandParameter) throws Exception
Send a command and optional command parameter to the server and block until receiving a response.- Parameters:
action
- The command Action to send.commandParameter
- The command parameter, in the form of command/action/parameter.- Returns:
- The full response body from the CommandListener server.
- Throws:
Exception
-
-