Ignite-2087
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/bd1f506e Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/bd1f506e Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/bd1f506e Branch: refs/heads/ignite-gg-10889 Commit: bd1f506eaa618f803b39461f5198091d7cbea3a4 Parents: e7e4a48 Author: Anton Vinogradov <a...@apache.org> Authored: Thu Dec 17 14:27:16 2015 +0300 Committer: Anton Vinogradov <a...@apache.org> Committed: Thu Dec 17 14:27:16 2015 +0300 ---------------------------------------------------------------------- .../org/apache/ignite/cache/CacheManager.java | 2 +- .../org/apache/ignite/internal/IgnitionEx.java | 51 +++++++++++++++----- .../java/org/apache/ignite/IgniteSpring.java | 4 +- 3 files changed, 43 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/bd1f506e/modules/core/src/main/java/org/apache/ignite/cache/CacheManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheManager.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheManager.java index 84ed2cd..6e09d72 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/CacheManager.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheManager.java @@ -114,7 +114,7 @@ public class CacheManager implements javax.cache.CacheManager { ignite = (IgniteKernal)IgnitionEx.start(cfg); } else - ignite = (IgniteKernal)IgnitionEx.start(uri.toURL()); + ignite = (IgniteKernal)IgnitionEx.start(uri.toURL(), clsLdr); kernalGateway = ignite.context().gateway(); } http://git-wip-us.apache.org/repos/asf/ignite/blob/bd1f506e/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java index 4f6c6d9..5153fb3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java @@ -495,7 +495,7 @@ public class IgnitionEx { URL url = U.resolveIgniteUrl(DFLT_CFG); if (url != null) - return start(DFLT_CFG, null, springCtx); + return start(DFLT_CFG, null, springCtx, null); U.warn(null, "Default Spring XML file not found (is IGNITE_HOME set?): " + DFLT_CFG); @@ -581,7 +581,7 @@ public class IgnitionEx { return start(cfg); } else - return start(springCfgPath, gridName, null); + return start(springCfgPath, gridName, null, null); } /** @@ -697,6 +697,7 @@ public class IgnitionEx { * @param springCfgPath Spring XML configuration file path or URL. This cannot be {@code null}. * @param gridName Grid name that will override default. * @param springCtx Optional Spring application context, possibly {@code null}. + * @param ldr Optional class loader that will be used by default. * Spring bean definitions for bean injection are taken from this context. * If provided, this context can be injected into grid tasks and grid jobs using * {@link SpringApplicationContextResource @SpringApplicationContextResource} annotation. @@ -707,10 +708,10 @@ public class IgnitionEx { * been started or Spring XML configuration file is invalid. */ public static Ignite start(String springCfgPath, @Nullable String gridName, - @Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException { + @Nullable GridSpringResourceContext springCtx, @Nullable ClassLoader ldr) throws IgniteCheckedException { URL url = U.resolveSpringUrl(springCfgPath); - return start(url, gridName, springCtx); + return start(url, gridName, springCtx, ldr); } /** @@ -730,7 +731,28 @@ public class IgnitionEx { * been started or Spring XML configuration file is invalid. */ public static Ignite start(URL springCfgUrl) throws IgniteCheckedException { - return start(springCfgUrl, null, null); + return start(springCfgUrl, null, null, null); + } + + /** + * Starts all grids specified within given Spring XML configuration file URL. If grid with given name + * is already started, then exception is thrown. In this case all instances that may + * have been started so far will be stopped too. + * <p> + * Usually Spring XML configuration file will contain only one Grid definition. Note that + * Grid configuration bean(s) is retrieved form configuration file by type, so the name of + * the Grid configuration bean is ignored. + * + * @param springCfgUrl Spring XML configuration file URL. This cannot be {@code null}. + * @param ldr Optional class loader that will be used by default. + * @return Started grid. If Spring configuration contains multiple grid instances, + * then the 1st found instance is returned. + * @throws IgniteCheckedException If grid could not be started or configuration + * read. This exception will be thrown also if grid with given name has already + * been started or Spring XML configuration file is invalid. + */ + public static Ignite start(URL springCfgUrl, @Nullable ClassLoader ldr) throws IgniteCheckedException { + return start(springCfgUrl, null, null, ldr); } /** @@ -745,6 +767,7 @@ public class IgnitionEx { * @param springCfgUrl Spring XML configuration file URL. This cannot be {@code null}. * @param gridName Grid name that will override default. * @param springCtx Optional Spring application context, possibly {@code null}. + * @param ldr Optional class loader that will be used by default. * Spring bean definitions for bean injection are taken from this context. * If provided, this context can be injected into grid tasks and grid jobs using * {@link SpringApplicationContextResource @SpringApplicationContextResource} annotation. @@ -755,7 +778,7 @@ public class IgnitionEx { * been started or Spring XML configuration file is invalid. */ public static Ignite start(URL springCfgUrl, @Nullable String gridName, - @Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException { + @Nullable GridSpringResourceContext springCtx, @Nullable ClassLoader ldr) throws IgniteCheckedException { A.notNull(springCfgUrl, "springCfgUrl"); boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null; @@ -789,7 +812,7 @@ public class IgnitionEx { U.removeJavaNoOpLogger(savedHnds); } - return startConfigurations(cfgMap, springCfgUrl, gridName, springCtx); + return startConfigurations(cfgMap, springCfgUrl, gridName, springCtx, ldr); } /** @@ -809,7 +832,7 @@ public class IgnitionEx { * been started or Spring XML configuration file is invalid. */ public static Ignite start(InputStream springCfgStream) throws IgniteCheckedException { - return start(springCfgStream, null, null); + return start(springCfgStream, null, null, null); } /** @@ -824,6 +847,7 @@ public class IgnitionEx { * @param springCfgStream Input stream containing Spring XML configuration. This cannot be {@code null}. * @param gridName Grid name that will override default. * @param springCtx Optional Spring application context, possibly {@code null}. + * @param ldr Optional class loader that will be used by default. * Spring bean definitions for bean injection are taken from this context. * If provided, this context can be injected into grid tasks and grid jobs using * {@link SpringApplicationContextResource @SpringApplicationContextResource} annotation. @@ -834,7 +858,7 @@ public class IgnitionEx { * been started or Spring XML configuration file is invalid. */ public static Ignite start(InputStream springCfgStream, @Nullable String gridName, - @Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException { + @Nullable GridSpringResourceContext springCtx, @Nullable ClassLoader ldr) throws IgniteCheckedException { A.notNull(springCfgStream, "springCfgUrl"); boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null; @@ -868,7 +892,7 @@ public class IgnitionEx { U.removeJavaNoOpLogger(savedHnds); } - return startConfigurations(cfgMap, null, gridName, springCtx); + return startConfigurations(cfgMap, null, gridName, springCtx, ldr); } /** @@ -878,6 +902,7 @@ public class IgnitionEx { * @param springCfgUrl Spring XML configuration file URL. * @param gridName Grid name that will override default. * @param springCtx Optional Spring application context. + * @param ldr Optional class loader that will be used by default. * @return Started grid. * @throws IgniteCheckedException If failed. */ @@ -885,7 +910,8 @@ public class IgnitionEx { IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> cfgMap, URL springCfgUrl, @Nullable String gridName, - @Nullable GridSpringResourceContext springCtx) + @Nullable GridSpringResourceContext springCtx, + @Nullable ClassLoader ldr) throws IgniteCheckedException { List<IgniteNamedInstance> grids = new ArrayList<>(cfgMap.size()); @@ -896,6 +922,9 @@ public class IgnitionEx { if (cfg.getGridName() == null && !F.isEmpty(gridName)) cfg.setGridName(gridName); + if (ldr != null && cfg.getClassLoader() == null) + cfg.setClassLoader(ldr); + // Use either user defined context or our one. IgniteNamedInstance grid = start0( new GridStartContext(cfg, springCfgUrl, springCtx == null ? cfgMap.get2() : springCtx)); http://git-wip-us.apache.org/repos/asf/ignite/blob/bd1f506e/modules/spring/src/main/java/org/apache/ignite/IgniteSpring.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/ignite/IgniteSpring.java b/modules/spring/src/main/java/org/apache/ignite/IgniteSpring.java index 9c70591..ddb44a7 100644 --- a/modules/spring/src/main/java/org/apache/ignite/IgniteSpring.java +++ b/modules/spring/src/main/java/org/apache/ignite/IgniteSpring.java @@ -87,7 +87,7 @@ public class IgniteSpring { * been started or Spring XML configuration file is invalid. */ public static Ignite start(String springCfgPath, @Nullable ApplicationContext springCtx) throws IgniteCheckedException { - return IgnitionEx.start(springCfgPath, null, new GridSpringResourceContextImpl(springCtx)); + return IgnitionEx.start(springCfgPath, null, new GridSpringResourceContextImpl(springCtx), null); } /** @@ -111,6 +111,6 @@ public class IgniteSpring { * been started or Spring XML configuration file is invalid. */ public static Ignite start(URL springCfgUrl, @Nullable ApplicationContext springCtx) throws IgniteCheckedException { - return IgnitionEx.start(springCfgUrl, null, new GridSpringResourceContextImpl(springCtx)); + return IgnitionEx.start(springCfgUrl, null, new GridSpringResourceContextImpl(springCtx), null); } } \ No newline at end of file