@Override public void run() { boolean healthy = check(); if (healthy) { for (ActiveMQComponent component : componentList) { if (!component.isStarted() && ownShutdown) { try { ActiveMQUtilLogger.LOGGER.startingService(component.toString()); component.start(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStartingComponent(e, component.toString()); } } ownShutdown = false; } } else { for (ActiveMQComponent component : componentList) { if (component.isStarted()) { ownShutdown = true; try { ActiveMQUtilLogger.LOGGER.stoppingService(component.toString()); component.stop(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStoppingComponent(e, component.toString()); } } } } }
protected static final void waitForComponent(final ActiveMQComponent component, final long seconds) throws InterruptedException { long time = System.currentTimeMillis(); long toWait = seconds * 1000; while (!component.isStarted()) { Thread.sleep(50); if (System.currentTimeMillis() > (time + toWait)) { fail("component did not start within timeout of " + seconds); } } }
@Override public void run() { boolean healthy = check(); if (healthy) { for (ActiveMQComponent component : componentList) { if (!component.isStarted() && ownShutdown) { try { ActiveMQUtilLogger.LOGGER.startingService(component.toString()); component.start(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStartingComponent(e, component.toString()); } } ownShutdown = false; } } else { for (ActiveMQComponent component : componentList) { if (component.isStarted()) { ownShutdown = true; try { ActiveMQUtilLogger.LOGGER.stoppingService(component.toString()); component.stop(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStoppingComponent(e, component.toString()); } } } } }
@Override public void run() { boolean healthy = check(); if (healthy) { for (ActiveMQComponent component : componentList) { if (!component.isStarted() && ownShutdown) { try { ActiveMQUtilLogger.LOGGER.startingService(component.toString()); component.start(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStartingComponent(e, component.toString()); } } ownShutdown = false; } } else { for (ActiveMQComponent component : componentList) { if (component.isStarted()) { ownShutdown = true; try { ActiveMQUtilLogger.LOGGER.stoppingService(component.toString()); component.stop(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStoppingComponent(e, component.toString()); } } } } }
@Override public void run() { boolean healthy = check(); if (healthy) { for (ActiveMQComponent component : componentList) { if (!component.isStarted() && ownShutdown) { try { ActiveMQUtilLogger.LOGGER.startingService(component.toString()); component.start(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStartingComponent(e, component.toString()); } } ownShutdown = false; } } else { for (ActiveMQComponent component : componentList) { if (component.isStarted()) { ownShutdown = true; try { ActiveMQUtilLogger.LOGGER.stoppingService(component.toString()); component.stop(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStoppingComponent(e, component.toString()); } } } } }
@Override public void run() { boolean healthy = check(); if (healthy) { for (ActiveMQComponent component : componentList) { if (!component.isStarted() && ownShutdown) { try { ActiveMQUtilLogger.LOGGER.startingService(component.toString()); component.start(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStartingComponent(e, component.toString()); } } ownShutdown = false; } } else { for (ActiveMQComponent component : componentList) { if (component.isStarted()) { ownShutdown = true; try { ActiveMQUtilLogger.LOGGER.stoppingService(component.toString()); component.stop(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStoppingComponent(e, component.toString()); } } } } }
@Override public void run() { boolean healthy = check(); if (healthy) { for (ActiveMQComponent component : componentList) { if (!component.isStarted() && ownShutdown) { try { ActiveMQUtilLogger.LOGGER.startingService(component.toString()); component.start(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStartingComponent(e, component.toString()); } } ownShutdown = false; } } else { for (ActiveMQComponent component : componentList) { if (component.isStarted()) { ownShutdown = true; try { ActiveMQUtilLogger.LOGGER.stoppingService(component.toString()); component.stop(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStoppingComponent(e, component.toString()); } } } } }
@Override public void run() { boolean healthy = check(); if (healthy) { for (ActiveMQComponent component : componentList) { if (!component.isStarted() && ownShutdown) { try { ActiveMQUtilLogger.LOGGER.startingService(component.toString()); component.start(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStartingComponent(e, component.toString()); } } ownShutdown = false; } } else { for (ActiveMQComponent component : componentList) { if (component.isStarted()) { ownShutdown = true; try { ActiveMQUtilLogger.LOGGER.stoppingService(component.toString()); component.stop(); } catch (Exception e) { ActiveMQUtilLogger.LOGGER.errorStoppingComponent(e, component.toString()); } } } } }
@Test public void testCheckUsingHTTP() throws Exception { startHTTPServer(); NetworkHealthCheck check = addCheck(new NetworkHealthCheck(null, 100, 1000)); Assert.assertTrue(check.check(new URL("http://localhost:8787"))); stopHTTPServer(); Assert.assertFalse(check.check(new URL("http://localhost:8787"))); check.addComponent(component); URL url = new URL("http://localhost:8787"); Assert.assertFalse(check.check(url)); startHTTPServer(); Assert.assertTrue(check.check(url)); check.addURL(url); Assert.assertFalse(latch.await(500, TimeUnit.MILLISECONDS)); Assert.assertTrue(component.isStarted()); // stopping the web server should stop the component stopHTTPServer(); Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); Assert.assertFalse(component.isStarted()); latch.setCount(1); startHTTPServer(); Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); Assert.assertTrue(component.isStarted()); }
@Test public void testAlreadyShutdown() throws Exception { assumeTrue(purePingWorks(IPV6_LOCAL)); ReusableLatch latch = new ReusableLatch(0); NetworkHealthCheck check = addCheck(new NetworkHealthCheck(null, 100, 100) { @Override public void run() { super.run(); latch.countDown(); System.out.println("Check"); } }); check.addComponent(component); InetAddress address = InetAddress.getByName("127.0.0.1"); check.addAddress(address); component.stop(); latch.setCount(1); Assert.assertTrue(latch.await(1, TimeUnit.MINUTES)); Assert.assertFalse("NetworkHealthCheck should have no business on restarting the component, the network was never down, hence no check needed!", component.isStarted()); }
Assert.assertTrue(backupServer.getServer().getExternalComponents().get(0).isStarted()); ((ServiceComponent) (backupServer.getServer().getExternalComponents().get(0))).stop(true); } finally {