@Override
	public void onApplicationEvent(ApplicationEvent event) {
		if (event instanceof ContextRefreshedEvent) {
            super.onApplicationEvent(event);
            try {
                final ApplicationContext ctx = ((ContextRefreshedEvent) event).getApplicationContext();
				// Check that the JMXControl exists before registering all exportables
				// see JMXControl javadocs for why we have to do it this way
				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);
					}
				}

				// Open the starting gate
				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();
		}
	}
@ 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 ( ) ; } }
In the case of ContextRefreshedEvent (that is, once all Spring configuration is loaded), the following actions
will be taken:
<list>
<li>the superclass's onAppEvent will initialise all services</li>
<li>The JMXControl will be retrieved from the application context and all registered Exportable implementations will be exported</li>
<li>All registered StartingGateListeners will be notified that the starting gate is open</li>
<li>A status check will be made on every registered service, with the status logged</li>
</list>