@Test public void testOnApplicationEvent() { JMXControl jmxControl = new JMXControl(null); when(appContext.getBean(JMXControl.BEAN_JMX_CONTROL)).thenReturn(jmxControl); setupExportables(); setupGateListeners(); ev.onApplicationEvent(new ContextRefreshedEvent(appContext)); verify(exportable1).export(jmxControl); verify(exportable2).export(jmxControl); verify(gateListener1).onCougarStart(); verify(gateListener2).onCougarStart(); }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { super.onApplicationEvent(event); try { final ApplicationContext ctx = ((ContextRefreshedEvent) event).getApplicationContext(); JMXControl jmxControl = JMXControl.getFromContext(ctx); if (jmxControl == null) { throw new PanicInTheCougar("jmxControl bean not found in ApplicationContext"); } if (exportables != null) { for (Exportable exportable : exportables) { exportable.export(jmxControl); } } notifyStartingGateListeners(); Collection<ServiceAware> serviceAwareImpls = getServiceAwareImplementations(ctx); if (serviceAwareImpls != null && serviceAwareImpls.size() > 0) { Set<Service> services = new HashSet<Service>(); Collection<Map<ServiceDefinition, Service>> serviceDefinitions = getServiceImplementationMap().values(); for (Map<ServiceDefinition, Service> serviceDefinition : serviceDefinitions) { services.addAll(serviceDefinition.values()); } for (ServiceAware serviceAware : serviceAwareImpls) { serviceAware.setServices(services); } } Status status = monitorRegistry .getStatusAggregator() .getStatus(); if (status != Status.OK) { LOGGER.warn("Cougar returned status {} at startup", status); } else { LOGGER.info("Cougar returned status {} at startup", status); } } catch (Exception e) { throw new PanicInTheCougar("Failed to initialise server", e); } logSuccessfulCougarStartup(); } }
ContainerAwareExecutionVenue extends ServiceRegisterableExecutionVenue implements CougarStartingGate, ExportableRegistration { @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { super.onApplicationEvent(event); try { final ApplicationContext ctx = ((ContextRefreshedEvent) event).getApplicationContext(); JMXControl jmxControl = JMXControl.getFromContext(ctx); if (jmxControl == null) { throw new PanicInTheCougar("jmxControl bean not found in ApplicationContext"); } if (exportables != null) { for (Exportable exportable : exportables) { exportable.export(jmxControl); } } notifyStartingGateListeners(); Collection<ServiceAware> serviceAwareImpls = getServiceAwareImplementations(ctx); if (serviceAwareImpls != null && serviceAwareImpls.size() > 0) { Set<Service> services = new HashSet<Service>(); Collection<Map<ServiceDefinition, Service>> serviceDefinitions = getServiceImplementationMap().values(); for (Map<ServiceDefinition, Service> serviceDefinition : serviceDefinitions) { services.addAll(serviceDefinition.values()); } for (ServiceAware serviceAware : serviceAwareImpls) { serviceAware.setServices(services); } } Status status = monitorRegistry .getStatusAggregator() .getStatus(); if (status != Status.OK) { LOGGER.warn("Cougar returned status {} at startup", status); } else { LOGGER.info("Cougar returned status {} at startup", status); } } catch (Exception e) { throw new PanicInTheCougar("Failed to initialise server", e); } logSuccessfulCougarStartup(); } } }
ContainerAwareExecutionVenue extends ServiceRegisterableExecutionVenue implements CougarStartingGate, ExportableRegistration { @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { super.onApplicationEvent(event); try { final ApplicationContext ctx = ((ContextRefreshedEvent) event).getApplicationContext(); JMXControl jmxControl = JMXControl.getFromContext(ctx); if (jmxControl == null) { throw new PanicInTheCougar("jmxControl bean not found in ApplicationContext"); } if (exportables != null) { for (Exportable exportable : exportables) { exportable.export(jmxControl); } } notifyStartingGateListeners(); Collection<ServiceAware> serviceAwareImpls = getServiceAwareImplementations(ctx); if (serviceAwareImpls != null && serviceAwareImpls.size() > 0) { Set<Service> services = new HashSet<Service>(); Collection<Map<ServiceDefinition, Service>> serviceDefinitions = getServiceImplementationMap().values(); for (Map<ServiceDefinition, Service> serviceDefinition : serviceDefinitions) { services.addAll(serviceDefinition.values()); } for (ServiceAware serviceAware : serviceAwareImpls) { serviceAware.setServices(services); } } Status status = monitorRegistry .getStatusAggregator() .getStatus(); if (status != Status.OK) { LOGGER.warn("Cougar returned status {} at startup", status); } else { LOGGER.info("Cougar returned status {} at startup", status); } } catch (Exception e) { throw new PanicInTheCougar("Failed to initialise server", e); } logSuccessfulCougarStartup(); } } ContainerAwareExecutionVenue(); }
ContainerAwareExecutionVenue extends ServiceRegisterableExecutionVenue implements CougarStartingGate, ExportableRegistration { @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { super.onApplicationEvent(event); try { final ApplicationContext ctx = ((ContextRefreshedEvent) event).getApplicationContext(); JMXControl jmxControl = JMXControl.getFromContext(ctx); if (jmxControl == null) { throw new PanicInTheCougar("jmxControl bean not found in ApplicationContext"); } if (exportables != null) { for (Exportable exportable : exportables) { exportable.export(jmxControl); } } notifyStartingGateListeners(); Collection<ServiceAware> serviceAwareImpls = getServiceAwareImplementations(ctx); if (serviceAwareImpls != null && serviceAwareImpls.size() > 0) { Set<Service> services = new HashSet<Service>(); Collection<Map<ServiceDefinition, Service>> serviceDefinitions = getServiceImplementationMap().values(); for (Map<ServiceDefinition, Service> serviceDefinition : serviceDefinitions) { services.addAll(serviceDefinition.values()); } for (ServiceAware serviceAware : serviceAwareImpls) { serviceAware.setServices(services); } } Status status = monitorRegistry .getStatusAggregator() .getStatus(); if (status != Status.OK) { LOGGER.warn("Cougar returned status {} at startup", status); } else { LOGGER.info("Cougar returned status {} at startup", status); } } catch (Exception e) { throw new PanicInTheCougar("Failed to initialise server", e); } logSuccessfulCougarStartup(); } } ContainerAwareExecutionVenue(); @Override void registerExportable(Exportable exportable); @Override void onApplicationEvent(ApplicationEvent event); @Override boolean registerStartingListener(GateListener listener); }
ContainerAwareExecutionVenue extends ServiceRegisterableExecutionVenue implements CougarStartingGate, ExportableRegistration { @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { super.onApplicationEvent(event); try { final ApplicationContext ctx = ((ContextRefreshedEvent) event).getApplicationContext(); JMXControl jmxControl = JMXControl.getFromContext(ctx); if (jmxControl == null) { throw new PanicInTheCougar("jmxControl bean not found in ApplicationContext"); } if (exportables != null) { for (Exportable exportable : exportables) { exportable.export(jmxControl); } } notifyStartingGateListeners(); Collection<ServiceAware> serviceAwareImpls = getServiceAwareImplementations(ctx); if (serviceAwareImpls != null && serviceAwareImpls.size() > 0) { Set<Service> services = new HashSet<Service>(); Collection<Map<ServiceDefinition, Service>> serviceDefinitions = getServiceImplementationMap().values(); for (Map<ServiceDefinition, Service> serviceDefinition : serviceDefinitions) { services.addAll(serviceDefinition.values()); } for (ServiceAware serviceAware : serviceAwareImpls) { serviceAware.setServices(services); } } Status status = monitorRegistry .getStatusAggregator() .getStatus(); if (status != Status.OK) { LOGGER.warn("Cougar returned status {} at startup", status); } else { LOGGER.info("Cougar returned status {} at startup", status); } } catch (Exception e) { throw new PanicInTheCougar("Failed to initialise server", e); } logSuccessfulCougarStartup(); } } ContainerAwareExecutionVenue(); @Override void registerExportable(Exportable exportable); @Override void onApplicationEvent(ApplicationEvent event); @Override boolean registerStartingListener(GateListener listener);  }