List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext stop
@Override public void stop()
From source file:com.apress.prospringintegration.social.twitter.TwitterOutbound.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/spring/twitter/twitter-outbound.xml", TwitterOutbound.class); MessageChannel input = context.getBean("twitterOutbound", MessageChannel.class); Message<String> message = MessageBuilder .withPayload("Only can send message once " + Calendar.getInstance().getTimeInMillis()).build(); input.send(message);/*from w w w .jav a2 s.c om*/ context.stop(); }
From source file:com.apress.prospringintegration.social.twitter.TwitterDmOutbound.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/spring/twitter/twitter-outbound.xml", TwitterOutbound.class); MessageChannel input = context.getBean("twitterOutbound", MessageChannel.class); Message<String> message = MessageBuilder.withPayload("This is a test") .setHeader(TwitterHeaders.DM_TARGET_USER_ID, "@prosibook").build(); input.send(message);//from www. j ava2s. c o m context.stop(); }
From source file:com.apress.prospringintegration.jmx.JmxOperationGateway.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmx/operation-gateway.xml"); Map<String, Integer> parameters = new HashMap<String, Integer>(); parameters.put("p1", 5); parameters.put("p2", 7); MessageChannel request = (MessageChannel) context.getBean("request"); request.send(MessageBuilder.withPayload(parameters).build()); try {//from ww w .j a v a2 s .com Thread.sleep(180000); } catch (InterruptedException e) { //do nothing } context.stop(); }
From source file:com.apress.prospringintegration.monitoring.MonitoringExample.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:monitoring/monitoring.xml"); ProcessMessage processMessage = context.getBean("processMessage", ProcessMessage.class); for (int i = 0; i < 10; i++) { processMessage.processMessage("Process"); processMessage.checkMessage("Check"); }// w w w.j a v a 2 s .com while (true) { try { Thread.sleep(60000); } catch (InterruptedException e) { //do nothing } context.stop(); } }
From source file:com.apress.prospringintegration.jmx.JmxNotificationPublisher.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "jmx/notification-publisher.xml"); try {/*from ww w . ja va2 s .co m*/ Thread.sleep(60000); } catch (InterruptedException e) { //do nothing } System.out.println("Sending message"); MessageChannel send = context.getBean("send", MessageChannel.class); send.send(MessageBuilder.withPayload("Sample Message").build()); try { Thread.sleep(180000); } catch (InterruptedException e) { //do nothing } context.stop(); }
From source file:com.roncoo.pay.app.settlement.SettTask.java
public static void main(String[] args) { try {//from ww w . ja va 2 s.c o m @SuppressWarnings("resource") final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "spring-context.xml" }); context.start(); LOG.debug(""); SettScheduled settScheduled = (SettScheduled) context.getBean("settScheduled"); LOG.debug("(??)"); settScheduled.launchDailySettCollect(); LOG.debug("(??)?"); Thread.sleep(MILLIS); LOG.debug("()"); settScheduled.launchAutoSett(); LOG.debug("()?"); context.stop(); } catch (Exception e) { LOG.error("SettTask execute error:", e); } finally { System.exit(0); LOG.debug("SettTask Complete"); } }
From source file:com.nokia.dempsy.spring.RunAppInVm.java
public static void run(String[] args) throws Throwable { //====================================================== // Handle all of the options. String appCtxFilename = System.getProperty(appdefParam); if (appCtxFilename == null || appCtxFilename.length() == 0) { // usage("the java vm option \"-D" + appdefParam + "\" wasn't specified."); String application = System.getProperty(applicationParam); if (application == null || application.length() == 0) usage("the java vm option \"-D" + appdefParam + "\" or the java vm option \"-D" + applicationParam + "\" wasn't specified."); appCtxFilename = "DempsyApplicationContext-" + application + ".xml"; }//from w w w . j a va 2s . c o m //====================================================== String contextFile = "classpath:Dempsy-localVm.xml"; ClassPathXmlApplicationContext context = null; try { // Initialize Spring context = new ClassPathXmlApplicationContext(new String[] { appCtxFilename, contextFile }); context.registerShutdownHook(); } catch (Throwable e) { logger.error(MarkerFactory.getMarker("FATAL"), "Failed to start the application ", e); throw e; } if (context != null) { try { context.getBean(Dempsy.class).waitToBeStopped(); } catch (InterruptedException e) { logger.error("Interrupted . . . ", e); } finally { context.stop(); } logger.info("Shut down dempsy appliction " + appCtxFilename + ", bye!"); } }
From source file:com.nokia.dempsy.spring.RunNode.java
public static void run(String[] args) throws Throwable { //====================================================== // Handle all of the options. String application = System.getProperty(applicationParam); if (application == null || application.length() == 0) usage("the java vm option \"-D" + applicationParam + "\" wasn't specified."); String[] clusterIdParts = application.split(":"); if (clusterIdParts.length != 2) usage("invalid format for the -Dcluster option. It should be a clusterid of the form \"applicationName:clusterName.\""); System.setProperty("application", clusterIdParts[0]); System.setProperty("cluster", clusterIdParts[1]); String appCtxFilename = System.getProperty(appdefParam); if (appCtxFilename == null || appCtxFilename.length() == 0) { // usage("the java vm option \"-D" + appdefParam + "\" wasn't specified."); appCtxFilename = "DempsyApplicationContext-" + clusterIdParts[0] + ".xml"; }//www . ja va 2s . c o m String zkConnect = System.getProperty(zk_connectParam); if (zkConnect == null || zkConnect.length() == 0) usage("the java vm option \"-D" + zk_connectParam + "\" wasn't specified."); String zkTimeout = System.getProperty(zk_timeoutParam); if (zkTimeout == null || zkTimeout.length() == 0) System.setProperty(zk_timeoutParam, zk_timeoutDefault); String totalSlots = System.getProperty(total_slots_per_clusterParam); if (totalSlots == null || totalSlots.length() == 0) System.setProperty(total_slots_per_clusterParam, total_slots_per_clusterDefault); String minNodes = System.getProperty(min_num_nodes_per_clusterParam); if (minNodes == null || minNodes.length() == 0) System.setProperty(min_num_nodes_per_clusterParam, min_num_nodes_per_clusterDefault); //====================================================== String contextFile = "classpath:Dempsy-distributed.xml"; ClassPathXmlApplicationContext context = null; try { // Initialize Spring context = new ClassPathXmlApplicationContext(new String[] { appCtxFilename, contextFile }); context.registerShutdownHook(); } catch (Throwable e) { logger.error(MarkerFactory.getMarker("FATAL"), "Failed to start the application ", e); throw e; } if (context != null) { try { context.getBean(Dempsy.class).waitToBeStopped(); } catch (InterruptedException e) { logger.error("Interrupted . . . ", e); } finally { context.stop(); } logger.info("Shut down dempsy appliction " + appCtxFilename + "-" + application + ", bye!"); } }
From source file:com.alibaba.dubbo.examples.annotation.AnnotationTest.java
@Test public void testAnnotation() { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext( AnnotationTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml"); providerContext.start();//from w w w .j av a 2s . c o m try { ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext( AnnotationTest.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml"); consumerContext.start(); try { AnnotationAction annotationAction = (AnnotationAction) consumerContext.getBean("annotationAction"); String hello = annotationAction.doSayHello("world"); assertEquals("annotation: hello, world", hello); } finally { consumerContext.stop(); consumerContext.close(); } } finally { providerContext.stop(); providerContext.close(); } }
From source file:com.hm.SSI.dubbo.AnnotationTest.java
@Test public void testAnnotation() { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext( AnnotationTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml"); System.out.println(//w ww .j av a 2 s . c o m AnnotationTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml"); providerContext.start(); try { ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext( AnnotationTest.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml"); System.out.println( AnnotationTest.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml"); consumerContext.start(); try { AnnotationAction annotationAction = (AnnotationAction) consumerContext.getBean("annotationAction"); String hello = annotationAction.doSayHello("world"); assertEquals("annotation: hello, world", hello); } finally { consumerContext.stop(); consumerContext.close(); } } finally { providerContext.stop(); providerContext.close(); } }