命令調度程序

public class CommandScheduler
extends Object implements ICommandScheduler

java.lang.Object
com.android.tradefed.command.CommandScheduler


用於在所有可用裝置上執行 TradeFederation 指令的排程器。

將嘗試根據執行時間的總運行計數來確定要運行的命令的優先順序。例如,不頻繁或快速運行的命令將優先於長時間運行的命令。

永遠在後台運行直到關閉。

概括

公共構造函數

CommandScheduler ()

建立一個CommandScheduler

公共方法

Pair <Boolean, Integer> addCommand (String[] args)

在調度程序中新增命令。

void addCommandFile (String cmdFilePath, extraArgs) addCommandFile (String cmdFilePath, extraArgs)

將給定檔案中的所有命令新增至調度程序

void await ()

等待調度程序開始運行,包括等待舊 TF 的切換完成(如果適用)。

static TradefedDelegator checkDelegation (String[] args)

根據命令列建立委託器,看看我們是否需要委託運作。

static createReleaseMap ( IInvocationContext context, Throwable e)

建立設備狀態圖,以便可以適當地釋放它們。

ISandbox createSandbox ()

建立呼叫將用於運行的ISandbox

void displayCommandQueue (PrintWriter printWriter)

輸出有關命令執行佇列狀態的詳細偵錯資訊。

void displayCommandsInfo (PrintWriter printWriter, String regex)

輸出當前命令的列表。

void displayInvocationsInfo (PrintWriter printWriter)

顯示目前呼叫的清單。

void dumpCommandsXml (PrintWriter printWriter, String regex)

轉儲該命令的擴展 xml 文件,其中包含為所有當前命令指定的所有Option值。

long execCommand ( ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args) execCommand ( ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args)

直接在已指派的設備上執行命令。

long execCommand ( IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, String[] args)

直接分配裝置並執行命令,而不使用現有的IInvocationContext將其新增至命令佇列。

long execCommand ( ICommandScheduler.IScheduledInvocationListener listener, String[] args)

直接分配設備並執行命令,而不將其添加到命令隊列。

CommandFileWatcher getCommandFileWatcher ()

為該調度程序取得適當的 CommandFileWatcher

int getExecutingCommandCount ()

傳回處於執行狀態的命令數。

CommandScheduler.HostState getHostState ()
String getInvocationInfo (int invocationId)

傳回有關指定呼叫 ID 的呼叫的資訊。

CommandRunner.ExitCode getLastInvocationExitCode ()

傳回上次運行的呼叫的錯誤代碼。

Throwable getLastInvocationThrowable ()

返回上次運行的呼叫中的Throwable

int getReadyCommandCount ()

傳回佇列中處於就緒狀態的命令數。

long getShutdownTimeout ()
boolean isDeviceInInvocationThread ( ITestDevice device)

如果設備由活動呼叫線程使用,則傳回 true。

boolean isShuttingDown ()
void notifyFileChanged (File cmdFile, extraArgs) notifyFileChanged (File cmdFile, extraArgs)
void removeAllCommands ()

從排程器中刪除所有命令

void run ()

該線程的主要執行塊。

void setClearcutClient (ClearcutClient client)

設定客戶端報告線束數據

boolean shouldShutdownOnCmdfileError ()

如果我們需要在命令錯誤時關閉調度程序,則傳回 true

void shutdown (boolean notifyStop)

嘗試正常關閉命令調度程序。

void shutdownHard (boolean killAdb)

嘗試強制關閉命令調度程序。

void shutdownHard ()

嘗試強制關閉命令調度程序。

void shutdownOnEmpty ()

shutdown()類似,但會等待所有指令執行完畢後再退出。

void start ()

啟動調度程序,包括設定日誌記錄、 DeviceManager初始化等

boolean stopInvocation ( ITestInvocation invocation)

停止正在運行的呼叫。

boolean stopInvocation (int invocationId, String cause)

透過指定其 id 來停止正在運行的呼叫。

void stopScheduling ()

停止安排和接受新測試,但不停止 Tradefed。

受保護的方法

void cleanUp ()

在退出之前關閉日誌並進行任何其他必要的清理。

IConfiguration createConfiguration (String[] args)
IInvocationContext createInvocationContext ()
void dryRunCommandReporting ( ICommandScheduler.IScheduledInvocationListener handler, IConfiguration config)

確定給定命令是否為空運行。

long execCommand ( IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args) execCommand ( IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args)
IConfigurationFactory getConfigFactory ()

用於取得IConfigurationFactory引用的工廠方法

DeviceManagementGrpcServer getDeviceManagementServer ()
IDeviceManager getDeviceManager ()

用於取得IDeviceManager引用的工廠方法

TradefedFeatureServer getFeatureServer ()
IHostOptions getHostOptions ()
IKeyStoreClient getKeyStoreClient ()

使用IGlobalConfiguration中宣告的IKeyStoreClient IKeyStoreFactory如果未定義,則為 null。

TestInvocationManagementServer getTestInvocationManagementServer ()
void initLogging ()

初始化 ddmlib 日誌。

boolean isShutdown ()
void processReadyCommands ( IDeviceManager manager)

公共構造函數

命令調度程序

public CommandScheduler ()

建立一個CommandScheduler

注意:使用前必須呼叫start。

公共方法

新增命令

public Pair<Boolean, Integer> addCommand (String[] args)

在調度程序中新增命令。

命令本質上是要運行的配置及其關聯參數的實例。

如果指定了「--help」參數,則配置的說明文字將輸出到標準輸出。否則,配置將被加入到佇列中運行。

參數
args String :配置參數。

退貨
Pair <Boolean, Integer>一對值,如果指令加入成功,第一個值是布林值true 。第二個值是已知的命令追蹤器 ID(非負值),如果命令新增成功,則為所有裝置新增指令時傳回 0,否則傳回 -1。

投擲
ConfigurationException

新增命令文件

public void addCommandFile (String cmdFilePath, 
                 extraArgs)

將給定檔案中的所有命令新增至調度程序

參數
cmdFilePath String : 命令檔案的檔案系統路徑

extraArgs :附加到從檔案解析的每個指令的String參數的ERROR(/List) 。可以為空,但不應為空。

投擲
ConfigurationException

等待

public void await ()

等待調度程序開始運行,包括等待舊 TF 的切換完成(如果適用)。

檢查委託

public static TradefedDelegator checkDelegation (String[] args)

根據命令列建立委託器,看看我們是否需要委託運作。

參數
args String

退貨
TradefedDelegator

投擲
com.android.tradefed.config.ConfigurationException
ConfigurationException

建立發布映射

public static  createReleaseMap (IInvocationContext context, 
                Throwable e)

建立設備狀態圖,以便可以適當地釋放它們。

參數
context IInvocationContext

e Throwable

退貨

創建沙箱

public ISandbox createSandbox ()

建立呼叫將用於運行的ISandbox

退貨
ISandbox

顯示命令隊列

public void displayCommandQueue (PrintWriter printWriter)

輸出有關命令執行佇列狀態的詳細偵錯資訊。

顯示命令訊息

public void displayCommandsInfo (PrintWriter printWriter, 
                String regex)

輸出當前命令的列表。

參數
printWriter PrintWriter :要輸出到的ERROR(/PrintWriter)

regex String :指令應與其相符才能列印的正規表示式。如果為空,則將列印所有命令。

顯示呼叫訊息

public void displayInvocationsInfo (PrintWriter printWriter)

顯示目前呼叫的清單。

參數
printWriter PrintWriter :要輸出到的ERROR(/PrintWriter)

dumpCommandsXml

public void dumpCommandsXml (PrintWriter printWriter, 
                String regex)

轉儲該命令的擴展 xml 文件,其中包含為所有當前命令指定的所有Option值。

參數
printWriter PrintWriter :將狀態輸出到的ERROR(/PrintWriter)

regex String :命令應與其匹配的正規表示式,以便轉儲 xml 檔案。如果為 null,則所有命令都將被轉儲。

執行命令

public long execCommand (ICommandScheduler.IScheduledInvocationListener listener, 
                 reservedDevices, 
                String[] args)

直接在已指派的設備上執行命令。

參數
listener ICommandScheduler.IScheduledInvocationListener :要通知的ICommandScheduler.IScheduledInvocationListener

reservedDevicesERROR(/List ) ERROR(/List )使用

args String : 指令參數

退貨
long計劃命令的呼叫ID。

投擲
ConfigurationException

執行命令

public long execCommand (IInvocationContext context, 
                ICommandScheduler.IScheduledInvocationListener listener, 
                String[] args)

直接分配裝置並執行命令,而不使用現有的IInvocationContext將其新增至命令佇列。

參數
context IInvocationContext :現有的IInvocationContext

listener ICommandScheduler.IScheduledInvocationListener :要通知的ICommandScheduler.IScheduledInvocationListener

args String : 指令參數

退貨
long

投擲
ConfigurationException
NoDeviceException

執行命令

public long execCommand (ICommandScheduler.IScheduledInvocationListener listener, 
                String[] args)

直接分配設備並執行命令,而不將其添加到命令隊列。

參數
listener ICommandScheduler.IScheduledInvocationListener :要通知的ICommandScheduler.IScheduledInvocationListener

args String : 指令參數

退貨
long計劃命令的呼叫ID。

投擲
ConfigurationException
NoDeviceException

取得命令文件觀察者

public CommandFileWatcher getCommandFileWatcher ()

為該調度程序取得適當的 CommandFileWatcher

退貨
CommandFileWatcher

取得執行命令計數

public int getExecutingCommandCount ()

傳回處於執行狀態的命令數。

退貨
int

取得主機狀態

public CommandScheduler.HostState getHostState ()

退貨
CommandScheduler.HostState

獲取呼叫訊息

public String getInvocationInfo (int invocationId)

傳回有關指定呼叫 ID 的呼叫的資訊。

參數
invocationId int :調用的追蹤 ID。

退貨
String包含有關呼叫的資訊的String

取得最後調用退出程式碼

public CommandRunner.ExitCode getLastInvocationExitCode ()

傳回上次運行的呼叫的錯誤代碼。如果尚未運行任何調用,則返回 0(無錯誤)。

退貨
CommandRunner.ExitCode

取得最後一個呼叫Throwable

public Throwable getLastInvocationThrowable ()

返回上次運行的呼叫中的Throwable 。如果沒有可用的 throwable,則傳回 null。

退貨
Throwable

取得就緒命令計數

public int getReadyCommandCount ()

傳回佇列中處於就緒狀態的命令數。

退貨
int

取得關機逾時

public long getShutdownTimeout ()

退貨
long

是設備呼叫執行緒

public boolean isDeviceInInvocationThread (ITestDevice device)

如果設備由活動呼叫線程使用,則傳回 true。

參數
device ITestDevice

退貨
boolean

正在關閉

public boolean isShuttingDown ()

退貨
boolean

通知文件更改

public void notifyFileChanged (File cmdFile, 
                 extraArgs)

參數
cmdFile File

extraArgs

刪除所有命令

public void removeAllCommands ()

從排程器中刪除所有命令

跑步

public void run ()

該線程的主要執行塊。

設定ClearcutClient

public void setClearcutClient (ClearcutClient client)

設定客戶端報告線束數據

參數
client ClearcutClient

應該ShutdownOnCmdfileError

public boolean shouldShutdownOnCmdfileError ()

如果我們需要在命令錯誤時關閉調度程序,則傳回 true

退貨
boolean

關閉

public void shutdown (boolean notifyStop)

嘗試正常關閉命令調度程序。

參數
notifyStop boolean :如果為 true,則通知呼叫 TF 關閉。

硬關機

public void shutdownHard (boolean killAdb)

嘗試強制關閉命令調度程序。

shutdown()類似,但也可以選擇終止 adb 連接,以嘗試「激發」正在進行的呼叫更快完成。

參數
killAdb boolean

硬關機

public void shutdownHard ()

嘗試強制關閉命令調度程序。與 shutdownHard(true) 相同。

空時關閉

public void shutdownOnEmpty ()

shutdown()類似,但會等待所有指令執行完畢後再退出。

請注意,如果任何命令處於循環模式,調度程式將永遠不會退出。

開始

public void start ()

啟動調度程序,包括設定日誌記錄、 DeviceManager初始化等

停止調用

public boolean stopInvocation (ITestInvocation invocation)

停止正在運行的呼叫。

參數
invocation ITestInvocation

退貨
boolean如果呼叫停止則為 true,否則為 false

停止調用

public boolean stopInvocation (int invocationId, 
                String cause)

透過指定其 id 來停止正在運行的呼叫。

參數
invocationId int :調用的追蹤 ID。

cause String :停止呼叫的原因。

退貨
boolean如果呼叫停止則為 true,否則為 false

停止調度

public void stopScheduling ()

停止安排和接受新測試,但不停止 Tradefed。這是為了實現兩步驟關閉,首先我們耗盡所有正在執行的測試,然後終止 Tradefed 進程。

受保護的方法

清理

protected void cleanUp ()

在退出之前關閉日誌並進行任何其他必要的清理。

暴露出來以便單元測試可以模擬。

建立配置

protected IConfiguration createConfiguration (String[] args)

參數
args String

退貨
IConfiguration

投擲
ConfigurationException

建立呼叫上下文

protected IInvocationContext createInvocationContext ()

退貨
IInvocationContext

dryRunCommand報告

protected void dryRunCommandReporting (ICommandScheduler.IScheduledInvocationListener handler, 
                IConfiguration config)

確定給定命令是否為空運行。如果該命令是空運行,請驗證它。如果有任何設定問題,它將拋出 ConfigurationException。

參數
handler ICommandScheduler.IScheduledInvocationListenerERROR(/InvocationEventHandler)報告事件以進行空運行驗證。

config IConfiguration

退貨
void如果命令是空運行,則為 true,否則為 false。

投擲
com.android.tradefed.config.ConfigurationException
ConfigurationException

執行命令

protected long execCommand (IInvocationContext context, 
                ICommandScheduler.IScheduledInvocationListener listener, 
                 reservedDevices, 
                String[] args)

參數
context IInvocationContext

listener ICommandScheduler.IScheduledInvocationListener

reservedDevices

args String

退貨
long

投擲
ConfigurationException

取得配置工廠

protected IConfigurationFactory getConfigFactory ()

用於取得IConfigurationFactory引用的工廠方法

退貨
IConfigurationFactory要使用的IConfigurationFactory

取得設備管理伺服器

protected DeviceManagementGrpcServer getDeviceManagementServer ()

退貨
DeviceManagementGrpcServer

取得裝置管理員

protected IDeviceManager getDeviceManager ()

用於取得IDeviceManager引用的工廠方法

退貨
IDeviceManager要使用的IDeviceManager

取得特徵伺服器

protected TradefedFeatureServer getFeatureServer ()

退貨
TradefedFeatureServer

取得主機選項

protected IHostOptions getHostOptions ()

退貨
IHostOptions

取得KeyStoreClient

protected IKeyStoreClient getKeyStoreClient ()

使用IGlobalConfiguration中宣告的IKeyStoreClient IKeyStoreFactory如果未定義,則為 null。

退貨
IKeyStoreClient IKeyStore客戶端

取得測試調用管理伺服器

protected TestInvocationManagementServer getTestInvocationManagementServer ()

退貨
TestInvocationManagementServer

初始化日誌記錄

protected void initLogging ()

初始化 ddmlib 日誌。

暴露出來以便單元測試可以模擬。

正在關機

protected boolean isShutdown ()

退貨
boolean

處理就緒指令

protected void processReadyCommands (IDeviceManager manager)

參數
manager IDeviceManager