List of usage examples for org.springframework.context.support AbstractApplicationContext close
@Override public void close()
From source file:com.toms.mq.rabbitmq.tutorial.part2.TcpAmqp.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w w w . j a va 2s . c o m */ public static void main(final 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:context/part2/*-tcp.xml"); LOGGER.info("\n=========================================================" + "\n " + "\n This is the TCP-AMQP Sample - " + "\n " + "\n Start a netcat, listening on port 11112 - " + "\n netcat -l 11112 " + "\n " + "\n In another terminal, telnet to localhost 11111 " + "\n Enter text and you will see it echoed to the netcat " + "\n " + "\n Press Enter in this console to terminate " + "\n " + "\n========================================================="); System.in.read(); context.close(); }
From source file:com.osc.edu.chapter3.Starter.java
/** * <pre>//from w ww . j a v a 2 s .co m * ? samples/commons/db_configuration/build.xml ?? test-db-start, initializeData Task . * </pre> * @param args */ public static void main(String[] args) { logger.debug("Initializing Spring context."); AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext( new String[] { "spring/application-context.xml" }); logger.debug("Spring context initialized."); //CustomersService customersService = (CustomersService)applicationContext.getBean("customersService"); //EmployeesService employeesService = (EmployeesService)applicationContext.getBean("employeesService"); CustomersService customersService = applicationContext.getBean(CustomersService.class); EmployeesService employeesService = applicationContext.getBean(EmployeesService.class); customersService.setUseMapper(true); employeesService.setUseMapper(true); logger.debug("customers size with mapper : {}", customersService.getCustomersList().size()); logger.debug("employees size with mapper : {}", employeesService.getEmployeesList().size()); customersService.setUseMapper(false); employeesService.setUseMapper(false); logger.debug("customers size with sqlSession : {}", customersService.getCustomersList().size()); logger.debug("employees size with sqlSession : {}", employeesService.getEmployeesList().size()); applicationContext.close(); }
From source file:com.opengamma.masterdb.batch.cmd.BatchRunner.java
public static void main(String[] args) throws Exception { // CSIGNORE if (args.length == 0) { usage();//from ww w . ja va 2s .c o m System.exit(-1); } CommandLine line = null; try { CommandLineParser parser = new PosixParser(); line = parser.parse(getOptions(), args); initialize(line); } catch (ParseException e) { usage(); System.exit(-1); } AbstractApplicationContext appContext = null; try { appContext = getApplicationContext(); appContext.start(); ViewProcessor viewProcessor = appContext.getBean("viewProcessor", ViewProcessor.class); ViewClient viewClient = viewProcessor.createViewClient(UserPrincipal.getLocalUser()); MarketDataSpecification marketDataSpec = new FixedHistoricalMarketDataSpecification( s_observationDateTime.toLocalDate()); ViewCycleExecutionOptions cycleOptions = ViewCycleExecutionOptions.builder() .setValuationTime(s_valuationInstant).setMarketDataSpecification(marketDataSpec) .setResolverVersionCorrection(VersionCorrection.of(s_versionAsOf, s_correctedTo)).create(); ViewCycleExecutionSequence executionSequence = ArbitraryViewCycleExecutionSequence.of(cycleOptions); ExecutionOptions executionOptions = new ExecutionOptions(executionSequence, ExecutionFlags.none().awaitMarketData().get(), null, null); viewClient.attachToViewProcess(UniqueId.parse(s_viewDefinitionUid), executionOptions); } finally { if (appContext != null) { appContext.close(); } } /*if (failed) { s_logger.error("Batch failed."); System.exit(-1); } else { s_logger.info("Batch succeeded."); System.exit(0); }*/ }
From source file:org.jodconverter.cli.Convert.java
/** * Main entry point of the program./*from w ww . ja v a2 s.c om*/ * * @param arguments program arguments. */ public static void main(final String[] arguments) { try { final CommandLine commandLine = new DefaultParser().parse(OPTIONS, arguments); // Check if the command line contains arguments that is suppose // to print some info and then exit. checkPrintInfoAndExit(commandLine); // Get conversion arguments final String outputFormat = getStringOption(commandLine, OPT_OUTPUT_FORMAT.getOpt()); final String outputDirPath = getStringOption(commandLine, OPT_OUTPUT_DIRECTORY.getOpt()); final DocumentFormatRegistry registry = getRegistryOption(commandLine); final boolean overwrite = commandLine.hasOption(OPT_OVERWRITE.getOpt()); final String[] filenames = commandLine.getArgs(); // Validate arguments length if (outputFormat == null && filenames.length % 2 != 0 || filenames.length == 0) { printHelp(); System.exit(STATUS_INVALID_ARGUMENTS); } // Load the application context if provided final AbstractApplicationContext context = getApplicationContextOption(commandLine); // Create a default office manager from the command line final OfficeManager officeManager = createOfficeManager(commandLine, context); try { // Starts the manager printInfo("Starting office"); officeManager.start(); // Build a client converter and start the conversion final CliConverter converter = createCliConverter(commandLine, context, officeManager, registry); if (outputFormat == null) { // Build 2 arrays; one containing the input files and the other // containing the output files. final String[] inputFilenames = new String[filenames.length / 2]; final String[] outputFilenames = new String[inputFilenames.length]; for (int i = 0, j = 0; i < filenames.length; i += 2, j++) { inputFilenames[j] = filenames[i]; outputFilenames[j] = filenames[i + 1]; } converter.convert(inputFilenames, outputFilenames, outputDirPath, overwrite); } else { converter.convert(filenames, outputFormat, outputDirPath, overwrite); } } finally { printInfo("Stopping office"); OfficeUtils.stopQuietly(officeManager); // Close the application context if required if (context != null) { context.close(); } } System.exit(0); } catch (ParseException e) { printErr("jodconverter-cli: %s", e.getMessage()); printHelp(); System.exit(2); } catch (Exception e) { // NOSONAR printErr("jodconverter-cli: %s", e.getMessage()); e.printStackTrace(System.err); // NOSONAR System.exit(2); } }
From source file:org.settings4j.helper.spring.ByteArrayXMLApplicationContext.java
/** * Static method to get a single Bean from a Spring Configuration XML. * * @param content The Spring configuration XML as byte[]. * @param beanName The bean name/identifier. * @return The Bean-Object or <code>null</code>. *//*w ww . ja v a2s . co m*/ public static Object getBean(final byte[] content, final String beanName) { final AbstractApplicationContext context = new ByteArrayXMLApplicationContext(content); context.refresh(); final Object result = context.getBean(beanName); context.close(); return result; }
From source file:de.uzk.hki.da.at.AcceptanceTest.java
private static void instantiateRepository(Properties properties) { String repImplBeanName = properties.getProperty("cb.implementation.repository"); if (repImplBeanName == null) repImplBeanName = "fakeRepositoryFacade"; AbstractApplicationContext context = new FileSystemXmlApplicationContext("conf/beans.xml"); repositoryFacade = (RepositoryFacade) context.getBean(repImplBeanName); context.close(); }
From source file:de.uzk.hki.da.at.AcceptanceTest.java
/** * @param gridImplBeanName bean name /*from w w w .j ava2 s . c om*/ * @param dcaImplBeanName distributed conversion adapter beanName * @return */ private static void instantiateGrid(Properties properties) { String gridImplBeanName = properties.getProperty("cb.implementation.grid"); String dcaImplBeanName = properties.getProperty("cb.implementation.distributedConversion"); if (gridImplBeanName == null) gridImplBeanName = "fakeGridFacade"; if (dcaImplBeanName == null) dcaImplBeanName = "fakeDistributedConversionAdapter"; AbstractApplicationContext context = new FileSystemXmlApplicationContext("conf/beans.xml"); gridFacade = (GridFacade) context.getBean(gridImplBeanName); distributedConversionAdapter = (DistributedConversionAdapter) context.getBean(dcaImplBeanName); context.close(); }
From source file:de.uzk.hki.da.at.AcceptanceTest.java
private static void instantiateNode() { AbstractApplicationContext context = new FileSystemXmlApplicationContext("conf/beans.xml"); localNode = (Node) context.getBean("localNode"); Session session = HibernateUtil.openSession(); session.beginTransaction();/*w ww . j ava2s .c o m*/ session.refresh(localNode); session.close(); context.close(); }
From source file:de.uzk.hki.da.grid.CTIrodsFacade.java
/** * Sets up /*w w w. j av a 2 s.c o m*/ * <li>node * <li>irodsGridConnector * <li>gridFacade * @param properties */ private static void setUpGridInfrastructure(Properties properties) { AbstractApplicationContext context = new ClassPathXmlApplicationContext(BEANS_DIAGNOSTICS_IRODS); isc = (IrodsSystemConnector) context.getBean(BEAN_NAME_IRODS_SYSTEM_CONNECTOR); ig = (IrodsGridFacade) context.getBean(properties.getProperty(BEAN_NAME_IRODS_GRID_FACADE)); ig.setIrodsSystemConnector(isc); sp = new StoragePolicy(); sp.setWorkingResource("ciWorkingResource"); sp.setGridCacheAreaRootPath(Path.make(properties.getProperty(PROP_GRID_CACHE_AREA_ROOT_PATH)).toString()); sp.setWorkAreaRootPath(Path.make(properties.getProperty(PROP_WORK_AREA_ROOT_PATH)).toString()); sp.setReplDestinations("ciArchiveResourceGroup"); context.close(); }
From source file:org.apache.batchee.cli.lifecycle.impl.SpringLifecycle.java
@Override public void stop(final AbstractApplicationContext state) { state.close(); }