Package org.jboss.as.cli.impl
Class CommandExecutor.TimeoutCommandContext
- java.lang.Object
-
- org.jboss.as.cli.impl.CommandExecutor.TimeoutCommandContext
-
- All Implemented Interfaces:
CommandContext
- Enclosing class:
- CommandExecutor
public class CommandExecutor.TimeoutCommandContext extends Object implements CommandContext
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.as.cli.CommandContext
CommandContext.Scope, CommandContext.TIMEOUT_RESET_VALUE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEventListener(CliEventListener listener)Adds a listener for CLI events.voidbindClient(ModelControllerClient newClient)Bind the controller to an existing, connected client.org.jboss.dmr.ModelNodebuildRequest(String line)Builds a DMR request corresponding to the command or the operation.voidcaptureOutput(PrintStream captor)Redirect output to the given print stream.voidclear(CommandContext.Scope scope)Clear the content of a scope.voidclearScreen()Clears the screen.voidconnectController()Connects the controller client using the default controller definition.voidconnectController(String controller)Connects to the controller specified.voidconnectController(String host, int port)Connects the controller client using the host and the port.voidconnectController(String controller, String client)Connects to the controller specified.voiddisconnectController()Closes the previously established connection with the controller client.org.jboss.dmr.ModelNodeexecute(Operation op, String description)Execute an operation.org.jboss.dmr.ModelNodeexecute(org.jboss.dmr.ModelNode mn, String description)Execute an operation.Objectget(CommandContext.Scope scope, String key)Returns the value the key was associated with using the set(key, value) method above.StringgetArgumentsString()Returns the current command's arguments as a string.BatchManagergetBatchManager()Returns batch manager.CommandLineParsergetCommandLineParser()Returns the current operation request parser.intgetCommandTimeout()Returns the command execution timeout value.CliConfiggetConfig()Returns the JBoss CLI configuration.ConnectionInfogetConnectionInfo()The ConnectionInfo bean is set after the connection is established to the server.StringgetControllerHost()Returns the host the controller client is connected to or null if the connection hasn't been established yet.intgetControllerPort()Returns the port the controller client is connected to.FilegetCurrentDir()Returns current default filesystem directory.OperationRequestAddressgetCurrentNodePath()Returns the current prefix.CommandLineCompletergetDefaultCommandCompleter()Returns the default command line completer.ControllerAddressgetDefaultControllerAddress()The default address of the default controller to connect to.StringgetDefaultControllerHost()Returns the default host the controller client will be connected to.intgetDefaultControllerPort()Returns the default port the controller client will be connected to.intgetExitCode()Returns value that should be used as the exit code of the JVM process.CommandHistorygetHistory()Returns the history of all the commands and operations.Future<?>getLastTask()ModelControllerClientgetModelControllerClient()Returns the model controller client or null if it hasn't been initialized.NodePathFormattergetNodePathFormatter()Returns the prefix formatter.OperationCandidatesProvidergetOperationCandidatesProvider()Returns the provider of operation request candidates for tab-completion.ParsedCommandLinegetParsedCommandLine()Parsed command line arguments.intgetTerminalHeight()Returns the current terminal window height in case the console has been initialized.intgetTerminalWidth()Returns the current terminal window width in case the console has been initialized.StringgetVariable(String name)Returns the value for the variable.Collection<String>getVariables()Returns a collection of all the defined variable names.voidhandle(String line)Executes a command or an operation.voidhandleSafe(String line)Executes a command or an operation.voidinteract()This method will start an interactive session.booleanisBatchMode()Checks whether the CLI is in the batch mode.booleanisDomainMode()Indicates whether the CLI is in the domain mode or standalone one (assuming established connection to the controller).booleanisResolveParameterValues()Command argument or operation parameter values may contain system properties.booleanisSilent()Whether the info or error messages should be written to the terminal output.booleanisTerminated()Checks whether the session has been terminated.booleanisWorkflowMode()Checks whether the CLI is in a workflow mode.voidprintColumns(Collection<String> col)Prints a collection of strings as columns to the CLI's output.voidprintLine(String message)Prints a string to the CLI's output.voidregisterRedirection(CommandLineRedirection redirection)After this method returns command line handling will be redirected to the passed in CommandLineRedirection instance.voidreleaseOutput()Stops redirecting output to the stream passed toCommandContext.captureOutput(java.io.PrintStream).Objectremove(CommandContext.Scope scope, String key)Removes the value the key was associated with using the set(key, value) method above.voidresetTimeout(CommandContext.TIMEOUT_RESET_VALUE value)Reset the timeout value.voidset(CommandContext.Scope scope, String key, Object value)Associates an object with key.voidsetCommandTimeout(int numSeconds)Set the command timeout to a number of seconds.voidsetCurrentDir(File dir)Changes the current default filesystem directory to the argument.booleansetLastHandlerTask(Future<?> handlerTask)When an handler execution occurs, multiple calls can be operated.voidsetResolveParameterValues(boolean resolve)Command argument or operation parameter values may contain system properties.voidsetSilent(boolean silent)Enables of disables the silent mode.voidsetVariable(String name, String value)Initializes a variable with the given name with the given value.voidterminateSession()Terminates the command line session.BatchedCommandtoBatchedCommand(String line)Builds an operation request from the passed in command line.
-
-
-
Method Detail
-
setLastHandlerTask
public boolean setLastHandlerTask(Future<?> handlerTask)
When an handler execution occurs, multiple calls can be operated. A reference to the last one (in progress) is stored in order to cancel it if a timeout occurs. Public for testing purpose.- Parameters:
handlerTask- The task to cancel if a timeout occurs.
-
getLastTask
public Future<?> getLastTask()
-
getConfig
public CliConfig getConfig()
Description copied from interface:CommandContextReturns the JBoss CLI configuration.- Specified by:
getConfigin interfaceCommandContext- Returns:
- CLI configuration
-
getArgumentsString
public String getArgumentsString()
Description copied from interface:CommandContextReturns the current command's arguments as a string.- Specified by:
getArgumentsStringin interfaceCommandContext- Returns:
- current command's arguments as a string or null if the command was entered w/o arguments.
-
getParsedCommandLine
public ParsedCommandLine getParsedCommandLine()
Description copied from interface:CommandContextParsed command line arguments.- Specified by:
getParsedCommandLinein interfaceCommandContext- Returns:
- parsed command line arguments.
-
printLine
public void printLine(String message)
Description copied from interface:CommandContextPrints a string to the CLI's output. Terminates the message by writing the line separator string.- Specified by:
printLinein interfaceCommandContext- Parameters:
message- the message to print
-
printColumns
public void printColumns(Collection<String> col)
Description copied from interface:CommandContextPrints a collection of strings as columns to the CLI's output.- Specified by:
printColumnsin interfaceCommandContext- Parameters:
col- the collection of strings to print as columns.
-
clearScreen
public void clearScreen()
Description copied from interface:CommandContextClears the screen.- Specified by:
clearScreenin interfaceCommandContext
-
terminateSession
public void terminateSession()
Description copied from interface:CommandContextTerminates the command line session. Also closes the connection to the controller if it's still open.- Specified by:
terminateSessionin interfaceCommandContext
-
isTerminated
public boolean isTerminated()
Description copied from interface:CommandContextChecks whether the session has been terminated.- Specified by:
isTerminatedin interfaceCommandContext- Returns:
-
set
public void set(CommandContext.Scope scope, String key, Object value)
Description copied from interface:CommandContextAssociates an object with key. The mapping is valid until this method is called with the same key value and null as the new value for this key.- Specified by:
setin interfaceCommandContext- Parameters:
scope- Entry duration scopekey- the keyvalue- the value to be associated with the key
-
get
public Object get(CommandContext.Scope scope, String key)
Description copied from interface:CommandContextReturns the value the key was associated with using the set(key, value) method above.- Specified by:
getin interfaceCommandContext- Parameters:
scope- Entry duration scopekey- the key to fetch the value for- Returns:
- the value associated with the key or null, if the key wasn't associated with any non-null value.
-
clear
public void clear(CommandContext.Scope scope)
Description copied from interface:CommandContextClear the content of a scope.- Specified by:
clearin interfaceCommandContext- Parameters:
scope- The scope to clear, can't be null.
-
remove
public Object remove(CommandContext.Scope scope, String key)
Description copied from interface:CommandContextRemoves the value the key was associated with using the set(key, value) method above. If the key isn't associated with any value, the method will return null.- Specified by:
removein interfaceCommandContext- Parameters:
scope- The entry duration scopekey- the key to be removed- Returns:
- the value associated with the key or null, if the key wasn't associated with any non-null value.
-
getModelControllerClient
public ModelControllerClient getModelControllerClient()
Description copied from interface:CommandContextReturns the model controller client or null if it hasn't been initialized.- Specified by:
getModelControllerClientin interfaceCommandContext- Returns:
- the model controller client or null if it hasn't been initialized.
-
connectController
public void connectController() throws CommandLineExceptionDescription copied from interface:CommandContextConnects the controller client using the default controller definition. The default controller will be identified as the default specified on starting the CLI will be used, if no controller was specified on start up then the default defined in the CLI configuration will be used, if no default is defined then a connection to remote+http://localhost:9990 will be used instead.- Specified by:
connectControllerin interfaceCommandContext- Throws:
CommandLineException- in case the attempt to connect failed
-
connectController
public void connectController(String controller, String client) throws CommandLineException
Description copied from interface:CommandContextConnects to the controller specified. If the controller is null then the default specified on starting the CLI will be used, if no controller was specified on start up then the default defined in the CLI configuration will be used, if no default is defined then a connection to remote+http://localhost:9990 will be used instead.- Specified by:
connectControllerin interfaceCommandContext- Parameters:
controller- the controller to connect toclient- the address the client will bind to- Throws:
CommandLineException- in case the attempt to connect failed
-
connectController
public void connectController(String controller) throws CommandLineException
Description copied from interface:CommandContextConnects to the controller specified. If the controller is null then the default specified on starting the CLI will be used, if no controller was specified on start up then the default defined in the CLI configuration will be used, if no default is defined then a connection to remote+http://localhost:9990 will be used instead.- Specified by:
connectControllerin interfaceCommandContext- Parameters:
controller- the controller to connect to- Throws:
CommandLineException- in case the attempt to connect failed
-
connectController
public void connectController(String host, int port) throws CommandLineException
Description copied from interface:CommandContextConnects the controller client using the host and the port. If the host is null, the default controller host will be used, which is localhost. If the port is less than zero, the default controller port will be used, which is 9999.- Specified by:
connectControllerin interfaceCommandContext- Parameters:
host- the host to connect withport- the port to connect on- Throws:
CommandLineException- in case the attempt to connect failed
-
bindClient
public void bindClient(ModelControllerClient newClient)
Description copied from interface:CommandContextBind the controller to an existing, connected client.- Specified by:
bindClientin interfaceCommandContext
-
disconnectController
public void disconnectController()
Description copied from interface:CommandContextCloses the previously established connection with the controller client. If the connection hasn't been established, the method silently returns.- Specified by:
disconnectControllerin interfaceCommandContext
-
getDefaultControllerHost
public String getDefaultControllerHost()
Description copied from interface:CommandContextReturns the default host the controller client will be connected to.- Specified by:
getDefaultControllerHostin interfaceCommandContext- Returns:
- the default host the controller client will be connected to.
-
getDefaultControllerPort
public int getDefaultControllerPort()
Description copied from interface:CommandContextReturns the default port the controller client will be connected to.- Specified by:
getDefaultControllerPortin interfaceCommandContext- Returns:
- the default port the controller client will be connected to.
-
getDefaultControllerAddress
public ControllerAddress getDefaultControllerAddress()
Description copied from interface:CommandContextThe default address of the default controller to connect to.- Specified by:
getDefaultControllerAddressin interfaceCommandContext- Returns:
- The default address.
-
getControllerHost
public String getControllerHost()
Description copied from interface:CommandContextReturns the host the controller client is connected to or null if the connection hasn't been established yet.- Specified by:
getControllerHostin interfaceCommandContext- Returns:
- the host the controller client is connected to or null if the connection hasn't been established yet.
-
getControllerPort
public int getControllerPort()
Description copied from interface:CommandContextReturns the port the controller client is connected to.- Specified by:
getControllerPortin interfaceCommandContext- Returns:
- the port the controller client is connected to.
-
getCommandLineParser
public CommandLineParser getCommandLineParser()
Description copied from interface:CommandContextReturns the current operation request parser.- Specified by:
getCommandLineParserin interfaceCommandContext- Returns:
- current operation request parser.
-
getCurrentNodePath
public OperationRequestAddress getCurrentNodePath()
Description copied from interface:CommandContextReturns the current prefix.- Specified by:
getCurrentNodePathin interfaceCommandContext- Returns:
- current prefix
-
getNodePathFormatter
public NodePathFormatter getNodePathFormatter()
Description copied from interface:CommandContextReturns the prefix formatter.- Specified by:
getNodePathFormatterin interfaceCommandContext- Returns:
- the prefix formatter.
-
getOperationCandidatesProvider
public OperationCandidatesProvider getOperationCandidatesProvider()
Description copied from interface:CommandContextReturns the provider of operation request candidates for tab-completion.- Specified by:
getOperationCandidatesProviderin interfaceCommandContext- Returns:
- provider of operation request candidates for tab-completion.
-
getHistory
public CommandHistory getHistory()
Description copied from interface:CommandContextReturns the history of all the commands and operations.- Specified by:
getHistoryin interfaceCommandContext- Returns:
- the history of all the commands and operations.
-
isBatchMode
public boolean isBatchMode()
Description copied from interface:CommandContextChecks whether the CLI is in the batch mode.- Specified by:
isBatchModein interfaceCommandContext- Returns:
- true if the CLI is in the batch mode, false - otherwise.
-
isWorkflowMode
public boolean isWorkflowMode()
Description copied from interface:CommandContextChecks whether the CLI is in a workflow mode.- Specified by:
isWorkflowModein interfaceCommandContext- Returns:
- true if the CLI is in a workflow mode, false - otherwise.
-
getBatchManager
public BatchManager getBatchManager()
Description copied from interface:CommandContextReturns batch manager.- Specified by:
getBatchManagerin interfaceCommandContext- Returns:
- batch manager
-
toBatchedCommand
public BatchedCommand toBatchedCommand(String line) throws CommandFormatException
Description copied from interface:CommandContextBuilds an operation request from the passed in command line. If the line contains a command, the command must supported the batch mode, otherwise an exception will thrown.- Specified by:
toBatchedCommandin interfaceCommandContext- Parameters:
line- the command line which can be an operation request or a command that can be translated into an operation request.- Returns:
- the operation request
- Throws:
CommandFormatException- if the operation request couldn't be built.
-
buildRequest
public org.jboss.dmr.ModelNode buildRequest(String line) throws CommandFormatException
Description copied from interface:CommandContextBuilds a DMR request corresponding to the command or the operation. If the line contains a command, the corresponding command handler must implement org.jboss.cli.OperationCommand interface, in other words the command must translate into an operation request, otherwise an exception will be thrown.- Specified by:
buildRequestin interfaceCommandContext- Parameters:
line- command or an operation to build a DMR request for- Returns:
- DMR request corresponding to the line
- Throws:
CommandFormatException- thrown in case the line couldn't be translated into a DMR request
-
getDefaultCommandCompleter
public CommandLineCompleter getDefaultCommandCompleter()
Description copied from interface:CommandContextReturns the default command line completer.- Specified by:
getDefaultCommandCompleterin interfaceCommandContext- Returns:
- the default command line completer.
-
isDomainMode
public boolean isDomainMode()
Description copied from interface:CommandContextIndicates whether the CLI is in the domain mode or standalone one (assuming established connection to the controller).- Specified by:
isDomainModein interfaceCommandContext- Returns:
- true if the CLI is connected to the domain controller, otherwise false.
-
addEventListener
public void addEventListener(CliEventListener listener)
Description copied from interface:CommandContextAdds a listener for CLI events.- Specified by:
addEventListenerin interfaceCommandContext- Parameters:
listener- the listener
-
getExitCode
public int getExitCode()
Description copied from interface:CommandContextReturns value that should be used as the exit code of the JVM process.- Specified by:
getExitCodein interfaceCommandContext- Returns:
- JVM exit code
-
handle
public void handle(String line) throws CommandLineException
Description copied from interface:CommandContextExecutes a command or an operation. Or, if the context is in the batch mode and the command is allowed in the batch, adds the command (or the operation) to the currently active batch. NOTE: errors are not handled by this method, they won't affect the exit code or even be logged. Error handling is the responsibility of the caller.- Specified by:
handlein interfaceCommandContext- Parameters:
line- command or operation to handle- Throws:
CommandFormatException- in case there was an error handling the command or operationCommandLineException
-
handleSafe
public void handleSafe(String line)
Description copied from interface:CommandContextExecutes a command or an operation. Or, if the context is in the batch mode and the command is allowed in the batch, adds the command (or the operation) to the currently active batch. NOTE: unlike handle(String line), this method catches CommandLineException exceptions thrown by command handlers, logs them and sets the exit code status to indicate that the command or the operation has failed. It's up to the caller to check the exit code with getExitCode() to find out whether the command or the operation succeeded or failed.- Specified by:
handleSafein interfaceCommandContext- Parameters:
line- command or operation to handle
-
interact
public void interact()
Description copied from interface:CommandContextThis method will start an interactive session. It requires an initialized at the construction time console.- Specified by:
interactin interfaceCommandContext
-
getCurrentDir
public File getCurrentDir()
Description copied from interface:CommandContextReturns current default filesystem directory.- Specified by:
getCurrentDirin interfaceCommandContext- Returns:
- current default filesystem directory.
-
setCurrentDir
public void setCurrentDir(File dir)
Description copied from interface:CommandContextChanges the current default filesystem directory to the argument.- Specified by:
setCurrentDirin interfaceCommandContext- Parameters:
dir- the new default directory
-
isResolveParameterValues
public boolean isResolveParameterValues()
Description copied from interface:CommandContextCommand argument or operation parameter values may contain system properties. If this method returns true then the CLI will try to resolve the system properties before sending the operation request to the controller. Otherwise, the resolution will happen on the server side.- Specified by:
isResolveParameterValuesin interfaceCommandContext- Returns:
- true if system properties in the operation parameter values should be resolved by the CLI before the request is sent to the controller, false if system properties should be resolved on the server side.
-
setResolveParameterValues
public void setResolveParameterValues(boolean resolve)
Description copied from interface:CommandContextCommand argument or operation parameter values may contain system properties. If this property is set to true then the CLI will try to resolve the system properties before sending the operation request to the controller. Otherwise, the resolution will happen on the server side.- Specified by:
setResolveParameterValuesin interfaceCommandContext- Parameters:
resolve- true if system properties in the operation parameter values should be resolved by the CLI before the request is sent to the controller, false if system properties should be resolved on the server side.
-
isSilent
public boolean isSilent()
Description copied from interface:CommandContextWhether the info or error messages should be written to the terminal output. The output of the info and error messages is done in the following way: 1) the message is always logged using a logger (which is disabled in the config by default); 2) if the output target was specified on the command line using '>' it would be used; 3) if the output target was not specified, whether the message is written or not to the terminal output will depend on whether it's a silent mode or not.- Specified by:
isSilentin interfaceCommandContext- Returns:
- true if the CLI is in the silent mode, i.e. not writing info and error messages to the terminal output, otherwise - false.
-
setSilent
public void setSilent(boolean silent)
Description copied from interface:CommandContextEnables of disables the silent mode.- Specified by:
setSilentin interfaceCommandContext- Parameters:
silent- true if the CLI should go into the silent mode, false if the CLI should resume writing info and error messages to the terminal output.
-
getTerminalWidth
public int getTerminalWidth()
Description copied from interface:CommandContextReturns the current terminal window width in case the console has been initialized. Otherwise -1.- Specified by:
getTerminalWidthin interfaceCommandContext- Returns:
- current terminal with if the console has been initialized, -1 otherwise
-
getTerminalHeight
public int getTerminalHeight()
Description copied from interface:CommandContextReturns the current terminal window height in case the console has been initialized. Otherwise -1.- Specified by:
getTerminalHeightin interfaceCommandContext- Returns:
- current terminal height if the console has been initialized, -1 otherwise
-
setVariable
public void setVariable(String name, String value) throws CommandLineException
Description copied from interface:CommandContextInitializes a variable with the given name with the given value. The name of the variable must follow the rules for Java identifiers but not contain '$' character. If the variable already exists, its value will be silently overridden. Passing in null as the value will remove the variable altogether. If the variable with the given name has not been defined and the value passed in is null, the method will return silently.- Specified by:
setVariablein interfaceCommandContext- Parameters:
name- name of the variablevalue- value for the variable- Throws:
CommandLineException- in case the name contains illegal characters
-
getVariable
public String getVariable(String name)
Description copied from interface:CommandContextReturns the value for the variable. If the variable has not been defined the method will return null.- Specified by:
getVariablein interfaceCommandContext- Parameters:
name- name of the variable- Returns:
- the value of the variable or null if the variable has not been defined
-
getVariables
public Collection<String> getVariables()
Description copied from interface:CommandContextReturns a collection of all the defined variable names. If there no variables defined, an empty collection will be returned.- Specified by:
getVariablesin interfaceCommandContext- Returns:
- collection of all the defined variable names or an empty collection if no variables has been defined
-
registerRedirection
public void registerRedirection(CommandLineRedirection redirection) throws CommandLineException
Description copied from interface:CommandContextAfter this method returns command line handling will be redirected to the passed in CommandLineRedirection instance.- Specified by:
registerRedirectionin interfaceCommandContext- Parameters:
redirection- command line redirection handler- Throws:
CommandLineException- in case registration fails (e.g. in case one has already been registered
-
getConnectionInfo
public ConnectionInfo getConnectionInfo()
Description copied from interface:CommandContextThe ConnectionInfo bean is set after the connection is established to the server.- Specified by:
getConnectionInfoin interfaceCommandContext- Returns:
- information about the current connection to the server.
-
captureOutput
public void captureOutput(PrintStream captor)
Description copied from interface:CommandContextRedirect output to the given print stream.- Specified by:
captureOutputin interfaceCommandContext- Parameters:
captor- stream to which output should be written. Cannot benull
-
releaseOutput
public void releaseOutput()
Description copied from interface:CommandContextStops redirecting output to the stream passed toCommandContext.captureOutput(java.io.PrintStream).- Specified by:
releaseOutputin interfaceCommandContext
-
setCommandTimeout
public void setCommandTimeout(int numSeconds)
Description copied from interface:CommandContextSet the command timeout to a number of seconds. Value equals to 0 means no timeout.- Specified by:
setCommandTimeoutin interfaceCommandContext- Parameters:
numSeconds- The timeout value.
-
getCommandTimeout
public int getCommandTimeout()
Description copied from interface:CommandContextReturns the command execution timeout value. Value equals to 0 means no timeout.- Specified by:
getCommandTimeoutin interfaceCommandContext- Returns:
- The timeout value.
-
resetTimeout
public void resetTimeout(CommandContext.TIMEOUT_RESET_VALUE value)
Description copied from interface:CommandContextReset the timeout value.- Specified by:
resetTimeoutin interfaceCommandContext- Parameters:
value- The enumerated timeout reset value.
-
execute
public org.jboss.dmr.ModelNode execute(org.jboss.dmr.ModelNode mn, String description) throws CommandLineException, IOExceptionDescription copied from interface:CommandContextExecute an operation. This call is guarded by the command timeout.- Specified by:
executein interfaceCommandContext- Parameters:
mn- The operation.description- Operation description, used in exception message.- Returns:
- The response.
- Throws:
CommandLineException- If an exception occurs.IOException- If an IOException occurs.
-
execute
public org.jboss.dmr.ModelNode execute(Operation op, String description) throws CommandLineException, IOException
Description copied from interface:CommandContextExecute an operation. This call is guarded by the command timeout.- Specified by:
executein interfaceCommandContext- Parameters:
op- The operation.description- Operation description, used in exception message.- Returns:
- The response.
- Throws:
CommandLineException- If an exception occurs.IOException- If an IOException occurs.
-
-