1.CommandScheduler启动
CommandScheduler本身也是一个线程,是在Console线程启动时启动的,作为命令调度的线程,主要作用就是检查本身的CommandQueue中是不是有需要处理的command,进行调度不至于多命令或者多设备时出现混乱,以及启动真正的命令执行线程。
public void run() {
assertStarted();
try {
IDeviceManager manager = getDeviceManager();
startRemoteManager();
// 在启动的第一时间先countDown,此时main线程就会被释放,就退出了
mRunLatch.countDown();
// add a listener that will wake up scheduler when a new avail device is added
manager.addDeviceMonitor(new AvailDeviceMonitor());
// 进入了循环处理命令,直到输入了退出命令
while (!isShutdown()) {
// 每过30s起来看看是不是有需要调度的命令
mCommandProcessWait.waitAndReset(mPollTime);
checkInvocations();
processReadyCommands(manager);
postProcessReadyCommands();
}
// 退出循环之后代表程序即将退出了,进行一些清理工作
mCommandTimer.shutdown();
manager.terminateDeviceRecovery();
manager.terminateDeviceMonitor();
CLog.i("Waiting for invocation threads to complete");
waitForAllInvocationThreads();
closeRemoteClient();
if (mRemoteManager != null) {
mRemoteManager.cancelAndWait();
}
exit(manager);
cleanUp();
CLog.logAndDisplay(LogLevel.INFO, "All done")