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);
}
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));
}
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;
}
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);
}
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();
}
});
}
Aggregations