List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext close
@Override public void close()
From source file:com.digitalgeneralists.assurance.ui.workers.LoadScanResultsWorker.java
@Override protected Scan doInBackground() throws Exception { // List<ComparisonResult> list = null; // Because we are operating in a Swing application, the session context // closes after the initial bootstrap run. There appears to be an // "application"-level session configuration that should enable the // behavior we want for a desktop application, but there is no documentation // for it that I can find. // So, Assurance mimics a web app request/response // cycle for calls into the model delegate through the Swing // application. All calls to the model initiated directly from the UI // essentially operate as a new "request" and rebuild the Hibernate and // Spring session contexts for use within that operation. ClassPathXmlApplicationContext springContext = null; try {// ww w. j av a 2s.c om // NOTE: I'm letting Hibernate do the heavy lifting in terms of collection initialization. // Rather than re-work the complete application architecture, we'll leave // the worker in place. // springContext = new ClassPathXmlApplicationContext("/META-INF/spring/app-context.xml"); // IModelDelegate modelDelegate = (IModelDelegate) // springContext.getBean("ModelDelegate"); // list = modelDelegate.getScanResults(this.scan); } finally { if (springContext != null) { springContext.close(); } springContext = null; } return this.scan; }
From source file:org.ff4j.cli.FF4jCliProcessor.java
/** * Parse Spring context./* ww w . ja v a2 s .c o m*/ */ @SuppressWarnings("unchecked") public void parseSpringContext(String fileName) { try { logInfo("Loading configurations from classpath file [" + fileName + "]"); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(fileName); this.envs = ctx.getBeansOfType(FF4j.class); if (ctx.containsBean("AUTHORIZED_USERS")) { this.users = (Map<String, String>) ctx.getBean("AUTHORIZED_USERS"); } ctx.close(); } catch (RuntimeException fne) { error(fne, "Cannot parse Spring context"); } }
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(/* www.ja v a 2 s . co 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(); } }
From source file:org.activiti.crystalball.simulator.SimulateBottleneckTest.java
/** * results differs - that's why this test is ignored - possible bug. * @throws Exception /*from www . j av a2s .c o m*/ */ @Test public void testUser2OverLoaded() throws Exception { System.setProperty("liveDB", LIVE_DB); System.setProperty("_SIM_DB_PATH", tempDir + "/simulationRunDB-SimulateBottleNeck-Overload-" + Thread.currentThread().getId()); FileUtils.copyFile(new File(LIVE_DB + ".h2.db"), new File(tempDir + "/simulationRunDB-SimulateBottleNeck-Overload-" + Thread.currentThread().getId() + ".h2.db")); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/SimEngine-simulateBottleneck-h2-context.xml"); ProcessEngine processEngine = (ProcessEngine) appContext.getBean("simProcessEngine"); // increase frequency of process starts to 45 mins (default is 1 hour) StartProcessEventHandler startProcessEventHandler = appContext.getBean(StartProcessEventHandler.class); startProcessEventHandler.setPeriod(2700000); runSimulation(appContext, tempDir + "/SimulateBottleneckTest-2.png"); processEngine.close(); appContext.close(); File expected = new File(System.getProperty("baseDir", ".") + "/src/test/resources/org/activiti/crystalball/simulator/simulateBottleneckTest-2.png"); File generated = new File(tempDir + "/SimulateBottleneckTest-2.png"); assertTrue(FileUtils.contentEquals(expected, generated)); // delete database file File f = new File(System.getProperty("_SIM_DB_PATH") + ".h2.db"); if (!f.delete()) System.err.println("unable to delete file"); }
From source file:org.solmix.runtime.support.spring.SpringContainerTest.java
@Test public void testSchema() { ClassPathXmlApplicationContext context = null; try {/*from w w w. j a v a2 s . c o m*/ context = new ClassPathXmlApplicationContext("/org/solmix/runtime/support/spring/container.xml"); Container c = context.getBean("solmix1", Container.class); String v = c.getProperty("key").toString(); Assert.assertEquals("value", v); Assert.assertNotNull(c); Container c1 = context.getBean("solmix3", Container.class); Assert.assertNotSame(c, c1); Assert.assertNotNull(c1); List<ContainerListener> cls = c.getContainerListeners(); Assert.assertEquals(3, cls.size()); } finally { if (context != null) { context.close(); } } }
From source file:pl.baczkowicz.mqspy.connectivity.jms.JmsConnection.java
public void configure(final DaemonJmsConnectionDetails connectionSettings) { try {/*from w w w . j a va 2 s . c om*/ if (connectionSettings.getConnectionFactory().getContextFile() != null) { final JmsContextFile contextFile = connectionSettings.getConnectionFactory().getContextFile(); final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( contextFile.getContextFileLocation()); connectionFactory = context.getBean(contextFile.getConnectionFactoryBean(), ConnectionFactory.class); if (contextFile.getJmsTemplateBean() != null) { jmsTemplate = context.getBean(contextFile.getJmsTemplateBean(), JmsTemplate.class); } else { jmsTemplate = new JmsTemplate(connectionFactory); } context.close(); connection = connectionFactory.createConnection(); connection.start(); started = true; // TODO: optionally create all topics in spring? } else if (connectionSettings.getConnectionFactory().getScriptFile() != null) { // TODO: create a connection factory // TODO: create connection (optional) connection = connectionFactory.createConnection(); connection.start(); started = true; // TODO: create jms template (optional) // TODO: create a session (optional)? } // TODO: parametrise that session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); for (final ScriptedSubscriptionDetails subscription : connectionSettings.getSubscription()) { subscribe(subscription.getTopic()); } } catch (JMSException e) { logger.error("JMS error", e); } // TODO: username and password }
From source file:com.digitalgeneralists.assurance.ui.workers.MergeScanWorker.java
@Override protected Scan doInBackground() throws Exception { this.notifier.fireEvent(new ScanMergeStartedEvent(this.scan)); Scan scan = null;// ww w .j a v a 2s . c o m // Because we are operating in a Swing application, the session context // closes after the initial bootstrap run. There appears to be an // "application"-level session configuration that should enable the // behavior we want for a desktop application, but there is no documentation // for it that I can find. // So, Assurance mimics a web app request/response // cycle for calls into the model delegate through the Swing // application. All calls to the model initiated directly from the UI // essentially operate as a new "request" and rebuild the Hibernate and // Spring session contexts for use within that operation. ClassPathXmlApplicationContext springContext = null; try { springContext = new ClassPathXmlApplicationContext("/META-INF/spring/app-context.xml"); IModelDelegate modelDelegate = (IModelDelegate) springContext.getBean("ModelDelegate"); IAssuranceThreadPool threadPool = (IAssuranceThreadPool) springContext.getBean("ThreadPool"); threadPool.setNumberOfThreads(modelDelegate.getApplicationConfiguration().getNumberOfScanThreads()); scan = modelDelegate.mergeScan(this.scan, threadPool, this); modelDelegate = null; threadPool = null; } finally { if (springContext != null) { springContext.close(); } springContext = null; } return scan; }
From source file:com.digitalgeneralists.assurance.ui.workers.InitializeApplicationStateWorker.java
@Override protected List<Object> doInBackground() throws Exception { List<Object> bootstrapObjects = new ArrayList<Object>(); List<ScanDefinition> scanDefinitions = null; ApplicationConfiguration config = null; // Because we are operating in a Swing application, the session context // closes after the initial bootstrap run. There appears to be an // "application"-level session configuration that should enable the // behavior we want for a desktop application, but there is no documentation // for it that I can find. // So, Assurance mimics a web app request/response // cycle for calls into the model delegate through the Swing // application. All calls to the model initiated directly from the UI // essentially operate as a new "request" and rebuild the Hibernate and // Spring session contexts for use within that operation. ClassPathXmlApplicationContext springContext = null; try {/* w ww . j a v a2s .c om*/ springContext = new ClassPathXmlApplicationContext("/META-INF/spring/app-context.xml"); IModelDelegate modelDelegate = (IModelDelegate) springContext.getBean("ModelDelegate"); scanDefinitions = modelDelegate.getScanDefinitions(); config = modelDelegate.getApplicationConfiguration(); if (scanDefinitions != null) { bootstrapObjects.add(scanDefinitions); } if (config != null) { bootstrapObjects.add(config); } modelDelegate = null; } finally { if (springContext != null) { springContext.close(); } springContext = null; } return bootstrapObjects; }
From source file:org.activiti.crystalball.examples.mortages.firstsimulation.TheFirstSimulationTest.java
@Test public void testFirstRun() throws Exception { ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "org/activiti/crystalball/examples/mortages/firstsimulation/mortages-h2-context.xml"); SimulationRun simRun = (SimulationRun) appContext.getBean("simulationRun"); ProcessEngine simProcessEngine = (ProcessEngine) appContext.getBean("simProcessEngine"); simProcessEngine.getRepositoryService().createDeployment() .addClasspathResource("org/activiti/crystalball/examples/mortages/MortageDemo-0.bpmn").deploy(); ///*from w w w .jav a 2 s . c om*/ // execute simulation run, without end date // simRun.execute(new Date(), null); assertEquals(1, simProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().count()); simProcessEngine.close(); appContext.close(); }
From source file:org.d4rxh4wx.thread.executor.UserThreadPoolTest.java
@Test public void test() { System.out.println("Starting"); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "userthreadpoolexecutor-context-test.xml"); // building a user thread pool executor (one for this thread) // reminder: this user thread pool is using a shared thread pool UserThreadPoolExecutor userThreadPoolExecutor = ctx.getBean(UserThreadPoolExecutor.class); // submitting a number of 10 tasks (max per user = 5 (cf userthreadpool-context-test.xml) // this thread will block of the 6th task, waiting for a finished task to proceed for (int i = 0; i < 10; i++) { userThreadPoolExecutor.submit(new SampleTask(i + 1)); }/*from w w w .ja v a 2 s .c om*/ // waiting (in this thread) for remaining user tasks to finish userThreadPoolExecutor.waitForRemainingTasks(); ctx.close(); System.out.println("End"); }