CommandScheduler

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)

将指定文件中的所有命令添加到调度程序

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, ITestDevice device, String[] args)

直接在已分配的设备上执行命令。

long 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)
void removeAllCommands()

从调度程序中移除所有命令

void run()

相应线程的主要执行块。

void setClearcutClient(ClearcutClient client)

将客户端设置为报告功能区数据

void setMaxPollTime(long polling)
void setPrintSchedulingWarning(boolean print)
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)
IConfigurationFactory getConfigFactory()

用于获取对 IConfigurationFactory 的引用的工厂方法

DeviceManagementGrpcServer getDeviceManagementServer()
IDeviceManager getDeviceManager()

用于获取对 IDeviceManager 的引用的工厂方法

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

使用 IGlobalConfiguration 中声明的 IKeyStoreFactory 获取 IKeyStoreClient;如果未定义任何 IKeyStoreFactory,则返回 null。

TestInvocationManagementServer getTestInvocationManagementServer()
void initLogging()

初始化 ddmlib 日志。

boolean isShutdown()
void processReadyCommands(IDeviceManager manager)

公共构造函数

CommandScheduler

public CommandScheduler ()

创建 CommandScheduler

注意:必须先调用 start,然后才能使用。

公共方法

addCommand

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

向调度程序添加命令。

命令本质上是要运行的配置及其关联实参的实例。

如果指定了“--help”实参,则配置的帮助文本将输出到标准输出。 否则,配置将添加到队列中以供运行。

参数
args String:配置实参。

返回
Pair<Boolean, Integer> 一对值,第一个值是布尔值 true,表示命令是否已成功添加。第二个值是已知命令跟踪器 ID(非负值),如果命令已成功添加,则返回 0(如果命令是为所有设备添加的),否则返回 -1。

抛出
ConfigurationException

addCommandFile

public void addCommandFile (String cmdFilePath, 
                 extraArgs)

将指定文件中的所有命令添加到调度程序

参数
cmdFilePath String:命令文件的文件系统路径

extraArgs :要附加到从文件解析的每个命令的 String 实参的 ERROR(/List)。可以为空,但不应为 null。

抛出
ConfigurationException

await

public void await ()

等待调度器开始运行,包括等待从旧版 TF 完成切换(如果适用)。

checkDelegation

public static TradefedDelegator checkDelegation (String[] args)

基于命令行创建委托方,以确定是否需要委托运行。

参数
args String

返回
TradefedDelegator

抛出
com.android.tradefed.config.ConfigurationException
ConfigurationException

createReleaseMap

public static  createReleaseMap (IInvocationContext context, 
                Throwable e)

创建设备状态的映射,以便正确释放设备。

参数
context IInvocationContext

e Throwable

返回

createSandbox

public ISandbox createSandbox ()

创建一个供调用运行的 ISandbox

返回
ISandbox

displayCommandQueue

public void displayCommandQueue (PrintWriter printWriter)

输出有关命令执行队列状态的详细调试信息。

displayCommandsInfo

public void displayCommandsInfo (PrintWriter printWriter, 
                String regex)

输出当前命令的列表。

参数
printWriter PrintWriter:要输出到的 ERROR(/PrintWriter)

regex String:命令应匹配的正则表达式,以便打印命令。如果为 null,则打印所有命令。

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 文件。如果为 null,则转储所有命令。

execCommand

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

直接在已分配的设备上执行命令。

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

device ITestDevice:要使用的 ITestDevice

args String:命令实参

返回
long 已安排命令的调用 ID。

抛出
ConfigurationException

execCommand

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

直接在已分配的设备上执行命令。

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

reservedDevices :要使用的 ERROR(/List)

args String:命令实参

返回
long 已安排命令的调用 ID。

抛出
ConfigurationException

execCommand

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

直接分配设备并执行命令,而无需使用已有的 IInvocationContext 将其添加到命令队列。

参数
context IInvocationContext:现有 IInvocationContext

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

args String:命令实参

返回
long

抛出
ConfigurationException
NoDeviceException

execCommand

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

直接分配设备并执行命令,而无需将其添加到命令队列。

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

args String:命令实参

返回
long 已安排命令的调用 ID。

抛出
ConfigurationException
NoDeviceException

getCommandFileWatcher

public CommandFileWatcher getCommandFileWatcher ()

获取相应调度程序的 CommandFileWatcher

返回
CommandFileWatcher

getExecutingCommandCount

public int getExecutingCommandCount ()

返回处于执行状态的命令数。

返回
int

getHostState

public CommandScheduler.HostState getHostState ()

返回
CommandScheduler.HostState

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。 如果没有可抛出的对象,则返回 null。

返回
Throwable

getReadyCommandCount

public int getReadyCommandCount ()

返回队列中处于就绪状态的命令数。

返回
int

getShutdownTimeout

public long getShutdownTimeout ()

返回
long

isDeviceInInvocationThread

public boolean isDeviceInInvocationThread (ITestDevice device)

如果设备正被有效的调用线程使用,则返回 true。

参数
device ITestDevice

返回
boolean

isShuttingDown

public boolean isShuttingDown ()

返回
boolean

notifyFileChanged

public void notifyFileChanged (File cmdFile, 
                 extraArgs)

参数
cmdFile File

extraArgs

removeAllCommands

public void removeAllCommands ()

从调度程序中移除所有命令

得分

public void run ()

相应线程的主要执行块。

setClearcutClient

public void setClearcutClient (ClearcutClient client)

将客户端设置为报告安全带数据

参数
client ClearcutClient

setMaxPollTime

public void setMaxPollTime (long polling)

参数
polling long

setPrintSchedulingWarning

public void setPrintSchedulingWarning (boolean print)

参数
print boolean

shouldShutdownOnCmdfileError

public boolean shouldShutdownOnCmdfileError ()

如果需要在命令出错时关闭调度程序,则返回 true

返回
boolean

关停

public void shutdown (boolean notifyStop)

尝试正常关闭命令调度程序。

参数
notifyStop boolean:如果为 true,则通知调用方 TF 正在关闭。

shutdownHard

public void shutdownHard (boolean killAdb)

尝试强制关闭命令调度程序。

shutdown() 类似,但也会选择性地终止 adb 连接,以尝试“促使”正在进行的调用更快完成。

参数
killAdb boolean

shutdownHard

public void shutdownHard ()

尝试强制关闭命令调度程序。与 shutdownHard(true) 相同。

shutdownOnEmpty

public void shutdownOnEmpty ()

shutdown() 类似,但会等待所有命令执行完毕后再退出。

请注意,如果任何命令处于循环模式,调度程序将永远不会退出。

start

public void start ()

启动调度程序,包括设置日志记录、初始化 DeviceManager

stopInvocation

public boolean stopInvocation (ITestInvocation invocation)

停止正在运行的调用。

参数
invocation ITestInvocation

返回
boolean 如果调用已停止,则为 true;否则为 false

stopInvocation

public boolean stopInvocation (int invocationId, 
                String cause)

通过指定正在运行的调用的 ID 来停止该调用。

参数
invocationId int:调用的跟踪 ID。

cause String:停止调用的原因。

返回
boolean 如果调用已停止,则为 true;否则为 false

stopScheduling

public void stopScheduling ()

停止调度和接受新测试,但不停止 Tradefed。此标志旨在实现两步关停,即先排空所有正在运行的测试,然后终止 Tradefed 进程。

受保护的方法

cleanUp

protected void cleanUp ()

关闭日志并在退出之前执行任何其他必要的清理操作。

公开,以便单元测试可以进行模拟。

createConfiguration

protected IConfiguration createConfiguration (String[] args)

参数
args String

返回
IConfiguration

抛出
ConfigurationException

createInvocationContext

protected IInvocationContext createInvocationContext ()

返回
IInvocationContext

dryRunCommandReporting

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

确定给定命令是否为试运行。如果命令是试运行命令,请验证它。如果存在任何配置问题,它将抛出 ConfigurationException。

参数
handler ICommandScheduler.IScheduledInvocationListener:用于报告试运行验证事件的 ERROR(/InvocationEventHandler)

config IConfiguration

返回
void 如果命令是试运行,则为 true,否则为 false。

抛出
com.android.tradefed.config.ConfigurationException
ConfigurationException

execCommand

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

参数
context IInvocationContext

listener ICommandScheduler.IScheduledInvocationListener

reservedDevices

args String

返回
long

抛出
ConfigurationException

getConfigFactory

protected IConfigurationFactory getConfigFactory ()

用于获取对 IConfigurationFactory 的引用的工厂方法

返回
IConfigurationFactory 要使用的 IConfigurationFactory

getDeviceManagementServer

protected DeviceManagementGrpcServer getDeviceManagementServer ()

返回
DeviceManagementGrpcServer

getDeviceManager

protected IDeviceManager getDeviceManager ()

用于获取对 IDeviceManager 的引用的工厂方法

返回
IDeviceManager 要使用的 IDeviceManager

getFeatureServer

protected TradefedFeatureServer getFeatureServer ()

返回
TradefedFeatureServer

getHostOptions

protected IHostOptions getHostOptions ()

返回
IHostOptions

getKeyStoreClient

protected IKeyStoreClient getKeyStoreClient ()

使用 IGlobalConfiguration 中声明的 IKeyStoreFactory 获取 IKeyStoreClient;如果未定义任何 IKeyStoreFactory,则返回 null。

返回
IKeyStoreClient IKeyStoreClient

getTestInvocationManagementServer

protected TestInvocationManagementServer getTestInvocationManagementServer ()

返回
TestInvocationManagementServer

initLogging

protected void initLogging ()

初始化 ddmlib 日志。

公开,以便单元测试可以进行模拟。

isShutdown

protected boolean isShutdown ()

返回
boolean

processReadyCommands

protected void processReadyCommands (IDeviceManager manager)

参数
manager IDeviceManager