Example usage for org.springframework.context ConfigurableApplicationContext stop

List of usage examples for org.springframework.context ConfigurableApplicationContext stop

Introduction

In this page you can find the example usage for org.springframework.context ConfigurableApplicationContext stop.

Prototype

void stop();

Source Link

Document

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.

Usage

From source file:ch.vorburger.mariadb4j.springframework.boot.MariaDB4jApplication.java

public static void main(String[] args) throws Exception {
    SpringApplication app = new SpringApplication(MariaDB4jApplication.class);
    app.setBannerMode(Mode.OFF);/*from   ww w .j ava  2  s  .co m*/
    ConfigurableApplicationContext ctx = app.run(args);

    MariaDB4jService.waitForKeyPressToCleanlyExit();

    ctx.stop();
    ctx.close();
}

From source file:pkg.ContextEventHandlerMain.java

public static void main(String[] args) {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

    // Let us raise a start event.
    context.start();//from w w w. jav  a2s  . c  o  m

    HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
    obj.getMessage();

    // Let us raise a stop event.
    context.stop();

    /*
    ContextStartedEvent Received
    Your Message : Hello World!
    ContextStoppedEvent Received
    */
}

From source file:com.apipulse.bastion.Main.java

public static void main(String[] args) throws IOException, ClassNotFoundException {
    log.info("Bastion starting. Loading chains");
    final File dir = new File("etc/chains");

    final LinkedList<ActorRef> chains = new LinkedList<ActorRef>();
    for (File file : dir.listFiles()) {
        if (!file.getName().startsWith(".") && file.getName().endsWith(".yaml")) {
            log.info("Loading chain: " + file.getName());
            ChainConfig config = new ChainConfig(IOUtils.toString(new FileReader(file)));
            ActorRef ref = BastionActors.getInstance().initChain(config.getName(),
                    Class.forName(config.getQualifiedClass()));
            Iterator<StageConfig> iterator = config.getStages().iterator();
            while (iterator.hasNext())
                ref.tell(iterator.next(), null);
            chains.add(ref);/* w ww . jav  a  2s .c om*/
        }
    }
    SpringApplication app = new SpringApplication();
    HashSet<Object> objects = new HashSet<Object>();
    objects.add(ApiController.class);
    final ConfigurableApplicationContext context = app.run(ApiController.class, args);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                log.info("Bastion shutting down");
                Iterator<ActorRef> iterator = chains.iterator();
                while (iterator.hasNext())
                    iterator.next().tell(new StopMessage(), null);
                Thread.sleep(2000);
                context.stop();
                log.info("Bastion shutdown complete");
            } catch (Exception e) {
            }
        }
    });
}

From source file:org.springframework.amqp.rabbit.admin.RabbitTemplateProducerExample.java

public static void main(String[] args) throws Exception {

    ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(
            RabbitProducerConfiguration.class);
    RabbitTemplate template = ctx.getBean(RabbitTemplate.class);

    for (int i = 1; i <= 10; i++) {
        template.convertAndSend("test-" + i);
        Thread.sleep(100);//from  w  w  w.  java2 s.c  o m
    }
    log.debug("done sending");
    ctx.stop();
    System.exit(0);
}

From source file:org.springframework.cloud.stream.binder.test.integration.EndToEndIntegrationTests.java

@After
public void stopProducerAndConsumers() throws Exception {
    for (ConfigurableApplicationContext startedContext : startedContexts) {
        startedContext.stop();
    }/*w w w  .  j  a  va  2s  . co  m*/
    deprovisionDLQ();
}

From source file:org.springframework.integration.samples.fileprocessing.FileProcessingTest.java

@Test
public void testSequentialFileProcessing() throws Exception {
    logger.info("\n\n#### Starting Sequential processing test ####");
    logger.info("Populating directory with files");
    for (int i = 0; i < fileCount; i++) {
        File file = new File("input/file_" + i + ".txt");
        BufferedWriter out = new BufferedWriter(new FileWriter(file));
        out.write("hello " + i);
        out.close();/*from w  ww. ja  va2 s  . c  o  m*/
    }
    logger.info("Populated directory with files");
    Thread.sleep(2000);
    logger.info("Starting Spring Integration Sequential File processing");
    ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext(
            "META-INF/spring/integration/sequentialFileProcessing-config.xml");
    PollableChannel filesOutChannel = ac.getBean("filesOutChannel", PollableChannel.class);
    for (int i = 0; i < fileCount; i++) {
        logger.info("Finished processing " + filesOutChannel.receive(10000).getPayload());
    }
    ac.stop();
}