Example usage for org.springframework.context.support FileSystemXmlApplicationContext getBeanFactory

List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext getBeanFactory

Introduction

In this page you can find the example usage for org.springframework.context.support FileSystemXmlApplicationContext getBeanFactory.

Prototype

@Override
    public final ConfigurableListableBeanFactory getBeanFactory() 

Source Link

Usage

From source file:de.uniwue.dmir.heatmap.EntryPointIncremental.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) throws IOException, ParseException {

    DateFormat df = new SimpleDateFormat(DATE_FORMAT);
    SimpleDateFormat backupDf = new SimpleDateFormat(BACKUP_DATE_FORMAT);

    String workDir = System.getProperty("workDir", ".");
    LOGGER.debug("Work dir: {}", workDir);
    String configDir = System.getProperty("configDir", ".");
    LOGGER.debug("Config dir: {}", configDir);

    File seedDir = new File(workDir, SEED_DIR);
    LOGGER.debug("Seed dir: {}", seedDir);
    File currentDir = new File(workDir, CURRENT_DIR);
    LOGGER.debug("Current dir: {}", currentDir);
    File backupDir = new File(workDir, BACKUP_DIR);
    LOGGER.debug("Backup dir: {}", backupDir);

    String initialMinTimeString = System.getProperty("minTime");
    LOGGER.debug("Initial minimal time parameter: {}", initialMinTimeString);
    Date initialMinTime = initialMinTimeString == null ? new Date(0) : df.parse(initialMinTimeString);
    LOGGER.debug("Initial minimal time: {}", df.format(initialMinTime));

    String absoluteMaxTimeString = System.getProperty("maxTime");
    LOGGER.debug("Absolute maximal time parameter: {}", absoluteMaxTimeString);
    Date absoluteMaxTime = absoluteMaxTimeString == null ? new Date()
            : new SimpleDateFormat(DATE_FORMAT).parse(absoluteMaxTimeString);
    LOGGER.debug("Absolute maximal time: {}", df.format(absoluteMaxTime));

    String incrementalFile = new File("file:" + configDir, INCREMENTAL_FILE).getPath();
    String settingsFile = new File("file:" + configDir, HEATMAP_PROCESSOR__FILE).getPath();

    LOGGER.debug("Initializing incremental control file: {}", incrementalFile);
    FileSystemXmlApplicationContext incrementalContext = new FileSystemXmlApplicationContext(incrementalFile);

    // get point limit
    int pointLimit = Integer
            .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${point.limit}"));
    LOGGER.debug("Print limit: {}", pointLimit);

    // get backups to keep
    int backupsToKeep = Integer
            .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${backups.to.keep}"));
    LOGGER.debug("Backups to keep: {}", pointLimit);

    LOGGER.debug("Initializing process components (manager and limiter).");
    IProcessManager processManager = incrementalContext.getBean(IProcessManager.class);
    IProcessLimiter processLimiter = incrementalContext.getBean(IProcessLimiter.class);

    LOGGER.debug("Starting incremental loop.");
    while (true) { // break as soon as no new points are available

        // cleanup --- just in case
        LOGGER.debug("Deleting \"current\" dir.");
        FileUtils.deleteDirectory(currentDir);

        // copy from seed to current
        LOGGER.debug("Copying seed.");
        seedDir.mkdirs();/*  w ww .  j ava2 s .c o m*/
        FileUtils.copyDirectory(seedDir, currentDir);

        // get min time
        LOGGER.debug("Getting minimal time ...");
        Date minTime = initialMinTime;
        ProcessManagerEntry entry = processManager.getEntry();
        if (entry != null && entry.getMaxTime() != null) {
            minTime = entry.getMaxTime();
        }
        LOGGER.debug("Minimal time: {}", new SimpleDateFormat(DATE_FORMAT).format(minTime));

        // break if we processed all available points (minTime is greater than or equal to absoluteMaxTime)
        if (minTime.getTime() >= absoluteMaxTime.getTime()) {
            LOGGER.debug("Processed all points.");
            break;
        }

        // get the maximal time
        LOGGER.debug("Get maximal time.");

        // get the time from the newest point in our point range (pointMaxTime) ...
        Date pointMaxTime = processLimiter.getMaxTime(minTime, pointLimit);

        // ... and possibly break the loop if no new points are available
        if (pointMaxTime == null)
            break;

        // set the max time and make sure we are not taking to many points 
        // (set max time to the minimum of pointMaxTime and absoluteMaxTime)
        Date maxTime = pointMaxTime.getTime() > absoluteMaxTime.getTime() ? absoluteMaxTime : pointMaxTime;

        LOGGER.debug("Maximal time: {}", new SimpleDateFormat(DATE_FORMAT).format(maxTime));

        // start process
        processManager.start(minTime);

        System.setProperty("minTimestamp", new SimpleDateFormat(DATE_FORMAT).format(minTime));

        System.setProperty("maxTimestamp", new SimpleDateFormat(DATE_FORMAT).format(maxTime));

        FileSystemXmlApplicationContext heatmapContext = new FileSystemXmlApplicationContext(settingsFile);

        IHeatmap heatmap = heatmapContext.getBean(HEATMAP_BEAN, IHeatmap.class);

        ITileProcessor tileProcessor = heatmapContext.getBean(WRITER_BEAN, ITileProcessor.class);

        heatmap.processTiles(tileProcessor);

        tileProcessor.close();
        heatmapContext.close();

        // finish process
        processManager.finish(maxTime);

        // move old seed
        if (backupsToKeep > 0) {
            FileUtils.moveDirectory(seedDir, new File(backupDir, backupDf.format(minTime))); // minTime is the maxTime of the seed

            // cleanup backups
            String[] backups = backupDir.list(DirectoryFileFilter.DIRECTORY);
            File oldestBackup = null;
            if (backups.length > backupsToKeep) {
                for (String bs : backups) {
                    File b = new File(backupDir, bs);
                    if (oldestBackup == null || oldestBackup.lastModified() > b.lastModified()) {
                        oldestBackup = b;
                    }
                }
                FileUtils.deleteDirectory(oldestBackup);
            }

        } else {
            FileUtils.deleteDirectory(seedDir);
        }

        // move new seed
        FileUtils.moveDirectory(currentDir, seedDir);

    }

    incrementalContext.close();

}

From source file:org.red5.server.jboss.JbossLoader.java

/**
 * Shut server down/*  www .j ava  2 s .  c om*/
 */
public void stop() {
    logger.info("Shutting down jboss context");
    try {
        //prepare spring for shutdown
        Introspector.flushCaches();
        //shutdown our jmx agent
        JMXAgent.shutdown();
        //shutdown spring
        FileSystemXmlApplicationContext appContext = (FileSystemXmlApplicationContext) getApplicationContext();
        ConfigurableBeanFactory factory = appContext.getBeanFactory();
        if (factory.containsSingleton("default.context")) {
            for (String scope : factory.getRegisteredScopeNames()) {
                logger.debug("Registered scope: " + scope);
            }
            for (String singleton : factory.getSingletonNames()) {
                logger.debug("Registered singleton: " + singleton);
                //factory.destroyScopedBean(singleton);
            }
            factory.destroySingletons();
        }
        appContext.close();
        LogFactory.release(Thread.currentThread().getContextClassLoader());
    } catch (Exception e) {
        logger.warn("Jboss could not be stopped", e);
    }
}

From source file:edu.harvard.i2b2.plugin.pb.util.QueryProcessorUtil.java

/**
 * Function to create spring bean factory
 * //from   www  .  ja  v  a2 s  . co  m
 * @return BeanFactory
 */
public BeanFactory getSpringBeanFactory() {
    if (beanFactory == null) {
        String appDir = null;
        try {
            // read application directory property file via classpath
            loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
            // read directory property
            appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);

        } catch (I2B2Exception e) {
            log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath ");
        }
        String springContextFileName = loadProperties
                .getProperty(APPLICATION_SPRINGCONTEXT_FILENAME_PROPERTIES);

        if (appDir != null) {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "file:" + appDir + "/" + springContextFileName);
            beanFactory = ctx.getBeanFactory();
        } else {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "classpath:" + springContextFileName);
            beanFactory = ctx.getBeanFactory();
        }

    }
    return beanFactory;
}

From source file:edu.harvard.i2b2.pm.util.PMUtil.java

/**
 * Return the ontology spring config//  w  ww .  jav a  2s.  co m
 * @return
 */
public BeanFactory getSpringBeanFactory() {
    if (beanFactory == null) {
        String appDir = null;

        try {
            //read application directory property file via classpath
            Properties loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
            //read directory property
            appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);
        } catch (I2B2Exception e) {
            log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath ");
        }

        if (appDir != null) {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "file:" + appDir + "/" + "PMApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        } else {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "classpath:" + "PMApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        }
    }

    return beanFactory;
}

From source file:edu.harvard.i2b2.workplace.util.WorkplaceUtil.java

/**
 * Return the ontology spring config//from  w  w w .j  av a2s  .co m
 * @return
 */
public BeanFactory getSpringBeanFactory() {
    if (beanFactory == null) {
        String appDir = null;

        try {
            //read application directory property file via classpath
            Properties loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
            //read directory property
            appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);
        } catch (I2B2Exception e) {
            log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath ");
        }

        if (appDir != null) {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "file:" + appDir + "/" + "WorkplaceApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        } else {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "classpath:" + "WorkplaceApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        }
    }

    return beanFactory;
}

From source file:edu.harvard.i2b2.im.util.IMUtil.java

/**
 * Return the ontology spring config// w  ww .j av  a2s. co  m
 * @return
 */
public BeanFactory getSpringBeanFactory() {
    if (beanFactory == null) {
        String appDir = null;

        try {
            //read application directory property file via classpath
            Properties loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
            //read directory property
            appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);
        } catch (I2B2Exception e) {
            log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath ");
        }

        if (appDir != null) {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "file:" + appDir + "/" + "IMApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        } else {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "classpath:" + "IMApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        }
    }

    return beanFactory;
}

From source file:edu.harvard.i2b2.ontology.util.OntologyUtil.java

/**
 * Return the ontology spring config// w  ww. j  a  v a2  s . c o m
 * 
 * @return
 */
public BeanFactory getSpringBeanFactory() {
    if (beanFactory == null) {
        String appDir = null;

        try {
            // read application directory property file via classpath
            Properties loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
            // read directory property
            appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);
        } catch (I2B2Exception e) {
            log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath ");
        }

        if (appDir != null) {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "file:" + appDir + "/" + "OntologyApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        } else {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "classpath:" + "OntologyApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        }
    }

    return beanFactory;
}

From source file:edu.harvard.i2b2.crc.loader.util.CRCLoaderUtil.java

/**
 * Function to create spring bean factory
 * /*  w  w  w. j  a  va 2 s  .  c o  m*/
 * @return BeanFactory
 */
public BeanFactory getSpringBeanFactory() {
    if (beanFactory == null) {
        String appDir = null;
        try {
            // read application directory property file via classpath
            loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
            // read directory property
            appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);

        } catch (I2B2Exception e) {
            log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath ");
        }

        if (appDir != null) {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "file:" + appDir + "/" + "CRCLoaderApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        } else {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "classpath:" + "CRCLoaderApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        }

    }
    return beanFactory;
}

From source file:edu.harvard.i2b2.crc.util.QueryProcessorUtil.java

/**
 * Function to create spring bean factory
 * //from  w  w  w . ja va2s .  c  o m
 * @return BeanFactory
 */
public BeanFactory getSpringBeanFactory() {
    if (beanFactory == null) {
        String appDir = null;
        try {
            // read application directory property file via classpath
            loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
            // read directory property
            appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);

        } catch (I2B2Exception e) {
            log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath ");
        }

        if (appDir != null) {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "file:" + appDir + "/" + "CRCApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        } else {
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    "classpath:" + "CRCApplicationContext.xml");
            beanFactory = ctx.getBeanFactory();
        }

    }
    return beanFactory;
}