Example usage for org.springframework.context.support AbstractApplicationContext close

List of usage examples for org.springframework.context.support AbstractApplicationContext close

Introduction

In this page you can find the example usage for org.springframework.context.support AbstractApplicationContext close.

Prototype

@Override
public void close() 

Source Link

Document

Close this application context, destroying all beans in its bean factory.

Usage

From source file:org.springframework.integration.samples.poller.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/*w ww  .j  av a 2s.  co  m*/
 */
public static void main(final String... args) {

    LOGGER.info("\n=========================================================="
            + "\n                                                          "
            + "\n Welcome to the Spring Integration Dynamic Poller Sample! "
            + "\n                                                          "
            + "\n    For more information please visit:                    "
            + "\n    http://www.springsource.org/spring-integration        "
            + "\n                                                          "
            + "\n==========================================================");

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    final Scanner scanner = new Scanner(System.in);

    final DynamicPeriodicTrigger trigger = context.getBean(DynamicPeriodicTrigger.class);

    LOGGER.info("\n========================================================="
            + "\n                                                         "
            + "\n    Please press 'q + Enter' to quit the application.    "
            + "\n                                                         "
            + "\n=========================================================");

    System.out.print("Please enter a non-negative numeric value and press <enter>: ");

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        }

        try {

            int triggerPeriod = Integer.valueOf(input);

            System.out.println(String.format("Setting trigger period to '%s' ms", triggerPeriod));

            trigger.setPeriod(triggerPeriod);

        } catch (Exception e) {
            LOGGER.error("An exception was caught: " + e);
        }

        System.out.print("Please enter a non-negative numeric value and press <enter>: ");

    }

    LOGGER.info("Exiting application...bye.");

    scanner.close();
    context.close();

}

From source file:org.springframework.integration.samples.splitteraggregator.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/*from w  w  w  . j  a v  a2  s.c  o  m*/
 */
public static void main(final String... args) {

    LOGGER.info("\n========================================================="
            + "\n                                                         "
            + "\n          Welcome to Spring Integration!                 "
            + "\n                                                         "
            + "\n    For more information please visit:                   "
            + "\n    http://www.springsource.org/spring-integration       "
            + "\n                                                         "
            + "\n=========================================================");

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    final SearchRequestor searchRequestor = context.getBean(SearchRequestor.class);
    final SearchA searchA = context.getBean(SearchA.class);
    final SearchB searchB = context.getBean(SearchB.class);

    final Scanner scanner = new Scanner(System.in);

    System.out.println("Please enter a choice and press <enter>: ");
    System.out.println("\t1. Submit 2 search queries, 2 results returned.");
    System.out.println("\t2. Submit 2 search queries, 1 search query takes too long, 1 result returned.");
    System.out.println("\t3. Submit 2 search queries, 2 search queries take too long, 0 results returned.");

    System.out.println("\tq. Quit the application");
    System.out.print("Enter your choice: ");

    while (true) {
        final String input = scanner.nextLine();

        if ("1".equals(input.trim())) {
            searchA.setExecutionTime(1000L);
            searchB.setExecutionTime(1000L);
            final CompositeResult result = searchRequestor.search(TestUtils.getCompositeCriteria());
            System.out.println("Number of Search Results: " + result.getResults().size());
        } else if ("2".equals(input.trim())) {
            searchA.setExecutionTime(6000L);
            searchB.setExecutionTime(1000L);
            final CompositeResult result = searchRequestor.search(TestUtils.getCompositeCriteria());
            System.out.println("Number of Search Results: " + result.getResults().size());
        } else if ("3".equals(input.trim())) {
            searchA.setExecutionTime(6000L);
            searchB.setExecutionTime(6000L);
            final CompositeResult result = searchRequestor.search(TestUtils.getCompositeCriteria());
            System.out.println("Result is null: " + (result == null));
        } else if ("q".equals(input.trim())) {
            break;
        } else {
            System.out.println("Invalid choice\n\n");
        }

    }

    System.out.println("Exiting application...bye.");
    scanner.close();
    context.close();

}

From source file:org.springframework.integration.samples.storedprocedure.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/*from   www .  j a  va2 s . c  om*/
 */
public static void main(final String... args) {

    LOGGER.info(LINE + LINE + "\n    Welcome to Spring Integration Coffee Database!       " + NEWLINE
            + "\n    For more information please visit:                   "
            + "\n    http://www.springsource.org/spring-integration       " + NEWLINE + LINE);

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    final Scanner scanner = new Scanner(System.in);

    final CoffeeService service = context.getBean(CoffeeService.class);

    LOGGER.info(LINE + NEWLINE + "\n    Please press 'q + Enter' to quit the application." + NEWLINE + LINE);

    System.out.print("Please enter 'list' and press <enter> to get a list of coffees.");
    System.out.print("Enter a coffee id, e.g. '1' and press <enter> to get a description.\n\n");

    while (!scanner.hasNext("q")) {

        String input = scanner.nextLine();

        if ("list".equalsIgnoreCase(input)) {
            List<CoffeeBeverage> coffeeBeverages = service.findAllCoffeeBeverages();

            for (CoffeeBeverage coffeeBeverage : coffeeBeverages) {
                System.out.println(String.format("%s - %s", coffeeBeverage.getId(), coffeeBeverage.getName()));
            }

        } else {
            System.out.println("Retrieving coffee information...");
            String coffeeDescription = service.findCoffeeBeverage(Integer.valueOf(input));

            System.out.println(String.format("Searched for '%s' - Found: '%s'.", input, coffeeDescription));
            System.out.print("To try again, please enter another coffee beverage and press <enter>:\n\n");
        }

    }

    LOGGER.info("Exiting application...bye.");

    scanner.close();
    context.close();

}

From source file:org.springframework.samples.hadoop.hive.HiveClientApp.java

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/hive-context.xml",
            HiveClientApp.class);
    log.info("Hive Application Running");
    context.registerShutdownHook();/*from w w w .  j a  v  a2 s . c  o m*/

    HiveTemplate template = context.getBean(HiveTemplate.class);
    template.query("show tables;");

    PasswordRepository repository = context.getBean(HiveClientPasswordRepository.class);
    repository.processPasswordFile("/user/hive/input/passwd");
    log.info("Count of password entries = " + repository.count());
    context.close();
    log.info("Hive Application Completed");
}

From source file:ro.nextreports.server.web.ApplicationLoaderListener.java

private static void updateStorage() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Update storage...");
    }//from w w w .  j ava 2  s  .c  o  m
    try {
        long t = System.currentTimeMillis();

        String[] paths = { UPDATE_CONTEXT_PATH };
        AbstractApplicationContext updateContext = new ClassPathXmlApplicationContext(paths);

        updateContext.getBean("updater");
        updateContext.close();

        t = System.currentTimeMillis() - t;
        if (LOG.isDebugEnabled()) {
            LOG.debug("Updated storage in " + t + " ms");
        }

    } catch (Throwable tex) {
        LOG.error(tex.getMessage(), tex);
    }

}