@Test public void testLifecycleEvent() { Lifecycle mockLifeCycle = mock(Lifecycle.class); when(mockLifeCycle.getState()).thenReturn(LifecycleState.STARTING_PREP); LifecycleEvent mockLifecycleEvent = new LifecycleEvent(mockLifeCycle, "JVM STATE", "JVM STATE DATA"); listener.lifecycleEvent(mockLifecycleEvent); when(mockLifeCycle.getState()).thenReturn(LifecycleState.DESTROYING); listener.lifecycleEvent(mockLifecycleEvent); verify(mockLifeCycle, times(2)).getState(); }
@Override public synchronized void lifecycleEvent(final LifecycleEvent event) { final LifecycleState lifecycleState = event.getLifecycle().getState(); if (h2TcpServerService == null) { h2TcpServerService = new H2TcpServerServiceImpl(tcpServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2TcpServerService.isServerRunning()) { LOGGER.info("Initializing H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2TcpServerService.isServerRunning()) { LOGGER.info("Destroying H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.stopServer(); } try { if (h2WebServerService == null) { h2WebServerService = new H2WebServerServiceImpl(webServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2WebServerService.isServerRunning()) { LOGGER.info("Initializing H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2WebServerService.isServerRunning()) { LOGGER.info("Destroying H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.stopServer(); } } catch (final DbServerServiceException e) { LOGGER.log(Level.SEVERE, "Failed to start H2 Web Server! Continuing without it.", e); } }
H2LifecycleListener implements LifecycleListener { @Override public synchronized void lifecycleEvent(final LifecycleEvent event) { final LifecycleState lifecycleState = event.getLifecycle().getState(); if (h2TcpServerService == null) { h2TcpServerService = new H2TcpServerServiceImpl(tcpServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2TcpServerService.isServerRunning()) { LOGGER.info("Initializing H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2TcpServerService.isServerRunning()) { LOGGER.info("Destroying H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.stopServer(); } try { if (h2WebServerService == null) { h2WebServerService = new H2WebServerServiceImpl(webServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2WebServerService.isServerRunning()) { LOGGER.info("Initializing H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2WebServerService.isServerRunning()) { LOGGER.info("Destroying H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.stopServer(); } } catch (final DbServerServiceException e) { LOGGER.log(Level.SEVERE, "Failed to start H2 Web Server! Continuing without it.", e); } } }
H2LifecycleListener implements LifecycleListener { @Override public synchronized void lifecycleEvent(final LifecycleEvent event) { final LifecycleState lifecycleState = event.getLifecycle().getState(); if (h2TcpServerService == null) { h2TcpServerService = new H2TcpServerServiceImpl(tcpServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2TcpServerService.isServerRunning()) { LOGGER.info("Initializing H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2TcpServerService.isServerRunning()) { LOGGER.info("Destroying H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.stopServer(); } try { if (h2WebServerService == null) { h2WebServerService = new H2WebServerServiceImpl(webServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2WebServerService.isServerRunning()) { LOGGER.info("Initializing H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2WebServerService.isServerRunning()) { LOGGER.info("Destroying H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.stopServer(); } } catch (final DbServerServiceException e) { LOGGER.log(Level.SEVERE, "Failed to start H2 Web Server! Continuing without it.", e); } }  }
H2LifecycleListener implements LifecycleListener { @Override public synchronized void lifecycleEvent(final LifecycleEvent event) { final LifecycleState lifecycleState = event.getLifecycle().getState(); if (h2TcpServerService == null) { h2TcpServerService = new H2TcpServerServiceImpl(tcpServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2TcpServerService.isServerRunning()) { LOGGER.info("Initializing H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2TcpServerService.isServerRunning()) { LOGGER.info("Destroying H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.stopServer(); } try { if (h2WebServerService == null) { h2WebServerService = new H2WebServerServiceImpl(webServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2WebServerService.isServerRunning()) { LOGGER.info("Initializing H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2WebServerService.isServerRunning()) { LOGGER.info("Destroying H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.stopServer(); } } catch (final DbServerServiceException e) { LOGGER.log(Level.SEVERE, "Failed to start H2 Web Server! Continuing without it.", e); } }  @Override synchronized void lifecycleEvent(final LifecycleEvent event); void setTcpServerParam(final String tcpServerParam); void setWebServerParam(final String webServerParam); }
H2LifecycleListener implements LifecycleListener { @Override public synchronized void lifecycleEvent(final LifecycleEvent event) { final LifecycleState lifecycleState = event.getLifecycle().getState(); if (h2TcpServerService == null) { h2TcpServerService = new H2TcpServerServiceImpl(tcpServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2TcpServerService.isServerRunning()) { LOGGER.info("Initializing H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2TcpServerService.isServerRunning()) { LOGGER.info("Destroying H2 tcp server on Tomcat lifecycle: " + lifecycleState); h2TcpServerService.stopServer(); } try { if (h2WebServerService == null) { h2WebServerService = new H2WebServerServiceImpl(webServerParam); } if (LifecycleState.STARTING_PREP.equals(lifecycleState) && !h2WebServerService.isServerRunning()) { LOGGER.info("Initializing H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.startServer(); } else if (LifecycleState.DESTROYING.equals(lifecycleState) && h2WebServerService.isServerRunning()) { LOGGER.info("Destroying H2 web server on Tomcat lifecycle: " + lifecycleState); h2WebServerService.stopServer(); } } catch (final DbServerServiceException e) { LOGGER.log(Level.SEVERE, "Failed to start H2 Web Server! Continuing without it.", e); } }  @Override synchronized void lifecycleEvent(final LifecycleEvent event); void setTcpServerParam(final String tcpServerParam); void setWebServerParam(final String webServerParam);  }