in agentState-agent/src/main/java/org/jetbrains/teamcity/agentState/AgentStateListener.java [71:112]
public StateUpdater(@NotNull final BuildAgentConfiguration config, @NotNull final State state) {
myState = state;
final File file = new File(config.getCacheDirectory("agent-state"), "current-state");
myThread = new Thread(new Runnable() {
@Override
public void run() {
for (State prevState = null; ; ) {
State currState;
synchronized (myThread) {
currState = myState;
if (prevState == currState) {
if (myIsStopRequest)
break;
try {
myThread.wait();
} catch (InterruptedException ie) {
}
continue;
}
}
try {
FileUtil.writeFileAndReportErrors(file, currState.getValue());
} catch (IOException e) {
LOG.warn(String.format("Failed to update state to %s, try again", currState.name()));
try {
Thread.sleep(50);
} catch (InterruptedException ie) {
}
continue;
}
prevState = currState;
LOG.info(String.format("State was updated to %s", currState.name()));
}
LOG.info("The update thread was exited");
}
});
myThread.setName("AgentStateUpdater");
myThread.setDaemon(true);
myThread.start();
}