CommandScheduler
public
class
CommandScheduler
extends Object
implements
ICommandScheduler
java.lang.Object | |
↳ | com.android.tradefed.command.CommandScheduler |
這個排程器可在所有可用裝置上執行 TradeFederation 指令。
會嘗試根據其執行的總執行次數來排定指令執行的優先順序 讓應用程式從可以最快做出回應的位置 回應使用者要求例如:不常或快速執行的指令,其優先順序高於長時間執行的指令。
在背景中永久執行,直到關機為止。
摘要
巢狀類別 | |
---|---|
enum |
CommandScheduler.HostState
不同主機狀態的列舉 |
公用建構函式 | |
---|---|
CommandScheduler()
可建立 |
公用方法 | |
---|---|
boolean
|
addCommand(String[] args)
在排程器中新增指令。 |
void
|
addCommandFile(String cmdFilePath,
將指定檔案的所有指令新增至排程器 |
void
|
await()
等待排程器開始執行,包括等待舊 TF 轉換完成 (如適用)。 |
static
TradefedDelegator
|
checkDelegation(String[] args)
根據指令列建立委派者,確認是否需要委派執行作業。 |
void
|
completeHandover()
向指令排程器告知已啟動的交接序列作業已經完成,且 必須在預設通訊埠重新初始化遠端管理員。 |
static
|
createReleaseMap(IInvocationContext context, Throwable e)
建立裝置狀態的地圖,以便正確釋放裝置。 |
ISandbox
|
createSandbox()
建立叫用將用來執行的 |
void
|
displayCommandQueue(PrintWriter printWriter)
輸出指令執行佇列狀態的詳細偵錯資訊。 |
void
|
displayCommandsInfo(PrintWriter printWriter, String regex)
並輸出目前指令的清單。 |
void
|
displayInvocationsInfo(PrintWriter printWriter)
顯示目前叫用的清單。 |
void
|
dumpCommandsXml(PrintWriter printWriter, String regex)
使用所有指令傾印已展開的 XML 檔案
已為所有目前指令指定的 |
void
|
execCommand(ICommandScheduler.IScheduledInvocationListener listener, ITestDevice device, String[] args)
直接在已分配的裝置上執行指令。 |
void
|
execCommand(IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, String[] args)
直接分配裝置並執行指令,且不會將裝置新增至指令佇列
使用現有的 |
void
|
execCommand(ICommandScheduler.IScheduledInvocationListener listener, String[] args)
直接分配裝置並執行指令,且不會將裝置新增至指令佇列。 |
CommandFileWatcher
|
getCommandFileWatcher()
取得這個排程器適用的 |
int
|
getExecutingCommandCount()
傳回執行中狀態的指令數量。 |
CommandScheduler.HostState
|
getHostState()
|
String
|
getInvocationInfo(int invocationId)
傳回指定叫用 ID 的叫用耳機資訊。 |
CommandRunner.ExitCode
|
getLastInvocationExitCode()
傳回上次執行叫用的錯誤代碼。 |
Throwable
|
getLastInvocationThrowable()
從上次執行的叫用中傳回 |
int
|
getReadyCommandCount()
傳回佇列中處於就緒狀態的指令數量。 |
long
|
getShutdownTimeout()
|
void
|
handoverInitiationComplete()
向指令排程器告知初始交接裝置與使用中的指令 完成後,即可開始安排作業。 |
boolean
|
handoverShutdown(int handoverPort)
啟動 |
void
|
notifyFileChanged(File cmdFile,
|
void
|
removeAllCommands()
移除排程器中的所有指令 |
void
|
run()
這個執行緒的主要執行區塊。 |
void
|
setClearcutClient(ClearcutClient client)
將用戶端設為回報管理資料 |
boolean
|
shouldShutdownOnCmdfileError()
如果我們需要針對指令錯誤關閉排程器,則傳回 true |
void
|
shutdown()
嘗試安全關閉指令排程器。 |
void
|
shutdownHard(boolean killAdb)
嘗試強制關閉指令排程器。 |
void
|
shutdownHard()
嘗試強制關閉指令排程器。 |
void
|
shutdownOnEmpty()
與 |
void
|
start()
啟動排程器,包括設定記錄、啟動 |
boolean
|
stopInvocation(ITestInvocation invocation)
停止執行中的叫用。 |
boolean
|
stopInvocation(int invocationId, String cause)
指定 ID 即可停止執行中的叫用。 |
保護方法 | |
---|---|
void
|
cleanUp()
關閉記錄,並在退出前執行其他必要的清除作業。 |
IConfiguration
|
createConfiguration(String[] args)
|
IInvocationContext
|
createInvocationContext()
|
IConfigurationFactory
|
getConfigFactory()
取得 |
IDeviceManager
|
getDeviceManager()
取得 |
TradefedFeatureServer
|
getFeatureServer()
|
IHostOptions
|
getHostOptions()
|
IKeyStoreClient
|
getKeyStoreClient()
使用 |
void
|
initLogging()
初始化 ddmlib 記錄。 |
boolean
|
isShutdown()
|
boolean
|
isShuttingDown()
|
void
|
processReadyCommands(IDeviceManager manager)
|
void
|
waitForAllInvocationThreads()
請等待所有叫用執行緒完成。 |
公用建構函式
公用方法
addCommand
public boolean addCommand (String[] args)
在排程器中新增指令。
基本上,指令是執行設定的例項,以及其相關引數。
如果「--help」引數是指定的 設定則會輸出至 stdout否則,設定會新增至 此程序的第一步 是將程式碼簽入執行所有單元測試的存放區中
參數 | |
---|---|
args |
String :設定引數。 |
傳回 | |
---|---|
boolean |
true :如果成功新增指令 |
擲回 | |
---|---|
ConfigurationException |
addCommandFile
public void addCommandFile (String cmdFilePath,extraArgs)
將指定檔案的所有指令新增至排程器
參數 | |
---|---|
cmdFilePath |
String :comand 檔案的檔案系統路徑 |
extraArgs |
:String 引數的 ERROR(/List) ,附加在剖析的每個指令上
。可以是空白,但不能為空值。 |
擲回 | |
---|---|
ConfigurationException |
等人
public void await ()
等待排程器開始執行,包括等待舊 TF 轉換完成 (如適用)。
檢查委派
public static TradefedDelegator checkDelegation (String[] args)
根據指令列建立委派者,確認是否需要委派執行作業。
參數 | |
---|---|
args |
String |
傳回 | |
---|---|
TradefedDelegator |
擲回 | |
---|---|
ConfigurationException |
完整 Handover
public void completeHandover ()
向指令排程器告知已啟動的交接序列作業已經完成,且 必須在預設通訊埠重新初始化遠端管理員。
createReleaseMap
public staticcreateReleaseMap (IInvocationContext context, Throwable e)
建立裝置狀態的地圖,以便正確釋放裝置。
參數 | |
---|---|
context |
IInvocationContext |
e |
Throwable |
傳回 | |
---|---|
|
displayCommandQueue
public void displayCommandQueue (PrintWriter printWriter)
輸出指令執行佇列狀態的詳細偵錯資訊。
displayCommandsInfo
public void displayCommandsInfo (PrintWriter printWriter, String regex)
並輸出目前指令的清單。
參數 | |
---|---|
printWriter |
PrintWriter :要輸出的 ERROR(/PrintWriter) 。 |
regex |
String :為求相符指令的規則運算式
如果值為空值,則所有指令都會顯示。
|
displayInvocationsInfo
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 檔案如果為空值,系統會傾印所有指令。
|
execCommand
public void execCommand (ICommandScheduler.IScheduledInvocationListener listener, ITestDevice device, String[] args)
直接在已分配的裝置上執行指令。
參數 | |
---|---|
listener |
ICommandScheduler.IScheduledInvocationListener :要接收通知的 ICommandScheduler.IScheduledInvocationListener |
device |
ITestDevice :要使用的 ITestDevice |
args |
String :指令引數 |
擲回 | |
---|---|
ConfigurationException |
execCommand
public void execCommand (IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, String[] args)
直接分配裝置並執行指令,且不會將裝置新增至指令佇列
使用現有的 IInvocationContext
。
參數 | |
---|---|
context |
IInvocationContext :現有的 IInvocationContext 。 |
listener |
ICommandScheduler.IScheduledInvocationListener :要接收通知的 ICommandScheduler.IScheduledInvocationListener |
args |
String :指令引數 |
擲回 | |
---|---|
ConfigurationException |
|
NoDeviceException |
execCommand
public void execCommand (ICommandScheduler.IScheduledInvocationListener listener, String[] args)
直接分配裝置並執行指令,且不會將裝置新增至指令佇列。
參數 | |
---|---|
listener |
ICommandScheduler.IScheduledInvocationListener :要接收通知的 ICommandScheduler.IScheduledInvocationListener |
args |
String :指令引數 |
擲回 | |
---|---|
ConfigurationException |
|
NoDeviceException |
getCommandFileWatcher
public CommandFileWatcher getCommandFileWatcher ()
取得這個排程器適用的 CommandFileWatcher
傳回 | |
---|---|
CommandFileWatcher |
getExecutingCommandCount
public int getExecutingCommandCount ()
傳回執行中狀態的指令數量。
傳回 | |
---|---|
int |
getInvocationInfo
public String getInvocationInfo (int invocationId)
傳回指定叫用 ID 的叫用耳機資訊。
參數 | |
---|---|
invocationId |
int :叫用的追蹤 ID。 |
傳回 | |
---|---|
String |
包含叫用相關資訊的 String 。
|
getLastInvocationExitCode
public CommandRunner.ExitCode getLastInvocationExitCode ()
傳回上次執行叫用的錯誤代碼。 如果尚未執行叫用,會傳回 0 (無錯誤)。
傳回 | |
---|---|
CommandRunner.ExitCode |
getLastInvocationThrowable
public Throwable getLastInvocationThrowable ()
從上次執行的叫用中傳回 Throwable
。
如果沒有可用的 Throwable,則傳回空值。
傳回 | |
---|---|
Throwable |
getReadyCommandCount
public int getReadyCommandCount ()
傳回佇列中處於就緒狀態的指令數量。
傳回 | |
---|---|
int |
getShutdownTimeout
public long getShutdownTimeout ()
傳回 | |
---|---|
long |
移交完成
public void handoverInitiationComplete ()
向指令排程器告知初始交接裝置與使用中的指令 完成後,即可開始安排作業。
關機
public boolean handoverShutdown (int handoverPort)
啟動 shutdown()
並轉移至同一主機的其他交易程序。
排程器會通知遠端交易程序在監聽該釋出裝置的通訊埠 及時採用。
參數 | |
---|---|
handoverPort |
int |
傳回 | |
---|---|
boolean |
true 如果交替啟動成功,false
否則
|
通知檔案已變更
public void notifyFileChanged (File cmdFile,extraArgs)
參數 | |
---|---|
cmdFile |
File |
extraArgs |
|
removeAllCommands
public void removeAllCommands ()
移除排程器中的所有指令
得分
public void run ()
這個執行緒的主要執行區塊。
setClearcutClient
public void setClearcutClient (ClearcutClient client)
將用戶端設為回報管理資料
參數 | |
---|---|
client |
ClearcutClient |
shouldShutdownOnCmdfileError
public boolean shouldShutdownOnCmdfileError ()
如果我們需要針對指令錯誤關閉排程器,則傳回 true
傳回 | |
---|---|
boolean |
關機
public void shutdown ()
嘗試安全關閉指令排程器。
清除等待測試的指令,並清除所有進行中的叫用要求 安全關機
呼叫關閉後,排程器的主要迴圈會等候所有進行中的叫用作業 才能完全結束
關閉危險物品
public void shutdownHard (boolean killAdb)
嘗試強制關閉指令排程器。
與 shutdown()
類似,但也會視需要終止 ADB 連線,
試圖「激勵」即可更快完成
參數 | |
---|---|
killAdb |
boolean |
關閉危險物品
public void shutdownHard ()
嘗試強制關閉指令排程器。與 ShutHard(true) 相同。
停止叫用
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 |
保護方法
清理
protected void cleanUp ()
關閉記錄,並在退出前執行其他必要的清除作業。
公開,以便模擬單元測試。
建立設定
protected IConfiguration createConfiguration (String[] args)
參數 | |
---|---|
args |
String |
傳回 | |
---|---|
IConfiguration |
擲回 | |
---|---|
ConfigurationException |
createInvocationContext
protected IInvocationContext createInvocationContext ()
傳回 | |
---|---|
IInvocationContext |
getConfigFactory
protected IConfigurationFactory getConfigFactory ()
取得 IConfigurationFactory
參照的工廠方法
傳回 | |
---|---|
IConfigurationFactory |
要使用的 IConfigurationFactory
|
getDeviceManager
protected IDeviceManager getDeviceManager ()
取得 IDeviceManager
參照的工廠方法
傳回 | |
---|---|
IDeviceManager |
要使用的 IDeviceManager
|
getHost 選項
protected IHostOptions getHostOptions ()
傳回 | |
---|---|
IHostOptions |
getKeyStoreClient
protected IKeyStoreClient getKeyStoreClient ()
使用 IKeyStoreFactory
擷取 IKeyStoreClient
在 IGlobalConfiguration
中宣告;如未定義,則為空值。
傳回 | |
---|---|
IKeyStoreClient |
IKeyStoreClient |
initLogging
protected void initLogging ()
初始化 ddmlib 記錄。
公開,以便模擬單元測試。
關機
protected boolean isShutdown ()
傳回 | |
---|---|
boolean |
關機
protected boolean isShuttingDown ()
傳回 | |
---|---|
boolean |
processReadyCommands
protected void processReadyCommands (IDeviceManager manager)
參數 | |
---|---|
manager |
IDeviceManager |
waitForAllInvocationThreads
protected void waitForAllInvocationThreads ()
請等待所有叫用執行緒完成。