Package com.swiftmq.admin.cli
Class CLI
java.lang.Object
com.swiftmq.admin.cli.CLI
- All Implemented Interfaces:
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.
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
ConstructorsConstructorDescriptionCLI
(ConnectionHolder connectionHolder, 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
Modifier and TypeMethodDescriptionvoid
Add a router listenervoid
close()
Closed all resources created by CLI.createEndpoint
(String routerName, boolean routeInfos) void
executeCommand
(String cmd) Executes a CLI command.Returns the actual context, resulting from the last 'cc' command.Returns the actual router name, resulting from the last 'sr' command.String[]
Returns all currently available router names.String[]
Returns an array with names of all entities of the actual context.getContextProperty
(String name) Returns a property value from the actual context.boolean
static void
void
markRouter
(String routerName, boolean available) void
reconnected
(String host, int port) void
removeEndpoint
(String routerName) void
Remove a router listener.void
run()
void
waitForRouter
(String routerName) Wait for availability of a specific router.void
waitForRouter
(String routerName, long timeout) Wait for availability of a specific router with timeout.
-
Constructor Details
-
CLI
- Throws:
Exception
-
CLI
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
-
reconnected
- Specified by:
reconnected
in interfaceReconnectListener
-
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
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
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
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
Returns all currently available router names.- Returns:
- array of router names
-
waitForRouter
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
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
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
Add a router listener- Parameters:
l
- router listener
-
removeRouterListener
Remove a router listener.- Parameters:
l
- router listener
-
isProgrammatic
public boolean isProgrammatic() -
markRouter
-
createEndpoint
- Throws:
Exception
-
removeEndpoint
-
run
public void run() -
close
public void close()Closed all resources created by CLI. This method will not close the QueueConnection!
-