Package com.swiftmq.admin.cli
Class CLI
- java.lang.Object
-
- com.swiftmq.admin.cli.CLI
-
- All Implemented Interfaces:
ReconnectListener
public class CLI extends java.lang.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 Summary
Constructors Constructor Description CLI(ConnectionHolder connectionHolder, java.lang.String scriptFile)
CLI(javax.jms.QueueConnection queueConnection)
Creates a new CLI object and does the necessary setup (creating some sessions, senders and receivers).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRouterListener(RouterListener l)
Add a router listenervoid
close()
Closed all resources created by CLI.Endpoint
createEndpoint(java.lang.String routerName, boolean routeInfos)
void
executeCommand(java.lang.String cmd)
Executes a CLI command.java.lang.String
getActContext()
Returns the actual context, resulting from the last 'cc' command.java.lang.String
getActRouter()
Returns the actual router name, resulting from the last 'sr' command.java.lang.String[]
getAvailableRouters()
Returns all currently available router names.java.lang.String[]
getContextEntities()
Returns an array with names of all entities of the actual context.java.lang.String
getContextProperty(java.lang.String name)
Returns a property value from the actual context.boolean
isProgrammatic()
static void
main(java.lang.String[] args)
void
markRouter(java.lang.String routerName, boolean available)
void
reconnected(java.lang.String host, int port)
void
removeEndpoint(java.lang.String routerName)
void
removeRouterListener(RouterListener l)
Remove a router listener.void
run()
void
waitForRouter(java.lang.String routerName)
Wait for availability of a specific router.void
waitForRouter(java.lang.String routerName, long timeout)
Wait for availability of a specific router with timeout.
-
-
-
Constructor Detail
-
CLI
public CLI(ConnectionHolder connectionHolder, java.lang.String scriptFile) throws java.lang.Exception
- Throws:
java.lang.Exception
-
CLI
public CLI(javax.jms.QueueConnection queueConnection) throws java.lang.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:
java.lang.Exception
- if anything goes wrong during setup
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
-
reconnected
public void reconnected(java.lang.String host, int port)
- Specified by:
reconnected
in interfaceReconnectListener
-
getActRouter
public java.lang.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 java.lang.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 java.lang.String getContextProperty(java.lang.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 java.lang.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 java.lang.String[] getAvailableRouters()
Returns all currently available router names.- Returns:
- array of router names
-
waitForRouter
public void waitForRouter(java.lang.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(java.lang.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 nametimeout
- timeout value in milliseconds
-
executeCommand
public void executeCommand(java.lang.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(java.lang.String routerName, boolean available)
-
createEndpoint
public Endpoint createEndpoint(java.lang.String routerName, boolean routeInfos) throws java.lang.Exception
- Throws:
java.lang.Exception
-
removeEndpoint
public void removeEndpoint(java.lang.String routerName)
-
run
public void run()
-
close
public void close()
Closed all resources created by CLI. This method will not close the QueueConnection!
-
-