IRunUtil

public interface IRunUtil

com.android.tradefed.util.IRunUtil


用于运行定时操作和系统命令的接口。

概括

嵌套类

interface IRunUtil.IRunnableResult

用于异步执行返回布尔状态的操作的接口。

公共方法

abstract void allowInterrupt (boolean allow)

允许/禁止在当前线程上运行中断。

abstract void interrupt (Thread thread, String message, ErrorIdentifier errorId)

中断给定线程上正在进行的/即将进行的运行操作。

abstract void interrupt (Thread thread, String message)

中断给定线程上正在进行的/即将进行的运行操作。

abstract boolean isInterruptAllowed ()

给出 RunUtil 的中断状态。

abstract Process runCmdInBackground (Redirect redirect, command) runCmdInBackground (Redirect redirect, command)

另一种runCmdInBackground(String)方法接受ERROR(/List)形式的命令参数。

abstract Process runCmdInBackground ( command) runCmdInBackground ( command)

另一种runCmdInBackground(String)方法接受ERROR(/List)形式的命令参数。

abstract Process runCmdInBackground ( command, OutputStream output) runCmdInBackground ( command, OutputStream output)

运行带有ERROR(/OutputStream)的命令会记录命令的输出。

abstract Process runCmdInBackground (String... command)

异步执行系统命令的辅助方法。

abstract Process runCmdInBackground (Redirect redirect, String... command)

异步执行系统命令的辅助方法。

abstract boolean runEscalatingTimedRetry (long opTimeout, long initialPollInterval, long maxPollInterval, long maxTime, IRunUtil.IRunnableResult runnable)

多次阻塞并执行一个操作,直到成功。

abstract boolean runFixedTimedRetry (long opTimeout, long pollInterval, long maxTime, IRunUtil.IRunnableResult runnable)

多次阻塞并执行一个操作,直到成功。

abstract CommandStatus runTimed (long timeout, IRunUtil.IRunnableResult runnable, boolean logErrors)

阻止并执行一个操作,如果它花费的时间超过指定时间则中止。

abstract CommandResult runTimedCmd (long timeout, OutputStream stdout, OutputStream stderr, String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止,如果指定则将输出重定向到文件。

abstract CommandResult runTimedCmd (long timeout, String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

abstract CommandResult runTimedCmdRetry (long timeout, long retryInterval, int attempts, String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

abstract CommandResult runTimedCmdSilently (long timeout, String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

abstract CommandResult runTimedCmdSilentlyRetry (long timeout, long retryInterval, int attempts, String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

abstract CommandResult runTimedCmdWithInput (long timeout, String input, File stdoutFile, File stderrFile, String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止,如果指定则将输出重定向到文件。

abstract CommandResult runTimedCmdWithInput (long timeout, String input, String... command)

执行需要 stdin 输入的系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

abstract CommandResult runTimedCmdWithInput (long timeout, String input, command) runTimedCmdWithInput (long timeout, String input, command)

执行需要 stdin 输入的系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

abstract CommandResult runTimedCmdWithInputRedirect (long timeout, File inputRedirect, String... command)

执行需要从文件重定向 Stdin 的系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

abstract boolean runTimedRetry (long opTimeout, long pollInterval, int attempts, IRunUtil.IRunnableResult runnable)

多次阻塞并执行一个操作,直到成功。

abstract void setEnvVariable (String key, String value)

设置运行系统命令时要使用的环境变量。

abstract void setEnvVariablePriority ( IRunUtil.EnvPriority priority)

决定在创建进程时,取消设置环境变量是否比设置它们具有更高的优先级。

abstract void setInterruptibleInFuture (Thread thread, long timeMs)

等待一段时间后设置为可中断。

abstract void setLinuxInterruptProcess (boolean interrupt)

允许在达到超时时通过 #runTimed 方法对运行的进程使用 linux 'kill' 中断。

abstract void setRedirectStderrToStdout (boolean redirect)

设置标准错误流,在运行系统命令时重定向到标准输出流。

abstract void setWorkingDir (File dir)

设置系统命令的工作目录。

abstract void sleep (long time)

在给定时间内休眠的辅助方法,忽略任何异常。

abstract void unsetEnvVariable (String key)

取消设置环境变量,因此系统命令在没有此环境变量的情况下运行。

公共方法

允许中断

public abstract void allowInterrupt (boolean allow)

允许/禁止在当前线程上运行中断。如果允许,则可以通过interrupt(Thread, String)方法从其他线程中断当前线程的运行操作。

参数
allow boolean : 是否允许在当前线程上运行中断。

打断

public abstract void interrupt (Thread thread, 
                String message, 
                ErrorIdentifier errorId)

中断给定线程上正在进行的/即将进行的运行操作。给定线程上的运行操作将抛出RunInterruptedException

参数
message StringRunInterruptedException的消息。

errorId ErrorIdentifier :表示已知的中断原因。

打断

public abstract void interrupt (Thread thread, 
                String message)

中断给定线程上正在进行的/即将进行的运行操作。给定线程上的运行操作将抛出RunInterruptedException

参数
message StringRunInterruptedException的消息。

允许中断

public abstract boolean isInterruptAllowed ()

给出 RunUtil 的中断状态。

退货
boolean如果可以中断运行,则为 true,否则为 false。

后台运行命令

public abstract Process runCmdInBackground (Redirect redirect, 
                 command)

另一种runCmdInBackground(String)方法接受ERROR(/List)形式的命令参数。

参数
redirect Redirect :将ERROR(/Redirect)应用于ERROR(/ProcessBuilder)

command : ERROR(/List)包含指定的系统命令和可选的 exec 参数

退货
Process执行命令的ERROR(/Process)

投掷
如果命令运行失败

后台运行命令

public abstract Process runCmdInBackground ( command)

另一种runCmdInBackground(String)方法接受ERROR(/List)形式的命令参数。

参数
command : ERROR(/List)包含指定的系统命令和可选的 exec 参数

退货
Process执行命令的ERROR(/Process)

投掷
如果命令运行失败

后台运行命令

public abstract Process runCmdInBackground ( command, 
                OutputStream output)

运行带有ERROR(/OutputStream)的命令会记录命令的输出。 Stdout 和 stderr 合并在一起。

参数
command : 要运行的命令

output OutputStream :保存输出的 OutputStream

退货
Process运行命令的ERROR(/Process)

投掷
异常

后台运行命令

public abstract Process runCmdInBackground (String... command)

异步执行系统命令的辅助方法。

启动命令后会立即返回。

参数
command String : 指定的系统命令和可选的 exec 参数

退货
Process执行命令的ERROR(/Process)

投掷
如果命令运行失败

后台运行命令

public abstract Process runCmdInBackground (Redirect redirect, 
                String... command)

异步执行系统命令的辅助方法。

启动命令后会立即返回。

参数
redirect Redirect :将ERROR(/Redirect)应用于ERROR(/ProcessBuilder)

command String : 指定的系统命令和可选的 exec 参数

退货
Process执行命令的ERROR(/Process)

投掷
如果命令运行失败

运行升级定时重试

public abstract boolean runEscalatingTimedRetry (long opTimeout, 
                long initialPollInterval, 
                long maxPollInterval, 
                long maxTime, 
                IRunUtil.IRunnableResult runnable)

多次阻塞并执行一个操作,直到成功。

以指数方式增加操作尝试之间的等待时间。这旨在在执行诸如轮询服务器之类的操作时使用,以便在服务器暂时关闭时为其提供时间恢复。

参数
opTimeout long :等待一次操作尝试的最长时间(以毫秒为单位)

initialPollInterval long :操作尝试之间等待的初始时间

maxPollInterval long :操作尝试之间等待的最长时间

maxTime long :继续尝试操作的总近似最长时间

runnable IRunUtil.IRunnableResult : 要执行的IRunUtil.IRunnableResult

退货
boolean如果操作在 maxTime 到期之前成功完成, true

运行固定时间重试

public abstract boolean runFixedTimedRetry (long opTimeout, 
                long pollInterval, 
                long maxTime, 
                IRunUtil.IRunnableResult runnable)

多次阻塞并执行一个操作,直到成功。

参数
opTimeout long :等待一次操作尝试的最长时间(以毫秒为单位)

pollInterval long :操作尝试之间等待的初始时间

maxTime long :继续尝试操作的总近似最长时间

runnable IRunUtil.IRunnableResult : 要执行的IRunUtil.IRunnableResult

退货
boolean如果操作在 maxTime 到期之前成功完成, true

定时运行

public abstract CommandStatus runTimed (long timeout, 
                IRunUtil.IRunnableResult runnable, 
                boolean logErrors)

阻止并执行一个操作,如果它花费的时间超过指定时间则中止。

参数
timeout long : 以毫秒为单位等待的最长时间

runnable IRunUtil.IRunnableResult : 要执行的IRunUtil.IRunnableResult

logErrors boolean : 是否记录异常错误。

退货
CommandStatus CommandStatus操作结果。

运行时命令

public abstract CommandResult runTimedCmd (long timeout, 
                OutputStream stdout, 
                OutputStream stderr, 
                String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止,如果指定则将输出重定向到文件。当以这种方式提供ERROR(/OutputStream)时,它们将在函数结束时保持打开状态。

参数
timeout long :超时等待的最长时间,以毫秒为单位。 0 表示没有超时。

stdout OutputStream : ERROR(/OutputStream)标准输出将被重定向。可以为空。

stderr OutputStream : ERROR(/OutputStream)错误输出将被重定向。可以为空。

command String : 指定的系统命令和可选的 exec 参数

退货
CommandResult包含命令运行结果的CommandResult

运行时命令

public abstract CommandResult runTimedCmd (long timeout, 
                String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

参数
timeout long :等待的最长时间,以毫秒为单位。 0 表示没有超时。

command String : 指定的系统命令和可选的 exec 参数

退货
CommandResult包含命令运行结果的CommandResult

runTimedCmdRetry

public abstract CommandResult runTimedCmdRetry (long timeout, 
                long retryInterval, 
                int attempts, 
                String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

参数
timeout long :每次尝试等待的最长时间(以毫秒为单位)

retryInterval long :命令重试之间的等待时间

attempts int : 最大尝试次数

command String : 指定的系统命令和可选的 exec 参数

退货
CommandResult包含命令运行结果的CommandResult

runTimedCmdSilently

public abstract CommandResult runTimedCmdSilently (long timeout, 
                String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止。类似于runTimedCmd(long, String) ,但不记录任何异常错误。

参数
timeout long : 以毫秒为单位等待的最长时间

command String : 指定的系统命令和可选的 exec 参数

退货
CommandResult包含命令运行结果的CommandResult

runTimedCmdSilentlyRetry

public abstract CommandResult runTimedCmdSilentlyRetry (long timeout, 
                long retryInterval, 
                int attempts, 
                String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止。类似于runTimedCmdRetry(long, long, int, String[]) ,但不记录任何异常错误。

参数
timeout long : 以毫秒为单位等待的最长时间

retryInterval long :命令重试之间的等待时间

attempts int : 最大尝试次数

command String : 指定的系统命令和可选的 exec 参数

退货
CommandResult包含命令运行结果的CommandResult

runTimedCmdWithInput

public abstract CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                File stdoutFile, 
                File stderrFile, 
                String... command)

执行系统命令的辅助方法,如果它花费的时间超过指定时间则中止,如果指定则将输出重定向到文件。

参数
timeout long :超时等待的最长时间,以毫秒为单位。 0 表示没有超时。

input String : 要传递给进程的标准输入

stdoutFile File : ERROR(/File) std 输出将被重定向到的位置。可以为空。

stderrFile File : ERROR(/File)错误输出将被重定向。可以为空。

command String : 指定的系统命令和可选的 exec 参数

退货
CommandResult包含命令运行结果的CommandResult

runTimedCmdWithInput

public abstract CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                String... command)

执行需要 stdin 输入的系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

参数
timeout long : 以毫秒为单位等待的最长时间

input String : 要传递给进程的标准输入

command String : 指定的系统命令和可选的 exec 参数

退货
CommandResult包含命令运行结果的CommandResult

runTimedCmdWithInput

public abstract CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                 command)

执行需要 stdin 输入的系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

参数
timeout long : 以毫秒为单位等待的最长时间

input String : 要传递给进程的标准输入

command : ERROR(/List)包含系统命令和可选的 exec 参数

退货
CommandResult包含命令运行结果的CommandResult

runTimedCmdWithInputRedirect

public abstract CommandResult runTimedCmdWithInputRedirect (long timeout, 
                File inputRedirect, 
                String... command)

执行需要从文件重定向 Stdin 的系统命令的辅助方法,如果它花费的时间超过指定时间则中止。

参数
timeout long : 以毫秒为单位等待的最长时间

inputRedirect File :使用ERROR(/ProcessBuilder#redirectInput())ERROR(/File)重定向为标准输入。如果为 null,stdin 将不会被重定向。

command String : 指定的系统命令和可选的 exec 参数

退货
CommandResult包含命令运行结果的CommandResult

运行定时重试

public abstract boolean runTimedRetry (long opTimeout, 
                long pollInterval, 
                int attempts, 
                IRunUtil.IRunnableResult runnable)

多次阻塞并执行一个操作,直到成功。

参数
opTimeout long :等待一次操作尝试的最长时间(以毫秒为单位)

pollInterval long :命令重试之间的等待时间

attempts int : 最大尝试次数

runnable IRunUtil.IRunnableResult : 要执行的IRunUtil.IRunnableResult

退货
boolean如果操作在尝试次数达到之前成功完成, true

设置环境变量

public abstract void setEnvVariable (String key, 
                String value)

设置运行系统命令时要使用的环境变量。

参数
key String : 变量名

value String : 变量值

设置环境变量优先级

public abstract void setEnvVariablePriority (IRunUtil.EnvPriority priority)

决定在创建进程时,取消设置环境变量是否比设置它们具有更高的优先级。默认情况下,取消设置的优先级更高:这意味着如果尝试设置同名变量,则不会发生,因为变量将被取消设置。不能在默认的IRunUtil实例上使用。

参数
priority IRunUtil.EnvPriority

setInterruptibleInFuture

public abstract void setInterruptibleInFuture (Thread thread, 
                long timeMs)

等待一段时间后设置为可中断。 ERROR(/CommandScheduler#shutdownHard())强制我们最终终止。

参数
thread Thread :将变为可中断的线程。

timeMs long :设置可中断之前等待的时间。

setLinuxInterruptProcess

public abstract void setLinuxInterruptProcess (boolean interrupt)

允许在达到超时时通过 #runTimed 方法对运行的进程使用 linux 'kill' 中断。不能在默认的IRunUtil实例上使用。

参数
interrupt boolean

setRedirectStderrToStdout

public abstract void setRedirectStderrToStdout (boolean redirect)

设置标准错误流,在运行系统命令时重定向到标准输出流。初始值为假。

参数
redirect boolean : 是否重定向的新值

设置工作目录

public abstract void setWorkingDir (File dir)

设置系统命令的工作目录。

参数
dir File :工作目录

睡觉

public abstract void sleep (long time)

在给定时间内休眠的辅助方法,忽略任何异常。

参数
time long : 女士睡觉。小于或等于 0 的值将被忽略

取消环境变量

public abstract void unsetEnvVariable (String key)

取消设置环境变量,因此系统命令在没有此环境变量的情况下运行。

参数
key String : 变量名