Class CLI

java.lang.Object
com.swiftmq.admin.cli.CLI
All Implemented Interfaces:
ReconnectListener

public class CLI extends Object implements ReconnectListener
CLI is SwiftMQ's command line interface.

It can be invoked from command line and can also be used for programmatic administration. For latter usage, CLI is to be constructed with a valid and stopped QueueConnection. The user of this QueueConnection must have full administrator rights which takes place if he has full right for the queue swiftmqmgmt of the respective routers or if the authentication is disabled.

Programmatic administration with CLI is the same as invoking it from command line. All CLI commands can be invoked by the executeCommand method. There is only an exception regarding commands that return a result as 'ar', 'lc', 'show template'. These commands are not available for programmatic administration. Invoking such a command results in a CLIException.

Please refer to the CLI documentation to get involved with the available CLI commands.

Note (1):

To detect a connection lost, for example, as a result of a 'reboot' command for the router the QueueConnection is connected to, you have to register your own ExceptionListener on the QueueConnection.

Note (2):

CLI can be used only from a single thread of execution. Executing methods from different threads concurrently can result in an unexpected behavior.

Note (3):

If the connection factory from which the CLI JMS connection is created is configured for transparent reconnect (default in SwiftMQ HA Router), CLI reconnects as well. However, it does not restore the last router in use ('sr' command) nor does it restore the last CLI context ('cc' command). This is the responsibility of the application that uses CLI. In order to restore the router and context, an application must catch CLIReconnectedException and issue the last 'sr' and 'cc' commands before retrying the command that leads to the CLIReconnectedException.
Since:
1.2
Author:
IIT GmbH, Bremen/Germany
  • Constructor Details

    • CLI

      public CLI(ConnectionHolder connectionHolder, String scriptFile) throws Exception
      Throws:
      Exception
    • CLI

      public CLI(javax.jms.QueueConnection queueConnection) throws Exception
      Creates a new CLI object and does the necessary setup (creating some sessions, senders and receivers). After the initial setup, CLI will start the connection.
      Parameters:
      queueConnection - queue connection, should be in stopped mode
      Throws:
      Exception - if anything goes wrong during setup
  • Method Details

    • main

      public static void main(String[] args)
    • reconnected

      public void reconnected(String host, int port)
      Specified by:
      reconnected in interface ReconnectListener
    • getActRouter

      public String getActRouter()
      Returns the actual router name, resulting from the last 'sr' command. If no actual router is set, null is returned.
      Returns:
      actual router name or null
    • getActContext

      public String getActContext()
      Returns the actual context, resulting from the last 'cc' command. If no actual context is set, null is returned.

      Example:

      Say, the last 'cc' command was cc sys$queuemanager/queues, then the actual context returned is /sys$queuemanager/queues.
      Returns:
      actual context or null
    • getContextProperty

      public String getContextProperty(String name) throws CLIException
      Returns a property value from the actual context. If the property name is not defined in the actual context or no actual context is set, a CLIException is thrown. The value of the property is always casted to String, regardless of the property type. If the property value is null, null is returned.

      Example:

      Say, you like to determine the value of the cache.size property of the queue testqueue. First, you have to set your actual context:

      cli.executeCommand("cc /sys$queuemanager/queues/testqueue");

      Next, you can get the property value:

      int cacheSize = Integer.parseInt(cli.getProperty("cache.size"));
      Parameters:
      name - name of the property
      Returns:
      value of the property
      Throws:
      CLIException - if no actual context set or property is unknown in the actual context
    • getContextEntities

      public String[] getContextEntities() throws CLIException
      Returns an array with names of all entities of the actual context.

      Example:

      Say, you like to determine all defined queues. First, you have to set your actual context:

      cli.executeCommand("cc /sys$queuemanager/queues");

      Next, you can get the context entities which are the queue names:

      String[] currentQueueNames = cli.getContextEntities();
      Returns:
      array of entity names
      Throws:
      CLIException - if no actual context set
    • getAvailableRouters

      public String[] getAvailableRouters()
      Returns all currently available router names.
      Returns:
      array of router names
    • waitForRouter

      public void waitForRouter(String routerName)
      Wait for availability of a specific router. If the router is already available, the method returns immediatly. Otherwise it will wait until the router becomes available.
      Parameters:
      routerName - router name
    • waitForRouter

      public void waitForRouter(String routerName, long timeout)
      Wait for availability of a specific router with timeout. If the router is already available, the method returns immediatly. Otherwise it will wait until the router becomes available or the timeout is reached.
      Parameters:
      routerName - router name
      timeout - timeout value in milliseconds
    • executeCommand

      public void executeCommand(String cmd) throws CLIException
      Executes a CLI command. Refer to the CLI documentation for an overview and description of all CLI commands. The method throw a CLIException if the command returns a result. Therefore, commads such as 'ar', 'sr', 'lc' cannot be invoked via this method. Note also that the command 'exit' will terminate the whole JVM!
      Parameters:
      cmd - CLI command to be executed
      Throws:
      CLIException - if something goes wrong such as invalid command or command returns a result
    • addRouterListener

      public void addRouterListener(RouterListener l)
      Add a router listener
      Parameters:
      l - router listener
    • removeRouterListener

      public void removeRouterListener(RouterListener l)
      Remove a router listener.
      Parameters:
      l - router listener
    • isProgrammatic

      public boolean isProgrammatic()
    • markRouter

      public void markRouter(String routerName, boolean available)
    • createEndpoint

      public Endpoint createEndpoint(String routerName, boolean routeInfos) throws Exception
      Throws:
      Exception
    • removeEndpoint

      public void removeEndpoint(String routerName)
    • run

      public void run()
    • close

      public void close()
      Closed all resources created by CLI. This method will not close the QueueConnection!