public synchronized long check()

in core/src/main/java/hudson/slaves/SimpleScheduledRetentionStrategy.java [169:238]


    public synchronized long check(final SlaveComputer c) {
        boolean shouldBeOnline = isOnlineScheduled();
        LOGGER.log(Level.FINE, "Checking computer {0} against schedule. online = {1}, shouldBeOnline = {2}",
                new Object[]{c.getName(), c.isOnline(), shouldBeOnline});
        if (shouldBeOnline && c.isOffline()) {
            LOGGER.log(INFO, "Trying to launch computer {0} as schedule says it should be on-line at "
                    + "this point in time", new Object[]{c.getName()});
            if (c.isLaunchSupported()) {
                Computer.threadPoolForRemoting.submit(new Runnable() {
                    public void run() {
                        try {
                            c.connect(true).get();
                            if (c.isOnline()) {
                                LOGGER.log(INFO, "Launched computer {0} per schedule", new Object[]{c.getName()});
                            }
                            if (keepUpWhenActive && c.isOnline() && !c.isAcceptingTasks()) {
                                LOGGER.log(INFO,
                                        "Enabling new jobs for computer {0} as it has started its scheduled uptime",
                                        new Object[]{c.getName()});
                                c.setAcceptingTasks(true);
                            }
                        } catch (InterruptedException | ExecutionException e) {
                        }
                    }
                });
            }
        } else if (!shouldBeOnline && c.isOnline()) {
            if (keepUpWhenActive) {
                if (!c.isIdle() && c.isAcceptingTasks()) {
                    c.setAcceptingTasks(false);
                    LOGGER.log(INFO,
                            "Disabling new jobs for computer {0} as it has finished its scheduled uptime",
                            new Object[]{c.getName()});
                    return 1;
                } else if (c.isIdle() && c.isAcceptingTasks()) {
                    Queue.withLock(new Runnable() {
                        @Override
                        public void run() {
                            if (c.isIdle()) {
                                LOGGER.log(INFO, "Disconnecting computer {0} as it has finished its scheduled uptime",
                                        new Object[]{c.getName()});
                                c.disconnect(OfflineCause
                                        .create(Messages._SimpleScheduledRetentionStrategy_FinishedUpTime()));
                            } else {
                                c.setAcceptingTasks(false);
                            }
                        }
                    });
                } else if (c.isIdle() && !c.isAcceptingTasks()) {
                    Queue.withLock(new Runnable() {
                        @Override
                        public void run() {
                            if (c.isIdle()) {
                                LOGGER.log(INFO, "Disconnecting computer {0} as it has finished all jobs running when "
                                        + "it completed its scheduled uptime", new Object[]{c.getName()});
                                c.disconnect(OfflineCause
                                        .create(Messages._SimpleScheduledRetentionStrategy_FinishedUpTime()));
                            }
                        }
                    });
                }
            } else {
                // no need to get the queue lock as the user has selected the break builds option!
                LOGGER.log(INFO, "Disconnecting computer {0} as it has finished its scheduled uptime",
                        new Object[]{c.getName()});
                c.disconnect(OfflineCause.create(Messages._SimpleScheduledRetentionStrategy_FinishedUpTime()));
            }
        }
        return 1;
    }