org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent Java Examples

The following examples show how to use org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringEventListener.java    From mercury with Apache License 2.0 6 votes vote down vote up
@EventListener
public void handleEvent(Object event) {
    // do optional life-cycle management
    if (event instanceof ServletWebServerInitializedEvent) {
        // when deploy as WAR, this event will not happen
        log.debug("Loading Spring Boot");
    }
    if (event instanceof ApplicationReadyEvent) {
        /*
         * this event will happen in both WAR and JAR deployment mode
         * At this point, Spring Boot is ready
         */
        if (!started) {
            new MainApps().start();
        }
    }
    // in case Spring Boot fails, it does not make sense to keep the rest of the application running.
    if (event instanceof ApplicationFailedEvent) {
        log.error("{}", ((ApplicationFailedEvent) event).getException().getMessage());
        System.exit(-1);
    }
}
 
Example #2
Source File: DiscoveryClientRegistrationInvoker.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(ConfigurableApplicationContext context) {
    if(context instanceof ServletWebServerApplicationContext
            && !AdminEndpointApplicationRunListener.isEmbeddedServletServer(context.getEnvironment())) {
        MetaDataProvider metaDataProvider = context.getBean(MetaDataProvider.class);
        WebServer webServer = new WebServer() {
            @Override
            public void start() throws WebServerException {

            }

            @Override
            public void stop() throws WebServerException {

            }

            @Override
            public int getPort() {
                return metaDataProvider.getServerPort();
            }
        };
        context.publishEvent(
                new ServletWebServerInitializedEvent(
                        webServer,
                        new ServletWebServerApplicationContext())
        );
    }
}
 
Example #3
Source File: NodeService.java    From jblockchain with Apache License 2.0 5 votes vote down vote up
/**
 * Initial setup, query master Node for
 *  - Other Nodes
 *  - All Addresses
 *  - Current Blockchain
 *  - Transactions in pool
 *  and publish self on all other Nodes
 * @param servletWebServerInitializedEvent serverletContainer for port retrieval
 */
@Override
public void onApplicationEvent(ServletWebServerInitializedEvent servletWebServerInitializedEvent) {
    Node masterNode = getMasterNode();

    // construct self node
    String host = retrieveSelfExternalHost(masterNode, restTemplate);
    int port = servletWebServerInitializedEvent.getWebServer().getPort();

    self = getSelfNode(host, port);
    LOG.info("Self address: " + self.getAddress());

    // download data if necessary
    if (self.equals(masterNode)) {
        LOG.info("Running as master node, nothing to init");
    } else {
        knownNodes.add(masterNode);

        // retrieve data
        retrieveKnownNodes(masterNode, restTemplate);
        addressService.retrieveAddresses(masterNode, restTemplate);
        blockService.retrieveBlockchain(masterNode, restTemplate);
        transactionService.retrieveTransactions(masterNode, restTemplate);

        // publish self
        broadcastPut("node", self);
    }
}
 
Example #4
Source File: KubernetesAutoServiceRegistration.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@EventListener(ServletWebServerInitializedEvent.class)
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
	// TODO: take SSL into account
	int localPort = event.getWebServer().getPort();
	if (this.port.get() == 0) {
		log.info("Updating port to " + localPort);
		this.port.compareAndSet(0, localPort);
		start();
	}
}
 
Example #5
Source File: SampleController.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
	this.port = event.getSource().getPort();
}
 
Example #6
Source File: SampleController.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
	this.port = event.getSource().getPort();
}
 
Example #7
Source File: SampleService.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
	this.port = event.getSource().getPort();
}
 
Example #8
Source File: DefaultEndpointLocator.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
	this.port = event.getSource().getPort();
}
 
Example #9
Source File: MultipleHopsIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
	this.port = event.getSource().getPort();
}
 
Example #10
Source File: SleuthBenchmarkingSpringApp.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
	this.port = event.getSource().getPort();
}
 
Example #11
Source File: TraceCustomFilterResponseInjectorTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
	this.port = event.getSource().getPort();
}