Source:
public void run() { ApplicationInfo applicationInfo = applicationRepository.findOne(appUid.toString()); if (applicationInfo == null) { log.error("ApplicationInfo is null, this should never happen!"); stopTask(); } else { switch (applicationInfo.getStateMachine().getState()) { case IGNORED: log.debug("App has been unbound. Cancelling task."); stopTask(); applicationInfo.markAsChecked(null); applicationRepository.save(applicationInfo); break; case MONITORED: ApplicationActivity applicationActivity = cloudFoundryApi.getApplicationActivity(appUid); Instant nextCheckTime; if (applicationActivity != null) { log.debug("Checking on app state, for bindingId {}", appUid, bindingId); applicationInfo.updateRemoteInfo(applicationActivity); if (applicationActivity.getState() == CloudApplication.AppState.STOPPED) { log.debug("App already stopped."); nextCheckTime = rescheduleWithDefaultPeriod(); } else { Instant lastEvent = LastDateComputer.computeLastDate(applicationActivity .getLastLog(), applicationActivity.getLastEvent()); if (lastEvent != null) { Instant nextIdleTime = lastEvent.plus(getPeriod()); log.debug("last event: {}", lastEvent.toString()); if (nextIdleTime.isBefore(Instant.now())) { log.info("Stopping app [{} / {}], last event: {}, last log: {}", applicationActivity.getApplication().getName(), appUid, applicationActivity.getLastEvent(), applicationActivity.getLastLog()); cloudFoundryApi.stopApplication(appUid); applicationInfo.markAsPutToSleep(); nextCheckTime = rescheduleWithDefaultPeriod(); } else { Duration delta = Duration.between(Instant.now(), nextIdleTime); nextCheckTime = reschedule(delta); } } else { log.error("cannot find last event"); nextCheckTime = rescheduleWithDefaultPeriod(); } } } else { log.debug("failed to retrieve application activity informations"); nextCheckTime = rescheduleWithDefaultPeriod(); } applicationInfo.markAsChecked(nextCheckTime); applicationRepository.save(applicationInfo); break; default: log.error("unkown state"); } } }

Target:
public void run() { ApplicationInfo applicationInfo = applicationRepository.findOne(appUid.toString()); if (applicationInfo == null) { log.error("ApplicationInfo is null, this should never happen!"); stopTask(); } else { switch (applicationInfo.getStateMachine().getState()) { case IGNORED: log.debug("App has been unbound. Cancelling task."); stopTask(); applicationInfo.clearCheckInformation(); applicationRepository.save(applicationInfo); break; case MONITORED: ApplicationActivity applicationActivity = cloudFoundryApi.getApplicationActivity(appUid); Instant nextCheckTime; if (applicationActivity != null) { log.debug("Checking on app state, for bindingId {}", appUid, bindingId); applicationInfo.updateRemoteInfo(applicationActivity); if (applicationActivity.getState() == CloudApplication.AppState.STOPPED) { log.debug("App already stopped."); nextCheckTime = rescheduleWithDefaultPeriod(); } else { Instant lastEvent = LastDateComputer.computeLastDate(applicationActivity .getLastLog(), applicationActivity.getLastEvent()); if (lastEvent != null) { Instant nextIdleTime = lastEvent.plus(getPeriod()); log.debug("last event: {}", lastEvent.toString()); if (nextIdleTime.isBefore(Instant.now())) { log.info("Stopping app [{} / {}], last event: {}, last log: {}", applicationActivity.getApplication().getName(), appUid, applicationActivity.getLastEvent(), applicationActivity.getLastLog()); cloudFoundryApi.stopApplication(appUid); applicationInfo.markAsPutToSleep(); nextCheckTime = rescheduleWithDefaultPeriod(); } else { Duration delta = Duration.between(Instant.now(), nextIdleTime); nextCheckTime = reschedule(delta); } } else { log.error("cannot find last event"); nextCheckTime = rescheduleWithDefaultPeriod(); } } } else { log.debug("failed to retrieve application activity informations"); nextCheckTime = rescheduleWithDefaultPeriod(); } applicationInfo.markAsChecked(nextCheckTime); applicationRepository.save(applicationInfo); break; default: log.error("unkown state"); } } }