Skip to content

Commit

Permalink
[JENKINS-38678] Properly remove administrative monitors from the Exte…
Browse files Browse the repository at this point in the history
…nsionList (#2577)

* [JENKINS-38678] Remove properly administrative monitor

previous impl didn't work because ExtensionList#iterator() returns a
readonly iterator.

* Use foreach loop
  • Loading branch information
Vlatombe authored and oleg-nenashev committed Oct 10, 2016
1 parent 67df10d commit d868256
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -1214,16 +1214,19 @@ private void launchTcpSlaveAgentListener() throws IOException {
tcpSlaveAgentListener = null;
}
if (slaveAgentPort != -1 && tcpSlaveAgentListener == null) {
String administrativeMonitorId = getClass().getName() + ".tcpBind";
final String administrativeMonitorId = getClass().getName() + ".tcpBind";
try {
tcpSlaveAgentListener = new TcpSlaveAgentListener(slaveAgentPort);
// remove previous monitor in case of previous error
for (Iterator<AdministrativeMonitor> it = AdministrativeMonitor.all().iterator(); it.hasNext(); ) {
AdministrativeMonitor am = it.next();
AdministrativeMonitor toBeRemoved = null;
ExtensionList<AdministrativeMonitor> all = AdministrativeMonitor.all();
for (AdministrativeMonitor am : all) {
if (administrativeMonitorId.equals(am.id)) {
it.remove();
toBeRemoved = am;
break;
}
}
all.remove(toBeRemoved);
} catch (BindException e) {
LOGGER.log(Level.WARNING, String.format("Failed to listen to incoming agent connections through JNLP port %s. Change the JNLP port number", slaveAgentPort), e);
new AdministrativeError(administrativeMonitorId,
Expand Down

0 comments on commit d868256

Please sign in to comment.