Class CommandClient


  • public class CommandClient
    extends java.lang.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​(java.net.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, java.lang.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, java.lang.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​(java.net.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,
                                      java.lang.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,
                                                                        java.lang.String commandParameter)
                                                                 throws java.lang.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:
        java.lang.Exception