List of usage examples for org.springframework.context.support AbstractApplicationContext close
@Override public void close()
From source file:org.opennms.poller.remote.Main.java
private static void shutdownContextAndExit(AbstractApplicationContext context) { int returnCode = 0; // MVR: gracefully shutdown scheduler, otherwise context.close() will raise // an exception. See #NMS-6966 for more details. if (context.isActive()) { // If there is a scheduler in the context, then shut it down Scheduler scheduler = (Scheduler) context.getBean("scheduler"); if (scheduler != null) { try { LOG.info("Shutting down PollerFrontEnd scheduler"); scheduler.shutdown();/*from ww w . java 2 s . com*/ LOG.info("PollerFrontEnd scheduler shutdown complete"); } catch (SchedulerException ex) { LOG.warn("Shutting down PollerFrontEnd scheduler failed", ex); returnCode = 10; } } // Now close the application context. This will invoke // {@link DefaultPollerFrontEnd#destroy()} which will mark the // remote poller as "Stopped" during shutdown instead of letting // it remain in the "Disconnected" state. context.close(); } final int returnCodeValue = returnCode; new Thread() { public void run() { // Sleep for a couple of seconds so that the other // PropertyChangeListeners get a chance to fire try { Thread.sleep(5000); } catch (InterruptedException e) { } // Exit System.exit(returnCodeValue); } }.start(); }
From source file:org.springframework.integration.samples.advice.CircuitBreakerDemo.java
public static void main(String[] args) throws Exception { 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/circuit-breaker-advice-context.xml"); context.registerShutdownHook();/*from ww w . j ava 2s .c om*/ LOGGER.info("\n=========================================================" + "\n " + "\n This is the Circuit Breaker Sample - " + "\n " + "\n Please enter some text and press return a few times. " + "\n Service will succeed only in the last quarter " + "\n minute. Breaker will open after 2 failures and " + "\n will go half-open after 15 seconds. " + "\n Demo will terminate in 2 minutes. " + "\n " + "\n========================================================="); Thread.sleep(120000); context.close(); }
From source file:org.springframework.integration.samples.advice.StatefulRetryDemo.java
public static void main(String[] args) throws Exception { 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/stateful-retry-advice-context.xml"); context.registerShutdownHook();/*from w w w . j a v a 2s. c o m*/ LOGGER.info("\n=========================================================" + "\n " + "\n This is the Stateful Sample - " + "\n " + "\n Please enter some text and press return. " + "\n 'fail 2' will fail twice, then succeed " + "\n 'fail 3' will fail and never succeed " + "\n Demo will terminate in 60 seconds. " + "\n " + "\n========================================================="); Thread.sleep(60000); context.close(); }
From source file:org.springframework.integration.samples.advice.StatelessRetryDemo.java
public static void main(String[] args) throws Exception { 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/stateless-retry-advice-context.xml"); context.registerShutdownHook();/*from w w w . java2s . co m*/ LOGGER.info("\n=========================================================" + "\n " + "\n This is the Stateless Sample - " + "\n " + "\n Please enter some text and press return. " + "\n 'fail 2' will fail twice, then succeed " + "\n 'fail 3' will fail and never succeed " + "\n Demo will terminate in 60 seconds. " + "\n " + "\n========================================================="); Thread.sleep(60000); context.close(); }
From source file:org.springframework.integration.samples.advice.TransactionSynchronizationDemo.java
public static void main(String[] args) throws Exception { 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/transaction-synch-context.xml"); context.registerShutdownHook();/*w w w. ja va2s .co m*/ LOGGER.info("\n=========================================================" + "\n " + "\n This is the Transaction Synchronization Sample - " + "\n " + "\n Press 'Enter' to terminate. " + "\n " + "\n Place a file in " + System.getProperty("java.io.tmpdir") + "/txSynchDemo ending " + "\n with .txt " + "\n If the first line begins with 'fail' the transaction " + "\n transaction will be rolled back.The result of the " + "\n expression evaluation is logged. " + "\n " + "\n========================================================="); System.out.println(System.getProperty("java.io.tmpdir") + "/txSynchDemo"); System.in.read(); context.close(); }
From source file:org.springframework.integration.samples.cafe.demo.ControlBusMain.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/integration/cafeDemo-control-bus.xml"); WaiterMonitor waiterMonitor = (WaiterMonitor) context.getBean("waiterMonitor"); int totalDeliveries = 0; while (totalDeliveries <= 3) { try {/*w ww . ja v a 2 s .c om*/ Thread.sleep(1000); } catch (InterruptedException e) { logger.error("Interrupted", e); } totalDeliveries = (Integer) waiterMonitor.sendControlScript("waiter.totalDeliveries"); logger.info("Total cafe deliveries: " + totalDeliveries); if (totalDeliveries > 3) { logger.info("stopping orders..."); waiterMonitor.sendControlScript("cafe.stop()"); logger.info("orders stopped"); } } context.close(); System.exit(0); }
From source file:org.springframework.integration.samples.enricher.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments// w w w . j a v a2s .c o m */ public static void main(final String... args) { LOGGER.info(LINE_SEPARATOR + EMPTY_LINE + "\n Welcome to Spring Integration! " + EMPTY_LINE + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + EMPTY_LINE + LINE_SEPARATOR); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final UserService service = context.getBean(UserService.class); LOGGER.info(LINE_SEPARATOR + EMPTY_LINE + "\n Please press 'q + Enter' to quit the application. " + EMPTY_LINE + LINE_SEPARATOR + EMPTY_LINE + "\n This example illustrates the usage of the Content Enricher. " + EMPTY_LINE + "\n Usage: Please enter 1 or 2 or 3 + Enter " + EMPTY_LINE + "\n 3 different message flows are triggered. For sample 1+2 a " + "\n user object containing only the username is passed in. " + "\n For sample 3 a Map with the 'username' key is passed in and enriched " + "\n with the user object using the 'user' key. " + EMPTY_LINE + "\n 1: In the Enricher, pass the full User object to the request channel. " + "\n 2: In the Enricher, pass only the username to the request channel. " + "\n 3: In the Enricher, pass only the username to the request channel. " + EMPTY_LINE + LINE_SEPARATOR); while (!scanner.hasNext("q")) { final String input = scanner.nextLine(); User user = new User("foo", null, null); if ("1".equals(input)) { final User fullUser = service.findUser(user); printUserInformation(fullUser); } else if ("2".equals(input)) { final User fullUser = service.findUserByUsername(user); printUserInformation(fullUser); } else if ("3".equals(input)) { final Map<String, Object> userData = new HashMap<String, Object>(); userData.put("username", "foo_map"); final Map<String, Object> enrichedUserData = service.findUserWithUsernameInMap(userData); final User fullUser = (User) enrichedUserData.get("user"); printUserInformation(fullUser); } else { LOGGER.info("\n\n Please enter '1', '2', or '3' <enter>:\n\n"); } } LOGGER.info("\n\nExiting application...bye."); scanner.close(); context.close(); }
From source file:org.springframework.integration.samples.helloworld.HelloWorldApp.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class); MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class); PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class); inputChannel.send(new GenericMessage<String>("World")); logger.info("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload()); context.close(); }
From source file:org.springframework.integration.samples.jdbc.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from ww w .j av a 2 s . c om*/ */ 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 Scanner scanner = new Scanner(System.in); final PersonService personService = context.getBean(PersonService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.println("Please enter a choice and press <enter>: "); System.out.println("\t1. Find person details"); System.out.println("\t2. Create a new person detail"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); while (true) { final String input = scanner.nextLine(); if ("1".equals(input.trim())) { getPersonDetails(scanner, personService); } else if ("2".equals(input.trim())) { createPersonDetails(scanner, personService); } else if ("q".equals(input.trim())) { break; } else { System.out.println("Invalid choice\n\n"); } System.out.println("Please enter a choice and press <enter>: "); System.out.println("\t1. Find person details"); System.out.println("\t2. Create a new person detail"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); } LOGGER.info("Exiting application...bye."); context.close(); }
From source file:org.springframework.integration.samples.mailattachments.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from w w w. jav a 2 s.c om*/ */ public static void main(final String... args) { LOGGER.info(HORIZONTAL_LINE + "\n" + "\n Welcome to Spring Integration! " + "\n" + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n" + HORIZONTAL_LINE); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); LOGGER.info(HORIZONTAL_LINE + "\n" + "\n Please press 'q + Enter' to quit the application. " + "\n" + HORIZONTAL_LINE); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } } LOGGER.info("Exiting application...bye."); scanner.close(); context.close(); }