Source:
<code>public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { String namespace = ((EmbeddedWebApplicationContext) event.getSource()).getNamespace(); if (!MGMT_CONTEXT_NAMESPACE.equals(namespace)) { this.applicationContext = ((ContextRefreshedEvent) event).getApplicationContext(); String delay = this.applicationContext.getEnvironment().getProperty(QUIET_PERIOD_PROPERTY); if (StringUtils.hasText(delay)) { quietPeriod.set(Long.parseLong(delay)); logger.info("Set container quiet period to ms", delay); } if (this.zkConnection.isConnected()) { <START> if (this.applicationContext.equals(((ContextRefreshedEvent) event).getApplicationContext())) { <END> registerWithZooKeeper(zkConnection.getClient()); } requestLeadership(this.zkConnection.getClient()); } this.zkConnection.addListener(connectionListener); } } else if (event instanceof ContextStoppedEvent) { if (this.leaderSelector != null) { this.leaderSelector.close(); } } else if (event instanceof EmbeddedServletContainerInitializedEvent) { String namespace = ((EmbeddedServletContainerInitializedEvent) event).getApplicationContext().getNamespace(); int port = ((EmbeddedServletContainerInitializedEvent) event).getEmbeddedServletContainer().getPort(); synchronized (adminAttributes) { if (MGMT_CONTEXT_NAMESPACE.equals(namespace)) { adminAttributes.setManagementPort(port); } else { adminAttributes.setPort(port); } if (zkConnection.isConnected() && adminRepository.exists(adminAttributes.getId())) { adminRepository.update(new Admin(adminAttributes.getId(), adminAttributes)); } } } }</code><technical_language>this is redundant. this.applicationContext is populated of previous lines: this.applicationContext = ((ContextRefreshedEvent) event).getApplicationContext();</technical_language>

Target:
public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { String namespace = ((EmbeddedWebApplicationContext) event.getSource()).getNamespace(); if (!MGMT_CONTEXT_NAMESPACE.equals(namespace)) { this.applicationContext = ((ContextRefreshedEvent) event).getApplicationContext(); String delay = this.applicationContext.getEnvironment().getProperty(QUIET_PERIOD_PROPERTY); if (StringUtils.hasText(delay)) { quietPeriod.set(Long.parseLong(delay)); logger.info("Set container quiet period to ms", delay); } if (this.zkConnection.isConnected()) { registerWithZooKeeper(zkConnection.getClient()); requestLeadership(this.zkConnection.getClient()); } this.zkConnection.addListener(connectionListener); } } else if (event instanceof ContextStoppedEvent) { if (this.leaderSelector != null) { this.leaderSelector.close(); } } else if (event instanceof EmbeddedServletContainerInitializedEvent) { String namespace = ((EmbeddedServletContainerInitializedEvent) event).getApplicationContext().getNamespace(); int port = ((EmbeddedServletContainerInitializedEvent) event).getEmbeddedServletContainer().getPort(); synchronized (adminAttributes) { if (MGMT_CONTEXT_NAMESPACE.equals(namespace)) { adminAttributes.setManagementPort(port); } else { adminAttributes.setPort(port); } if (zkConnection.isConnected() && adminRepository.exists(adminAttributes.getId())) { adminRepository.update(new Admin(adminAttributes.getId(), adminAttributes)); } } } }