CommandClient (Apache ZooKeeper - Server 3.7.0 API)
Date: 2021-03-17

org.apache.zookeeper.server.controller

## 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 and Description
    `CommandClient(InetSocketAddress hostAddress, int requestTimeoutInMs)` Instantiate a client configured to send requests to the specified host address.
    `CommandClient(int localhostPort)`
    `CommandClient(int localHostPort, int requestTimeoutInMs)` Instantiate a client configured to send requests to localhost.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and 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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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`

Copyright © 2008–2021 The Apache Software Foundation. All rights reserved.