RunUtil

public class RunUtil
extends Object implements IRunUtil

java.lang.Object
com.android.tradefed.util.RunUtil


操作を実行するためのヘルパー メソッドのコレクション。

まとめ

田畑

public static final String INHERITIO_PREFIX

public static final String RUNNABLE_NOTIFIER_NAME

パブリック コンストラクター

RunUtil ()

使用する新しいRunUtilオブジェクトを作成します。

公開メソッド

void allowInterrupt (boolean allow)

現在のスレッドで実行割り込みを許可/禁止します。

static IRunUtil getDefault ()

デフォルトのRunUtilオブジェクトへの参照を取得します。

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

指定されたスレッドで進行中/今後の実行操作を中断します。

void interrupt (Thread thread, String message)

指定されたスレッドで進行中/今後の実行操作を中断します。

boolean isInterruptAllowed ()

RunUtil の割り込みステータスを指定します。

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

コマンド引数をERROR(/List)形式で受け取る代替のrunCmdInBackground(String)メソッド。

Process runCmdInBackground ( command) runCmdInBackground ( command)

コマンド引数をERROR(/List)形式で受け取る代替のrunCmdInBackground(String)メソッド。

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

ERROR(/OutputStream)を指定してコマンドを実行すると、コマンドの出力がログに記録されます。

Process runCmdInBackground (String... command)

システム コマンドを非同期で実行するためのヘルパー メソッド。

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

システム コマンドを非同期で実行するためのヘルパー メソッド。

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

成功するまで操作をブロックして複数回実行します。

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

成功するまで操作をブロックして複数回実行します。

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

操作をブロックして実行し、指定された時間より長くかかる場合は中止します。

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

システム コマンドを実行し、指定された時間より長くかかる場合は中止し、指定されている場合は出力をファイルにリダイレクトするヘルパー メソッド。

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

システム コマンドを実行するためのヘルパー メソッドと、指定された時間より長くかかる場合の中止。

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

システム コマンドを実行するためのヘルパー メソッドと、指定された時間より長くかかる場合の中止。

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

システム コマンドを実行するためのヘルパー メソッドと、指定された時間より長くかかる場合の中止。

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

システム コマンドを実行するためのヘルパー メソッドと、指定された時間より長くかかる場合の中止。

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

システム コマンドを実行し、指定された時間より長くかかる場合は中止し、指定されている場合は出力をファイルにリダイレクトするヘルパー メソッド。

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

stdin 入力を必要とするシステム コマンドを実行し、指定された時間よりも時間がかかる場合は中止するためのヘルパー メソッド。

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

stdin 入力を必要とするシステム コマンドを実行し、指定された時間よりも時間がかかる場合は中止するためのヘルパー メソッド。

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

ファイルから Stdin をリダイレクトし、指定された時間より長くかかる場合は中止する必要があるシステム コマンドを実行するためのヘルパー メソッド。

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

成功するまで操作をブロックして複数回実行します。

void setEnvVariable (String name, String value)

システム コマンドの実行時に使用する環境変数を設定します。

void setEnvVariablePriority ( IRunUtil.EnvPriority priority)

プロセスの作成時に、環境変数の設定よりも設定の解除を優先するかどうかを決定します。

void setInterruptibleInFuture (Thread thread, long timeMs)

しばらく待った後、割り込み可能として設定します。

void setLinuxInterruptProcess (boolean interrupt)

#runTimed メソッドを介して実行中のプロセスがタイムアウトに達したときに、Linux の「kill」割り込みを使用できるようにします。

void setRedirectStderrToStdout (boolean redirect)

システム コマンドの実行時に、標準エラー ストリームを標準出力ストリームにリダイレクトするように設定します。

void setWorkingDir (File dir)

システム コマンドの作業ディレクトリを設定します。

void sleep (long time)

例外を無視して、指定された時間だけスリープするヘルパー メソッド。

void unsetEnvVariable (String key)

環境変数を設定解除して、システム コマンドがこの環境変数なしで実行されるようにします。環境変数は親プロセスから継承される可能性があるため、 ERROR(/ProcessBuilder#environment())から環境変数を削除する必要があります。

田畑

INHERITIO_PREFIX

public static final String INHERITIO_PREFIX

RUNNABLE_NOTIFIER_NAME

public static final String RUNNABLE_NOTIFIER_NAME

パブリック コンストラクター

RunUtil

public RunUtil ()

使用する新しいRunUtilオブジェクトを作成します。

公開メソッド

許可割り込み

public void allowInterrupt (boolean allow)

現在のスレッドで実行割り込みを許可/禁止します。許可されている場合、現在のスレッドの実行操作はinterrupt(Thread, String)メソッドを介して他のスレッドから中断できます。

パラメーター
allow boolean : 現在のスレッドで実行割り込みを許可するかどうか。

getDefault

public static IRunUtil getDefault ()

デフォルトのRunUtilオブジェクトへの参照を取得します。

これは、カスタマイズせずに IRunUtil を使用したい呼び出し元にとって便利です。カスタム IRunUtil インスタンスを必要とする (つまり、 setEnvVariable(String, String)またはsetWorkingDir(File)のいずれかを呼び出す必要がある) 呼び出し元は、独自のコピーを作成することをお勧めします。

戻り値
IRunUtil

割り込み

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

指定されたスレッドで進行中/今後の実行操作を中断します。指定されたスレッドで実行操作を行うと、 RunInterruptedExceptionがスローされます。

パラメーター
message String : RunInterruptedExceptionのメッセージ。

errorId ErrorIdentifier : 既知の場合に中断の原因を表します。

割り込み

public void interrupt (Thread thread, 
                String message)

指定されたスレッドで進行中/今後の実行操作を中断します。指定されたスレッドで実行操作を行うと、 RunInterruptedExceptionがスローされます。

パラメーター
message String : RunInterruptedExceptionのメッセージ。

isInterruptAllowed

public boolean isInterruptAllowed ()

RunUtil の割り込みステータスを指定します。

戻り値
boolean Run を中断できる場合は true、そうでない場合は false。

runCmdInBackground

public Process runCmdInBackground (Redirect redirect, 
                 command)

コマンド引数をERROR(/List)形式で受け取る代替のrunCmdInBackground(String)メソッド。

パラメーター
redirect Redirect : ERROR(/Redirect) ERROR(/ProcessBuilder)

command : 指定されたシステム コマンドと、オプションで exec への引数を含むERROR(/List)

戻り値
Process実行されたコマンドのERROR(/Process)

runCmdInBackground

public Process runCmdInBackground ( command)

コマンド引数をERROR(/List)形式で受け取る代替のrunCmdInBackground(String)メソッド。

パラメーター
command : 指定されたシステム コマンドと、オプションで exec への引数を含むERROR(/List)

戻り値
Process実行されたコマンドのERROR(/Process)

runCmdInBackground

public Process runCmdInBackground ( command, 
                OutputStream output)

ERROR(/OutputStream)を指定してコマンドを実行すると、コマンドの出力がログに記録されます。 Stdout と stderr は一緒にマージされます。

パラメーター
command : 実行するコマンド

output OutputStream : 出力を保存する OutputStream

戻り値
Processコマンドを実行しているERROR(/Process)

runCmdInBackground

public Process runCmdInBackground (String... command)

システム コマンドを非同期で実行するためのヘルパー メソッド。

コマンドを起動するとすぐに戻ります。

パラメーター
command String : 指定されたシステム コマンドと、オプションで exec への引数

戻り値
Process実行されたコマンドのERROR(/Process)

runCmdInBackground

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

システム コマンドを非同期で実行するためのヘルパー メソッド。

コマンドを起動するとすぐに戻ります。

パラメーター
redirect Redirect : ERROR(/Redirect) ERROR(/ProcessBuilder)

command String : 指定されたシステム コマンドと、オプションで exec への引数

戻り値
Process実行されたコマンドのERROR(/Process)

runEscalatingTimedRetry

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

成功するまで操作をブロックして複数回実行します。

操作試行間の待機時間を指数関数的に増やします。これは、サーバーのポーリングなどの操作を実行するときに使用して、サーバーが一時的にダウンした場合に回復する時間を与えることを目的としています。

パラメーター
opTimeout long : 1 回の操作試行を待機する最大時間 (ミリ秒)

initialPollInterval long : 操作試行間の初期待機時間

maxPollInterval long : 操作試行間の最大待機時間

maxTime long : 操作を試行し続ける合計おおよその最大時間

runnable IRunUtil.IRunnableResult : 実行するIRunUtil.IRunnableResult

戻り値
boolean maxTime が期限切れになる前に操作が正常に完了した場合はtrue

runFixedTimedRetry

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

成功するまで操作をブロックして複数回実行します。

パラメーター
opTimeout long : 1 回の操作試行を待機する最大時間 (ミリ秒)

pollInterval long : 操作試行間の初期待機時間

maxTime long : 操作を試行し続ける合計おおよその最大時間

runnable IRunUtil.IRunnableResult : 実行するIRunUtil.IRunnableResult

戻り値
boolean maxTime が期限切れになる前に操作が正常に完了した場合はtrue

実行時間

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

操作をブロックして実行し、指定された時間より長くかかる場合は中止します。

パラメーター
timeout long : 最大待機時間 (ミリ秒)

runnable IRunUtil.IRunnableResult : 実行するIRunUtil.IRunnableResult

logErrors boolean : 例外のエラーをログに記録するかどうか。

戻り値
CommandStatus操作のCommandStatus結果。

runTimedCmd

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

システム コマンドを実行し、指定された時間より長くかかる場合は中止し、指定されている場合は出力をファイルにリダイレクトするヘルパー メソッド。 ERROR(/OutputStream)このように提供されると、それらは関数の最後で開いたままになります。

パラメーター
timeout long : タイムアウトの最大待機時間 (ミリ秒)。 0 はタイムアウトなしを意味します。

stdout OutputStream : std 出力がリダイレクトされるERROR(/OutputStream) 。 null にすることができます。

stderr OutputStream : エラー出力がリダイレクトされるERROR(/OutputStream) 。 null にすることができます。

command String : 指定されたシステム コマンドと、オプションで exec への引数

戻り値
CommandResultコマンド実行の結果を含むCommandResult

runTimedCmd

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

システム コマンドを実行するためのヘルパー メソッドと、指定された時間より長くかかる場合の中止。

パラメーター
timeout long : ミリ秒で待機する最大時間。 0 はタイムアウトなしを意味します。

command String : 指定されたシステム コマンドと、オプションで exec への引数

戻り値
CommandResultコマンド実行の結果を含むCommandResult

runTimedCmdRetry

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

システム コマンドを実行するためのヘルパー メソッドと、指定された時間より長くかかる場合の中止。

パラメーター
timeout long : 各試行の最大待機時間 (ミリ秒)

retryInterval long : コマンドの再試行の間に待機する時間

attempts int : 試行の最大回数

command String : 指定されたシステム コマンドと、オプションで exec への引数

戻り値
CommandResultコマンド実行の結果を含むCommandResult

runTimedCmdSilently

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

システム コマンドを実行するためのヘルパー メソッドと、指定された時間より長くかかる場合の中止。 runTimedCmd(long, String)に似ていますが、例外のエラーをログに記録しません。

パラメーター
timeout long : 最大待機時間 (ミリ秒)

command String : 指定されたシステム コマンドと、オプションで exec への引数

戻り値
CommandResultコマンド実行の結果を含むCommandResult

runTimedCmdSilentlyRetry

public 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 CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                File stdoutFile, 
                File stderrFile, 
                String... command)

システム コマンドを実行し、指定された時間より長くかかる場合は中止し、指定されている場合は出力をファイルにリダイレクトするヘルパー メソッド。

パラメーター
timeout long : タイムアウトの最大待機時間 (ミリ秒)。 0 はタイムアウトなしを意味します。

input String : プロセスに渡す stdin 入力

stdoutFile File : std 出力がリダイレクトされるERROR(/File) 。 null にすることができます。

stderrFile File : エラー出力がリダイレクトされるERROR(/File) 。 null にすることができます。

command String : 指定されたシステム コマンドと、オプションで exec への引数

戻り値
CommandResultコマンド実行の結果を含むCommandResult

runTimedCmdWithInput

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

stdin 入力を必要とするシステム コマンドを実行し、指定された時間よりも時間がかかる場合は中止するためのヘルパー メソッド。

パラメーター
timeout long : 最大待機時間 (ミリ秒)

input String : プロセスに渡す stdin 入力

command String : 指定されたシステム コマンドと、オプションで exec への引数

戻り値
CommandResultコマンド実行の結果を含むCommandResult

runTimedCmdWithInput

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

stdin 入力を必要とするシステム コマンドを実行し、指定された時間よりも時間がかかる場合は中止するためのヘルパー メソッド。

パラメーター
timeout long : 最大待機時間 (ミリ秒)

input String : プロセスに渡す stdin 入力

command : システム コマンドとオプションで exec への引数を含むERROR(/List)

戻り値
CommandResultコマンド実行の結果を含むCommandResult

runTimedCmdWithInputRedirect

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

ファイルから Stdin をリダイレクトし、指定された時間より長くかかる場合は中止する必要があるシステム コマンドを実行するためのヘルパー メソッド。

パラメーター
timeout long : 最大待機時間 (ミリ秒)

inputRedirect File : ERROR ERROR(/ProcessBuilder#redirectInput())を使用して標準入力としてリダイレクトするERROR(/File) ) 。 null の場合、stdin はリダイレクトされません。

command String : 指定されたシステム コマンドと、オプションで exec への引数

戻り値
CommandResultコマンド実行の結果を含むCommandResult

runTimedRetry

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

成功するまで操作をブロックして複数回実行します。

パラメーター
opTimeout long : 1 回の操作試行を待機する最大時間 (ミリ秒)

pollInterval long : コマンドの再試行の間に待機する時間

attempts int : 試行の最大回数

runnable IRunUtil.IRunnableResult : 実行するIRunUtil.IRunnableResult

戻り値
boolean試行に到達する前に操作が正常に完了した場合はtrue

setEnvVariable

public void setEnvVariable (String name, 
                String value)

システム コマンドの実行時に使用する環境変数を設定します。

パラメーター
name String : 変数名

value String : 変数値

setEnvVariablePriority

public void setEnvVariablePriority (IRunUtil.EnvPriority priority)

プロセスの作成時に、環境変数の設定よりも設定の解除を優先するかどうかを決定します。デフォルトでは、設定解除の優先度が高くなります。つまり、同じ名前の変数を設定しようとしても、変数が設定解除されるため、設定は行われません。デフォルトのIRunUtilインスタンスでは使用できません。

パラメーター
priority IRunUtil.EnvPriority

setInterruptibleInFuture

public void setInterruptibleInFuture (Thread thread, 
                long timeMs)

しばらく待った後、割り込み可能として設定します。 ERROR(/CommandScheduler#shutdownHard())強制的に最終的に終了します。

パラメーター
thread Thread : 割り込み可能になるスレッド。

timeMs long : 割り込み可能に設定する前に待機する時間。

setLinuxInterruptProcess

public void setLinuxInterruptProcess (boolean interrupt)

#runTimed メソッドを介して実行中のプロセスがタイムアウトに達したときに、Linux の「kill」割り込みを使用できるようにします。デフォルトのIRunUtilインスタンスでは使用できません。

パラメーター
interrupt boolean

setRedirectStderrToStdout

public void setRedirectStderrToStdout (boolean redirect)

システム コマンドの実行時に、標準エラー ストリームを標準出力ストリームにリダイレクトするように設定します。初期値は偽です。

パラメーター
redirect boolean : リダイレクトするかどうかの新しい値

setWorkingDir

public void setWorkingDir (File dir)

システム コマンドの作業ディレクトリを設定します。

パラメーター
dir File : 作業ディレクトリ

寝る

public void sleep (long time)

例外を無視して、指定された時間だけスリープするヘルパー メソッド。

パラメーター
time long : スリープまでのミリ秒。 0 以下の値は無視されます

unsetEnvVariable

public void unsetEnvVariable (String key)

環境変数を設定解除して、システム コマンドがこの環境変数なしで実行されるようにします。環境変数は親プロセスから継承される可能性があるため、 ERROR(/ProcessBuilder#environment())から環境変数を削除する必要があります。

パラメーター
key String : 変数名

以下も参照してください。