to top
public class

CommandScheduler

extends Thread
implements ICommandScheduler CommandFileWatcher.ICommandFileListener
java.lang.Object
   ↳ java.lang.Thread
     ↳ com.android.tradefed.command.CommandScheduler

Class Overview

A scheduler for running TradeFederation commands across all available devices.

Will attempt to prioritize commands to run based on a total running count of their execution time. e.g. infrequent or fast running commands will get prioritized over long running commands.

Runs forever in background until shutdown.

Summary

Nested Classes
class CommandScheduler.CommandTracker Represents one active command added to the scheduler. 
class CommandScheduler.CommandTrackerIdComparator Comparator for CommandScheduler.CommandTracker
[Expand]
Inherited Constants
From class java.lang.Thread
[Expand]
Inherited Fields
From class java.lang.Thread
Public Constructors
CommandScheduler()
Creates a CommandScheduler.
Public Methods
boolean addCommand(String[] args)
Adds a command to the scheduler.
boolean addCommand(String[] args, long totalExecTime)
An alternate addCommand(String[]) that accepts an initial total execution time for the command.
void addCommandFile(String cmdFilePath, List<String> extraArgs)
Adds all commands from given file to the scheduler
void await()
Waits for scheduler to start running, including waiting for handover from old TF to complete if applicable.
void completeHandover()
Informs the command scheduler that a initiated handover sequence is fully complete, and it should re-initialize its remote manager on the default port.
void displayCommandQueue(PrintWriter printWriter)
Output detailed debug info on state of command execution queue.
void displayCommandsInfo(PrintWriter printWriter, String regex)
Output a list of current commands.
void displayInvocationsInfo(PrintWriter printWriter)
Displays a list of current invocations.
void execCommand(ICommandScheduler.IScheduledInvocationListener listener, ITestDevice device, String[] args)
Directly execute command on already allocated device.
void execCommand(ICommandScheduler.IScheduledInvocationListener listener, String[] args)
Directly allocates a device and executes a command without adding it to the command queue.
synchronized CommandFileWatcher getCommandFileWatcher()
Get the appropriate CommandFileWatcher for this scheduler
void handoverInitiationComplete()
Informs the command scheduler that initial handover exchange of devices and commands in use is complete, and it can begin scheduling operation.
synchronized boolean handoverShutdown(int handoverPort)
Initiates a shutdown() and handover to another tradefed process on this same host.
void notifyFileChanged(File cmdFile, List<String> extraArgs)
synchronized void removeAllCommands()
Remove all commands from scheduler
void run()
The main execution block of this thread.
synchronized void shutdown()
Attempt to gracefully shutdown the command scheduler.
synchronized void shutdownHard()
Attempt to forcefully shutdown the command scheduler.
synchronized void shutdownOnEmpty()
Similar to shutdown(), but will instead wait for all commands to be executed before exiting.
void start()
Starts the scheduler including setting up of logging, init of DeviceManager etc
boolean stopInvocation(ITestInvocation invocation)
Stop a running invocation.
Protected Methods
synchronized boolean isShutdown()
synchronized boolean isShuttingDown()
void processReadyCommands(IDeviceManager manager)
[Expand]
Inherited Methods
From class java.lang.Thread
From class java.lang.Object
From interface java.lang.Runnable
From interface com.android.tradefed.command.ICommandScheduler
From interface com.android.tradefed.command.CommandFileWatcher.ICommandFileListener

Public Constructors

public CommandScheduler ()

Creates a CommandScheduler.

Note: start must be called before use.

Public Methods

public boolean addCommand (String[] args)

Adds a command to the scheduler.

A command is essentially an instance of a configuration to run and its associated arguments.

If "--help" argument is specified the help text for the config will be outputed to stdout. Otherwise, the config will be added to the queue to run.

Parameters
args the config arguments.
Returns
  • true if command was added successfully

public boolean addCommand (String[] args, long totalExecTime)

An alternate addCommand(String[]) that accepts an initial total execution time for the command.

Useful when transitioning pre-existing commands from another tradefed process

Parameters
args the config arguments.
totalExecTime the accumulated elapsed execution time of the command
Returns
  • true if command was added successfully

public void addCommandFile (String cmdFilePath, List<String> extraArgs)

Adds all commands from given file to the scheduler

Parameters
cmdFilePath the filesystem path of comand file
extraArgs a List of String arguments to append to each command parsed from file. Can be empty but should not be null.

public void await ()

Waits for scheduler to start running, including waiting for handover from old TF to complete if applicable.

Throws
InterruptedException

public void completeHandover ()

Informs the command scheduler that a initiated handover sequence is fully complete, and it should re-initialize its remote manager on the default port.

public void displayCommandQueue (PrintWriter printWriter)

Output detailed debug info on state of command execution queue.

public void displayCommandsInfo (PrintWriter printWriter, String regex)

Output a list of current commands.

Parameters
printWriter the PrintWriter to output to.
regex the regular expression to which commands should be matched in order to be printed. If null, then all commands will be printed

public void displayInvocationsInfo (PrintWriter printWriter)

Displays a list of current invocations.

Parameters
printWriter the PrintWriter to output to.

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

Directly execute command on already allocated device.

Parameters
listener the ERROR(/IScheduledInvocationListener) to be informed
device the ITestDevice to use
args the command arguments

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

Directly allocates a device and executes a command without adding it to the command queue.

Parameters
listener the ERROR(/IScheduledInvocationListener) to be informed
args the command arguments

public synchronized CommandFileWatcher getCommandFileWatcher ()

Get the appropriate CommandFileWatcher for this scheduler

public void handoverInitiationComplete ()

Informs the command scheduler that initial handover exchange of devices and commands in use is complete, and it can begin scheduling operation.

public synchronized boolean handoverShutdown (int handoverPort)

Initiates a shutdown() and handover to another tradefed process on this same host.

The scheduler will inform the remote tradefed process listening on that port of freed devices as they become available.

Returns
  • true if handover initiation was successful, false otherwise

public void notifyFileChanged (File cmdFile, List<String> extraArgs)

public synchronized void removeAllCommands ()

Remove all commands from scheduler

public void run ()

The main execution block of this thread.

public synchronized void shutdown ()

Attempt to gracefully shutdown the command scheduler.

Clears commands waiting to be tested, and requests that all invocations in progress shut down gracefully.

After shutdown is called, the scheduler main loop will wait for all invocations in progress to complete before exiting completely.

public synchronized void shutdownHard ()

Attempt to forcefully shutdown the command scheduler.

Similar to shutdown(), but will also forcefully kill the adb connection, in an attempt to 'inspire' invocations in progress to complete quicker.

public synchronized void shutdownOnEmpty ()

Similar to shutdown(), but will instead wait for all commands to be executed before exiting.

Note that if any commands are in loop mode, the scheduler will never exit.

public void start ()

Starts the scheduler including setting up of logging, init of DeviceManager etc

public boolean stopInvocation (ITestInvocation invocation)

Stop a running invocation.

Returns
  • true if the invocation was stopped, false otherwise
Throws
UnsupportedOperationException

Protected Methods

protected synchronized boolean isShutdown ()

protected synchronized boolean isShuttingDown ()

protected void processReadyCommands (IDeviceManager manager)