命令调度程序
public class CommandScheduler
extends Object
implements ICommandScheduler
java.lang.Object | |
↳ | com.android.tradefed.command.CommandScheduler |
用于在所有可用设备上运行 TradeFederation 命令的调度程序。
将尝试根据执行时间的总运行计数确定要运行的命令的优先级。例如,不频繁或快速运行的命令将优先于长时间运行的命令。
永远在后台运行直到关闭。
概括
公共构造函数 | |
---|---|
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 () 创建调用将用于运行的 |
void | displayCommandQueue (PrintWriter printWriter) 输出有关命令执行队列状态的详细调试信息。 |
void | displayCommandsInfo (PrintWriter printWriter, String regex) 输出当前命令的列表。 |
void | displayInvocationsInfo (PrintWriter printWriter) 显示当前调用的列表。 |
void | dumpCommandsXml (PrintWriter printWriter, String regex) 转储该命令的扩展 xml 文件,其中包含为所有当前命令指定的所有 |
long | execCommand ( ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args) execCommand ( ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args) 直接在已分配的设备上执行命令。 |
long | execCommand ( IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, String[] args) 直接分配设备并执行命令,而不使用现有的 |
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 () 返回上次运行的调用中的 |
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 () 与 |
void | start () 启动调度程序,包括设置日志记录、 |
boolean | stopInvocation ( ITestInvocation invocation) 停止正在运行的调用。 |
boolean | stopInvocation (int invocationId, String cause) 通过指定其 id 来停止正在运行的调用。 |
受保护的方法 | |
---|---|
void | cleanUp () 在退出之前关闭日志并进行任何其他必要的清理。 |
IConfiguration | createConfiguration (String[] args) |
IInvocationContext | createInvocationContext () |
long | execCommand ( IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args) execCommand ( IInvocationContext context, ICommandScheduler.IScheduledInvocationListener listener, reservedDevices, String[] args) |
IConfigurationFactory | getConfigFactory () 用于获取 |
DeviceManagementGrpcServer | getDeviceManagementServer () |
IDeviceManager | getDeviceManager () 用于获取 |
TradefedFeatureServer | getFeatureServer () |
IHostOptions | getHostOptions () |
IKeyStoreClient | getKeyStoreClient () 使用 |
TestInvocationManagementServer | getTestInvocationManagementServer () |
void | initLogging () 初始化 ddmlib 日志。 |
boolean | isShutdown () |
void | processReadyCommands ( IDeviceManager manager) |
公共构造函数
公共方法
添加命令
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 staticcreateReleaseMap (IInvocationContext context, Throwable e)
创建设备状态图,以便可以适当地释放它们。
参数 | |
---|---|
context | IInvocationContext |
e | Throwable |
退货 | |
---|---|
显示命令队列
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 |
reservedDevices | ERROR(/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 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 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 |
执行命令
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 |
获取KeyStoreClient
protected IKeyStoreClient getKeyStoreClient ()
使用IGlobalConfiguration
中声明的IKeyStoreClient
IKeyStoreFactory
如果未定义,则为 null。
退货 | |
---|---|
IKeyStoreClient | IKeyStore客户端 |
获取测试调用管理服务器
protected TestInvocationManagementServer getTestInvocationManagementServer ()
退货 | |
---|---|
TestInvocationManagementServer |
初始化日志记录
protected void initLogging ()
初始化 ddmlib 日志。
暴露出来以便单元测试可以模拟。
正在关机
protected boolean isShutdown ()
退货 | |
---|---|
boolean |