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 : 變量名