public class CommandContextImpl extends Object implements CommandContext, ModelControllerClientFactory.ConnectionCloseHandler
CommandContext.Scope, CommandContext.TIMEOUT_RESET_VALUE| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(CliEventListener listener)
Adds a listener for CLI events.
|
protected void |
addShutdownHook() |
void |
bindClient(ModelControllerClient newClient)
Bind the controller to an existing, connected client.
|
OperationCommand.HandledRequest |
buildAeshCommandRequest(ParsedCommandLine parsedCmd,
boolean batchMode) |
org.jboss.dmr.ModelNode |
buildRequest(String line)
Builds a DMR request corresponding to the command or the operation.
|
protected OperationCommand.HandledRequest |
buildRequest(String line,
boolean batchMode) |
void |
captureOutput(PrintStream captor)
Redirect output to the given print stream.
|
void |
clear(CommandContext.Scope scope)
Clear the content of a scope.
|
void |
clearScreen()
Clears the screen.
|
void |
connectController()
Connects the controller client using the default controller definition.
|
void |
connectController(String controller)
Connects to the controller specified.
|
void |
connectController(String host,
int port)
Deprecated.
|
void |
connectController(String controller,
String clientAddress)
Connects to the controller specified.
|
void |
disconnectController()
Closes the previously established connection with the controller client.
|
protected void |
error(String message)
Set the exit code of the process to indicate an error and output the error message.
|
org.jboss.dmr.ModelNode |
execute(org.jboss.dmr.ModelNode mn,
String description)
Execute an operation.
|
org.jboss.dmr.ModelNode |
execute(Operation mn,
String description)
Execute an operation.
|
Object |
get(CommandContext.Scope scope,
String key)
Returns the value the key was associated with using the set(key, value) method above.
|
AeshCommands |
getAeshCommands() |
String |
getArgumentsString()
Returns the current command's arguments as a string.
|
BatchManager |
getBatchManager()
Returns batch manager.
|
CommandLineParser |
getCommandLineParser()
Returns the current operation request parser.
|
int |
getCommandTimeout()
Returns the command execution timeout value.
|
CliConfig |
getConfig()
Returns the JBoss CLI configuration.
|
ConnectionInfo |
getConnectionInfo()
The ConnectionInfo bean is set after the connection is established to the server.
|
ReadlineConsole |
getConsole()
Public for testing purpose only.
|
String |
getControllerHost()
Returns the host the controller client is connected to or
null if the connection hasn't been established yet.
|
int |
getControllerPort()
Returns the port the controller client is connected to.
|
File |
getCurrentDir()
Returns current default filesystem directory.
|
OperationRequestAddress |
getCurrentNodePath()
Returns the current prefix.
|
CommandLineCompleter |
getDefaultCommandCompleter()
Returns the default command line completer.
|
ControllerAddress |
getDefaultControllerAddress()
The default address of the default controller to connect to.
|
String |
getDefaultControllerHost()
Deprecated.
|
int |
getDefaultControllerPort()
Deprecated.
|
int |
getExitCode()
Returns value that should be used as the exit code of the JVM process.
|
CommandHistory |
getHistory()
Returns the history of all the commands and operations.
|
CLICommandCompleter.Completer |
getLegacyCommandCompleter() |
ModelControllerClient |
getModelControllerClient()
Returns the model controller client or null if it hasn't been initialized.
|
NodePathFormatter |
getNodePathFormatter()
Returns the prefix formatter.
|
OperationCandidatesProvider |
getOperationCandidatesProvider()
Returns the provider of operation request candidates for tab-completion.
|
ParsedCommandLine |
getParsedCommandLine()
Parsed command line arguments.
|
int |
getTerminalHeight()
Returns the current terminal window height in case the console
has been initialized.
|
int |
getTerminalWidth()
Returns the current terminal window width in case the console
has been initialized.
|
String |
getVariable(String name)
Returns the value for the variable.
|
Collection<String> |
getVariables()
Returns a collection of all the defined variable names.
|
void |
handle(String line)
Executes a command or an operation.
|
void |
handleClose() |
void |
handleSafe(String line)
Executes a command or an operation.
|
protected void |
initBasicConsole(InputStream consoleInput) |
protected void |
initBasicConsole(InputStream consoleInput,
boolean start) |
int[] |
input() |
String |
input(org.aesh.readline.Prompt prompt) |
String |
input(String prompt,
boolean password) |
void |
interact()
This method will start an interactive session.
|
protected void |
interactionDisabled() |
boolean |
isBatchMode()
Checks whether the CLI is in the batch mode.
|
boolean |
isColorOutput() |
boolean |
isDomainMode()
Indicates whether the CLI is in the domain mode or standalone one (assuming established
connection to the controller).
|
boolean |
isResolveParameterValues()
Command argument or operation parameter values may contain system properties.
|
boolean |
isSilent()
Whether the info or error messages should be written to the terminal output.
|
boolean |
isTerminated()
Checks whether the session has been terminated.
|
boolean |
isWorkflowMode()
Checks whether the CLI is in a workflow mode.
|
CommandContext |
newTimeoutCommandContext() |
protected void |
notifyListeners(CliEvent event) |
void |
print(String message)
Prints a string to the CLI's output.
|
void |
print(String message,
boolean newLine,
boolean collect) |
void |
printColumns(Collection<String> col)
Prints a collection of strings as columns to the CLI's output.
|
void |
printDMR(org.jboss.dmr.ModelNode node,
boolean compact)
Prints a ModelNode according to the current configuration.
|
void |
printLine(String message)
Prints a string to the CLI's output.
|
void |
printLine(String message,
String outcome) |
void |
registerRedirection(CommandLineRedirection redirection)
After this method returns command line handling will be redirected to
the passed in CommandLineRedirection instance.
|
void |
releaseOutput()
Stops redirecting output to the stream passed to
CommandContext.captureOutput(java.io.PrintStream). |
Object |
remove(CommandContext.Scope scope,
String key)
Removes the value the key was associated with using the set(key, value) method above.
|
void |
resetTimeout(CommandContext.TIMEOUT_RESET_VALUE value)
Reset the timeout value.
|
void |
set(CommandContext.Scope scope,
String key,
Object value)
Associates an object with key.
|
void |
setCommandTimeout(int numSeconds)
Set the command timeout to a number of seconds.
|
void |
setCurrentDir(File dir)
Changes the current default filesystem directory to the argument.
|
void |
setResolveParameterValues(boolean resolve)
Command argument or operation parameter values may contain system properties.
|
void |
setSilent(boolean silent)
Enables of disables the silent mode.
|
void |
setVariable(String name,
String value)
Initializes a variable with the given name with the given value.
|
void |
terminateSession()
Terminates the command line session.
|
BatchedCommand |
toBatchedCommand(String line)
Builds an operation request from the passed in command line.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitget, printDMR, remove, setprotected void addShutdownHook()
protected void initBasicConsole(InputStream consoleInput) throws CliInitializationException
CliInitializationExceptionprotected void initBasicConsole(InputStream consoleInput, boolean start) throws CliInitializationException
CliInitializationExceptionpublic int getExitCode()
CommandContextgetExitCode in interface CommandContextpublic boolean isTerminated()
CommandContextisTerminated in interface CommandContextpublic void handle(String line) throws CommandLineException
CommandContexthandle in interface CommandContextline - command or operation to handleCommandFormatException - in case there was an error handling the command or operationCommandLineExceptionpublic org.jboss.dmr.ModelNode execute(Operation mn, String description) throws CommandLineException, IOException
CommandContextexecute in interface CommandContextmn - The operation.description - Operation description, used in exception message.CommandLineException - If an exception occurs.IOException - If an IOException occurs.public org.jboss.dmr.ModelNode execute(org.jboss.dmr.ModelNode mn,
String description)
throws CommandLineException,
IOException
CommandContextexecute in interface CommandContextmn - The operation.description - Operation description, used in exception message.CommandLineException - If an exception occurs.IOException - If an IOException occurs.public void handleSafe(String line)
CommandContexthandleSafe in interface CommandContextline - command or operation to handlepublic String getArgumentsString()
CommandContextgetArgumentsString in interface CommandContextpublic void terminateSession()
CommandContextterminateSession in interface CommandContextpublic void print(String message, boolean newLine, boolean collect)
public void printDMR(org.jboss.dmr.ModelNode node,
boolean compact)
CommandContextprintDMR in interface CommandContextnode - The ModelNode to print.compact - true for content displayed onto a single line.public final boolean isColorOutput()
public void printLine(String message)
CommandContextprintLine in interface CommandContextmessage - the message to printpublic void print(String message)
CommandContextprint in interface CommandContextmessage - the message to printprotected void error(String message)
message - The message to display.public String input(String prompt, boolean password) throws CommandLineException, InterruptedException, IOException
public String input(org.aesh.readline.Prompt prompt) throws CommandLineException, InterruptedException, IOException
public int[] input()
throws CommandLineException,
InterruptedException,
IOException
protected void interactionDisabled()
throws CommandLineException
CommandLineExceptionpublic void printColumns(Collection<String> col)
CommandContextprintColumns in interface CommandContextcol - the collection of strings to print as columns.public void set(CommandContext.Scope scope, String key, Object value)
CommandContextset in interface CommandContextscope - Entry duration scopekey - the keyvalue - the value to be associated with the keypublic Object get(CommandContext.Scope scope, String key)
CommandContextget in interface CommandContextscope - Entry duration scopekey - the key to fetch the value forpublic void clear(CommandContext.Scope scope)
CommandContextclear in interface CommandContextscope - The scope to clear, can't be null.public Object remove(CommandContext.Scope scope, String key)
CommandContextremove in interface CommandContextscope - The entry duration scopekey - the key to be removedpublic ModelControllerClient getModelControllerClient()
CommandContextgetModelControllerClient in interface CommandContextpublic CommandLineParser getCommandLineParser()
CommandContextgetCommandLineParser in interface CommandContextpublic OperationRequestAddress getCurrentNodePath()
CommandContextgetCurrentNodePath in interface CommandContextpublic NodePathFormatter getNodePathFormatter()
CommandContextgetNodePathFormatter in interface CommandContextpublic OperationCandidatesProvider getOperationCandidatesProvider()
CommandContextgetOperationCandidatesProvider in interface CommandContextpublic void connectController()
throws CommandLineException
CommandContextconnectController in interface CommandContextCommandLineException - in case the attempt to connect failedpublic void connectController(String controller) throws CommandLineException
CommandContextconnectController in interface CommandContextcontroller - the controller to connect toCommandLineException - in case the attempt to connect failedpublic void connectController(String controller, String clientAddress) throws CommandLineException
CommandContextconnectController in interface CommandContextcontroller - the controller to connect toclientAddress - the address the client will bind toCommandLineException - in case the attempt to connect failed@Deprecated public void connectController(String host, int port) throws CommandLineException
CommandContextconnectController in interface CommandContexthost - the host to connect withport - the port to connect onCommandLineException - in case the attempt to connect failedpublic void bindClient(ModelControllerClient newClient)
CommandContextbindClient in interface CommandContextpublic File getCurrentDir()
CommandContextgetCurrentDir in interface CommandContextpublic void setCurrentDir(File dir)
CommandContextsetCurrentDir in interface CommandContextdir - the new default directorypublic void registerRedirection(CommandLineRedirection redirection) throws CommandLineException
CommandContextregisterRedirection in interface CommandContextredirection - command line redirection handlerCommandLineException - in case registration fails (e.g. in case
one has already been registeredpublic void disconnectController()
CommandContextdisconnectController in interface CommandContext@Deprecated public String getDefaultControllerHost()
CommandContextgetDefaultControllerHost in interface CommandContext@Deprecated public int getDefaultControllerPort()
CommandContextgetDefaultControllerPort in interface CommandContextpublic ControllerAddress getDefaultControllerAddress()
CommandContextgetDefaultControllerAddress in interface CommandContextpublic String getControllerHost()
CommandContextgetControllerHost in interface CommandContextpublic int getControllerPort()
CommandContextgetControllerPort in interface CommandContextpublic void clearScreen()
CommandContextclearScreen in interface CommandContextpublic CommandHistory getHistory()
CommandContextgetHistory in interface CommandContextpublic boolean isBatchMode()
CommandContextisBatchMode in interface CommandContextpublic boolean isWorkflowMode()
CommandContextisWorkflowMode in interface CommandContextpublic BatchManager getBatchManager()
CommandContextgetBatchManager in interface CommandContextpublic BatchedCommand toBatchedCommand(String line) throws CommandFormatException
CommandContexttoBatchedCommand in interface CommandContextline - the command line which can be an operation request or a command that can be translated into an operation request.CommandFormatException - if the operation request couldn't be built.public org.jboss.dmr.ModelNode buildRequest(String line) throws CommandFormatException
CommandContextbuildRequest in interface CommandContextline - command or an operation to build a DMR request forCommandFormatException - thrown in case the line couldn't be
translated into a DMR requestprotected OperationCommand.HandledRequest buildRequest(String line, boolean batchMode) throws CommandFormatException
CommandFormatExceptionpublic OperationCommand.HandledRequest buildAeshCommandRequest(ParsedCommandLine parsedCmd, boolean batchMode) throws CommandFormatException
CommandFormatExceptionpublic CommandLineCompleter getDefaultCommandCompleter()
CommandContextgetDefaultCommandCompleter in interface CommandContextpublic ParsedCommandLine getParsedCommandLine()
CommandContextgetParsedCommandLine in interface CommandContextpublic boolean isDomainMode()
CommandContextisDomainMode in interface CommandContextpublic void addEventListener(CliEventListener listener)
CommandContextaddEventListener in interface CommandContextlistener - the listenerpublic CliConfig getConfig()
CommandContextgetConfig in interface CommandContextprotected void notifyListeners(CliEvent event)
public void interact()
CommandContextinteract in interface CommandContextpublic boolean isResolveParameterValues()
CommandContextisResolveParameterValues in interface CommandContextpublic void setResolveParameterValues(boolean resolve)
CommandContextsetResolveParameterValues in interface CommandContextresolve - 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.public void handleClose()
handleClose in interface ModelControllerClientFactory.ConnectionCloseHandlerpublic boolean isSilent()
CommandContextisSilent in interface CommandContextpublic void setSilent(boolean silent)
CommandContextsetSilent in interface CommandContextsilent - 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.public int getTerminalWidth()
CommandContextgetTerminalWidth in interface CommandContextpublic int getTerminalHeight()
CommandContextgetTerminalHeight in interface CommandContextpublic void setVariable(String name, String value) throws CommandLineException
CommandContextsetVariable in interface CommandContextname - name of the variablevalue - value for the variableCommandLineException - in case the name contains illegal characterspublic String getVariable(String name)
CommandContextgetVariable in interface CommandContextname - name of the variablepublic Collection<String> getVariables()
CommandContextgetVariables in interface CommandContextpublic ConnectionInfo getConnectionInfo()
CommandContextgetConnectionInfo in interface CommandContextpublic void captureOutput(PrintStream captor)
CommandContextcaptureOutput in interface CommandContextcaptor - stream to which output should be written. Cannot be nullpublic void releaseOutput()
CommandContextCommandContext.captureOutput(java.io.PrintStream).releaseOutput in interface CommandContextpublic final void setCommandTimeout(int numSeconds)
CommandContextsetCommandTimeout in interface CommandContextnumSeconds - The timeout value.public final int getCommandTimeout()
CommandContextgetCommandTimeout in interface CommandContextpublic final void resetTimeout(CommandContext.TIMEOUT_RESET_VALUE value)
CommandContextresetTimeout in interface CommandContextvalue - The enumerated timeout reset value.public ReadlineConsole getConsole()
public AeshCommands getAeshCommands()
public CLICommandCompleter.Completer getLegacyCommandCompleter()
public CommandContext newTimeoutCommandContext()
Copyright © 2018 JBoss by Red Hat. All rights reserved.