Search in sources :

Example 1 with IgniteSpringHelper

use of org.apache.ignite.internal.util.spring.IgniteSpringHelper in project ignite by apache.

the class IgnitionEx method loadSpringBean.

/**
 * Loads spring bean by name.
 *
 * @param springXmlStream Input stream containing Spring XML configuration.
 * @param beanName Bean name.
 * @return Bean instance.
 * @throws IgniteCheckedException In case of error.
 */
public static <T> T loadSpringBean(InputStream springXmlStream, String beanName) throws IgniteCheckedException {
    A.notNull(springXmlStream, "springXmlPath");
    A.notNull(beanName, "beanName");
    IgniteSpringHelper spring = SPRING.create(false);
    return spring.loadBean(springXmlStream, beanName);
}
Also used : IgniteSpringHelper(org.apache.ignite.internal.util.spring.IgniteSpringHelper)

Example 2 with IgniteSpringHelper

use of org.apache.ignite.internal.util.spring.IgniteSpringHelper in project ignite by apache.

the class CdcLoader method loadCdc.

/**
 * Loads {@link CdcMain} from XML configuration file.
 *
 * @param springXmlPath Path to XML configuration file.
 * @return {@code ChangeDataCapture} instance.
 * @throws IgniteCheckedException If failed.
 */
public static CdcMain loadCdc(String springXmlPath) throws IgniteCheckedException {
    URL cfgUrl = U.resolveSpringUrl(springXmlPath);
    IgniteSpringHelper spring = SPRING.create(false);
    IgniteBiTuple<Map<Class<?>, Collection>, ? extends GridSpringResourceContext> cfgs = spring.loadBeans(cfgUrl, IgniteConfiguration.class, CdcConfiguration.class);
    Collection<IgniteConfiguration> igniteCfgs = cfgs.get1().get(IgniteConfiguration.class);
    if (F.size(igniteCfgs) != 1) {
        throw new IgniteCheckedException("Exact 1 IgniteConfiguration should be defined. Found " + F.size(igniteCfgs));
    }
    Collection<CdcConfiguration> cdcCfgs = cfgs.get1().get(CdcConfiguration.class);
    if (F.size(cdcCfgs) != 1) {
        throw new IgniteCheckedException("Exact 1 CaptureDataChangeConfiguration configuration should be defined. Found " + F.size(cdcCfgs));
    }
    return new CdcMain(F.first(igniteCfgs), cfgs.get2(), F.first(cdcCfgs));
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CdcMain(org.apache.ignite.internal.cdc.CdcMain) IgniteSpringHelper(org.apache.ignite.internal.util.spring.IgniteSpringHelper) Map(java.util.Map) URL(java.net.URL)

Example 3 with IgniteSpringHelper

use of org.apache.ignite.internal.util.spring.IgniteSpringHelper in project ignite by apache.

the class CachePojoStoreXmlSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    String path = builtinKeys ? "modules/spring/src/test/config/jdbc-pojo-store-builtin.xml" : "modules/spring/src/test/config/jdbc-pojo-store-obj.xml";
    URL url = U.resolveIgniteUrl(path);
    IgniteSpringHelper spring = IgniteComponentType.SPRING.create(false);
    IgniteConfiguration cfg = spring.loadConfigurations(url).get1().iterator().next();
    if (sqlEscapeAll()) {
        for (CacheConfiguration ccfg : cfg.getCacheConfiguration()) ((CacheJdbcPojoStoreFactory) ccfg.getCacheStoreFactory()).setSqlEscapeAll(true);
    }
    cfg.setIgniteInstanceName(igniteInstanceName);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteSpringHelper(org.apache.ignite.internal.util.spring.IgniteSpringHelper) URL(java.net.URL) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 4 with IgniteSpringHelper

use of org.apache.ignite.internal.util.spring.IgniteSpringHelper in project ignite by apache.

the class IgnitionEx method loadSpringBean.

/**
 * Loads spring bean by name.
 *
 * @param springXmlUrl Spring XML file URL.
 * @param beanName Bean name.
 * @return Bean instance.
 * @throws IgniteCheckedException In case of error.
 */
public static <T> T loadSpringBean(URL springXmlUrl, String beanName) throws IgniteCheckedException {
    A.notNull(springXmlUrl, "springXmlUrl");
    A.notNull(beanName, "beanName");
    IgniteSpringHelper spring = SPRING.create(false);
    return spring.loadBean(springXmlUrl, beanName);
}
Also used : IgniteSpringHelper(org.apache.ignite.internal.util.spring.IgniteSpringHelper)

Example 5 with IgniteSpringHelper

use of org.apache.ignite.internal.util.spring.IgniteSpringHelper in project ignite by apache.

the class GridRouterCommandLineStartup method main.

/**
 * Wrapper method to run router from command-line.
 *
 * @param args Command-line arguments.
 * @throws IgniteCheckedException If failed.
 */
public static void main(String[] args) throws IgniteCheckedException {
    X.println("   __________  ________________ ", "  /  _/ ___/ |/ /  _/_  __/ __/ ", " _/ // (_ /    // /  / / / _/   ", "/___/\\___/_/|_/___/ /_/ /___/  ", " ", "Ignite Router Command Line Loader", "ver. " + ACK_VER_STR, COPYRIGHT, " ");
    IgniteSpringHelper spring = SPRING.create(false);
    if (args.length < 1) {
        X.error("Missing XML configuration path.");
        System.exit(1);
    }
    String cfgPath = args[0];
    URL cfgUrl = U.resolveIgniteUrl(cfgPath);
    if (cfgUrl == null) {
        X.error("Spring XML file not found (is IGNITE_HOME set?): " + cfgPath);
        System.exit(1);
    }
    boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null;
    IgniteBiTuple<Object, Object> t = null;
    Collection<Handler> savedHnds = null;
    if (isLog4jUsed) {
        try {
            t = U.addLog4jNoOpLogger();
        } catch (Exception ignored) {
            isLog4jUsed = false;
        }
    }
    if (!isLog4jUsed)
        savedHnds = U.addJavaNoOpLogger();
    Map<Class<?>, Collection> beans;
    try {
        beans = spring.loadBeans(cfgUrl, IgniteLogger.class, GridTcpRouterConfiguration.class).get1();
    } finally {
        if (isLog4jUsed && t != null)
            U.removeLog4jNoOpLogger(t);
        if (!isLog4jUsed)
            U.removeJavaNoOpLogger(savedHnds);
    }
    final GridRouterCommandLineStartup routerStartup = new GridRouterCommandLineStartup();
    routerStartup.start(beans);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            routerStartup.stop();
        }
    });
}
Also used : Handler(java.util.logging.Handler) URL(java.net.URL) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpringHelper(org.apache.ignite.internal.util.spring.IgniteSpringHelper) Collection(java.util.Collection)

Aggregations

IgniteSpringHelper (org.apache.ignite.internal.util.spring.IgniteSpringHelper)7 URL (java.net.URL)3 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 Test (org.junit.Test)2 Connection (java.sql.Connection)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Handler (java.util.logging.Handler)1 DataSource (javax.sql.DataSource)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 CdcMain (org.apache.ignite.internal.cdc.CdcMain)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1