命令调度程序

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)

基于命令行创建一个delegator,看看我们是否需要委托运行。

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 ()

从最后一次运行的调用中返回ERROR(/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 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 ()

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

DeviceManagementGrpcServer getDeviceManagementServer ()
IDeviceManager getDeviceManager ()

获取对IDeviceManager引用的工厂方法

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

使用在IGlobalConfiguration中声明的IKeyStoreFactory获取IKeyStoreClient ,如果未定义则为 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 : 一个ERROR(/List)ERROR(/String)参数附加到从文件解析的每个命令。可以为空但不应为空。

投掷
ConfigurationException

等待

public void await ()

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

检查委派

public static TradefedDelegator checkDelegation (String[] args)

基于命令行创建一个delegator,看看我们是否需要委托运行。

参数
args String

退货
TradefedDelegator

投掷
com.android.tradefed.config.ConfigurationException
ConfigurationException

创建ReleaseMap

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 文件,命令应与其匹配的正则表达式。如果为空,则将转储所有命令。

执行命令

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

getCommandFileWatcher

public CommandFileWatcher getCommandFileWatcher ()

为此调度程序获取适当的CommandFileWatcher

退货
CommandFileWatcher

getExecutingCommandCount

public int getExecutingCommandCount ()

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

退货
int

获取主机状态

public CommandScheduler.HostState getHostState ()

退货
CommandScheduler.HostState

获取调用信息

public String getInvocationInfo (int invocationId)

返回有关指定调用 ID 的调用的信息。

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

退货
String包含有关调用的信息的ERROR(/String)

getLastInvocationExitCode

public CommandRunner.ExitCode getLastInvocationExitCode ()

返回最后一次运行的调用的错误代码。如果尚未运行任何调用,则返回 0(无错误)。

退货
CommandRunner.ExitCode

getLastInvocationThrowable

public Throwable getLastInvocationThrowable ()

从最后一次运行的调用中返回ERROR(/Throwable) 。如果没有可用的 throwable,则返回 null。

退货
Throwable

getReadyCommandCount

public int getReadyCommandCount ()

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

退货
int

获取关机超时

public long getShutdownTimeout ()

退货
long

isDeviceInInvocationThread

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 ()

该线程的主要执行块。

设置清除客户端

public void setClearcutClient (ClearcutClient client)

设置客户端上报线束数据

参数
client ClearcutClient

shouldShutdownOnCmdfileError

public boolean shouldShutdownOnCmdfileError ()

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

退货
boolean

关闭

public void shutdown (boolean notifyStop)

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

参数
notifyStop boolean :如果为真,则通知调用 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

受保护的方法

清理

protected void cleanUp ()

在我们退出之前关闭日志并进行任何其他必要的清理。

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

创建配置

protected IConfiguration createConfiguration (String[] args)

参数
args String

退货
IConfiguration

投掷
ConfigurationException

创建调用上下文

protected IInvocationContext createInvocationContext ()

退货
IInvocationContext

执行命令

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中声明的IKeyStoreFactory获取IKeyStoreClient ,如果未定义则为 null。

退货
IKeyStoreClient IKeyStoreClient

getTestInvocationManagementServer

protected TestInvocationManagementServer getTestInvocationManagementServer ()

退货
TestInvocationManagementServer

初始化记录

protected void initLogging ()

初始化 ddmlib 日志。

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

是关机

protected boolean isShutdown ()

退货
boolean

processReadyCommands

protected void processReadyCommands (IDeviceManager manager)

参数
manager IDeviceManager