hudson.model.Executor#isBusy ( )源码实例Demo

下面列出了hudson.model.Executor#isBusy ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jenkins-test-harness   文件: HudsonTestCase.java
/**
 * Waits until Jenkins finishes building everything, including those builds in the queue, or fail the test
 * if the specified timeout milliseconds is exceeded.
 */
protected void waitUntilNoActivityUpTo(int timeout) throws Exception {
    long startTime = System.currentTimeMillis();
    int streak = 0;

    while (true) {
        Thread.sleep(100);
        if (isSomethingHappening())
            streak=0;
        else
            streak++;

        if (streak>2)   // the system is quiet for a while
            return;

        if (System.currentTimeMillis()-startTime > timeout) {
            List<Executable> building = new ArrayList<Executable>();
            for (Computer c : jenkins.getComputers()) {
                for (Executor e : c.getExecutors()) {
                    if (e.isBusy())
                        building.add(e.getCurrentExecutable());
                }
            }
            throw new AssertionError(String.format("Jenkins is still doing something after %dms: queue=%s building=%s",
                    timeout, Arrays.asList(jenkins.getQueue().getItems()), building));
        }
    }
}
 
public synchronized int abortRunning(int number) throws IllegalAccessException {
        int aborted = 0;

        Computer[] computers = getJenkinsInstance().getComputers();
        for (Computer computer : computers) {
            if (isNull(computer)) {
                continue;
            }

            List<Executor> executors = computer.getExecutors();
            executors.addAll(computer.getOneOffExecutors());

            for (Executor executor : executors) {
                if (isNull(executor) || !executor.isBusy() || nonNull(executor.getCauseOfDeath()) ||
                        !getInterruptCauses(executor).isEmpty() || getInterruptStatus(executor) == Result.ABORTED) {
                    continue;
                }

                Queue.Executable executable = executor.getCurrentExecutable();
                final SubTask parent = executable.getParent();

                if (!(executable instanceof Run)) {
                    continue;
                }
                final Run executableRun = (Run) executable;

                if (!(parent instanceof Job)) {
                    continue;
                }
                final Job parentJob = (Job) parent;

                if (!parentJob.getFullName().equals(job.getFullName())) {
                    // name doesn't match
                    continue;
                }

                if (executableRun.getResult() == Result.ABORTED) {
                    // was already aborted
                    continue;
                }

                if (executableRun instanceof MatrixRun) {
                    // the whole MatrixBuild will be aborted
                    continue;
                }
//                if (executable instanceof MatrixBuild) {
//                    final MatrixBuild executable1 = (MatrixBuild) executable;
//                    executable1.doStop()
//                }

                final GitHubPRCause causeAction = (GitHubPRCause) executableRun.getCause(GitHubPRCause.class);
                if (nonNull(causeAction) && causeAction.getNumber() == number) {
                    LOGGER.info("Aborting '{}', by interrupting '{}'", executableRun, executor);
                    executor.interrupt(Result.ABORTED, new NewPRInterruptCause());
                    aborted++;
                }
            }
        }

        return aborted;
    }