@Test public void log_when_started_and_stopped() { Logger logger = mock(Logger.class); TomcatAccessLog.LifecycleLogger listener = new TomcatAccessLog.LifecycleLogger(logger); LifecycleEvent event = new LifecycleEvent(mock(Lifecycle.class), "before_init", null); listener.lifecycleEvent(event); verifyZeroInteractions(logger); event = new LifecycleEvent(mock(Lifecycle.class), "after_start", null); listener.lifecycleEvent(event); verify(logger).debug("Tomcat is started"); event = new LifecycleEvent(mock(Lifecycle.class), "after_destroy", null); listener.lifecycleEvent(event); verify(logger).debug("Tomcat is stopped"); } }
/** * Allow sub classes to fire {@link Lifecycle} events. * * @param type Event type * @param data Data associated with event. */ protected void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(this, type, data); for (LifecycleListener listener : lifecycleListeners) { listener.lifecycleEvent(event); } }
/** * Allow sub classes to fire {@link Lifecycle} events. * * @param type Event type * @param data Data associated with event. */ protected void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(this, type, data); for (LifecycleListener listener : lifecycleListeners) { listener.lifecycleEvent(event); } }
@Override public void notify(String type, Object data) { synchronized (this.monitor) { notify(new LifecycleEvent(this.source, type, data)); } }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = listeners; for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
@Override public void notify(String type, Object data) { synchronized (this.monitor) { notify(new LifecycleEvent(this.source, type, data)); } }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = listeners; for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = listeners; for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = listeners; for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = listeners; for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = listeners; for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = listeners; for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = listeners; for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
protected LifecycleEvent createAfterInitEvent(Lifecycle lifecycle) { return new LifecycleEvent(lifecycle, Lifecycle.AFTER_INIT_EVENT, null); }
protected LifecycleEvent createBeforeDestroyInitEvent(Lifecycle lifecycle) { return new LifecycleEvent(lifecycle, Lifecycle.BEFORE_DESTROY_EVENT, null); }
/** * Notify all lifecycle event listeners that a particular event has * occurred for this Container. The default implementation performs * this notification synchronously using the calling thread. * * @param type Event type * @param data Event data */ public void fireLifecycleEvent(String type, Object data) { LifecycleEvent event = new LifecycleEvent(lifecycle, type, data); LifecycleListener interested[] = null; synchronized (listeners) { interested = (LifecycleListener[]) listeners.clone(); } for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event); }
@Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.START_EVENT.equals(event.getType())) { event = new LifecycleEvent(event.getLifecycle(), Lifecycle.INIT_EVENT, event.getData()); } else if (Lifecycle.STOP_EVENT.equals(event.getType())) { event = new LifecycleEvent(event.getLifecycle(), Lifecycle.AFTER_STOP_EVENT, event.getData()); } super.lifecycleEvent(event); } }
protected void startServer(TomcatEventHandler handler, LifecycleServer server) { Server catalinaServer = mock(Server.class); when(this.factory.createServer(same(server))).thenReturn(catalinaServer); handler.lifecycleEvent(new LifecycleEvent(server, Lifecycle.AFTER_START_EVENT, null)); verify(this.eventHandler).start(same(catalinaServer)); reset(this.eventHandler); }
private static void configureServer(Server server) { //server.addLifecycleListener(new SecurityListener()); //server.addLifecycleListener(new AprLifecycleListener()); LifecycleListener jasperListener = new JasperListener(); server.addLifecycleListener(jasperListener); jasperListener.lifecycleEvent(new LifecycleEvent(server, Lifecycle.BEFORE_INIT_EVENT, null)); server.addLifecycleListener(new JreMemoryLeakPreventionListener()); //server.addLifecycleListener(new GlobalResourcesLifecycleListener()); server.addLifecycleListener(new ThreadLocalLeakPreventionListener()); }
@Test public void startServer() throws Exception { TomcatEventHandler handler = this.createEventHandler(this.eventHandler, this.provider, this.factory); LifecycleServer server = mock(LifecycleServer.class); this.initServer(handler, server); this.startServer(handler, server); handler.lifecycleEvent(new LifecycleEvent(server, Lifecycle.AFTER_START_EVENT, null)); Mockito.verifyZeroInteractions(this.eventHandler); }