/** * Starts grid with default configuration. By default this method will * use grid configuration defined in {@code IGNITE_HOME/config/default-config.xml} * configuration file. If such file is not found, then all system defaults will be used. * * @return Started grid. * @throws IgniteCheckedException If default grid could not be started. This exception will be thrown * also if default grid has already been started. */ public static Ignite start() throws IgniteCheckedException { return start((GridSpringResourceContext)null); }
/** * Loads all grid configurations specified within given Spring XML configuration file. * <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 springCfgPath Spring XML configuration file path. This cannot be {@code null}. * @return Tuple containing all loaded configurations and Spring context used to load them. * @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 IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> loadConfigurations(String springCfgPath) throws IgniteCheckedException { A.notNull(springCfgPath, "springCfgPath"); return loadConfigurations(IgniteUtils.resolveSpringUrl(springCfgPath)); }
/** * Stops default grid. This method is identical to {@code G.stop(null, cancel)} apply. * Note that method does not wait for all tasks to be completed. * * @param cancel If {@code true} then all jobs currently executing on * default grid will be cancelled by calling {@link ComputeJob#cancel()} * method. Note that just like with {@link Thread#interrupt()}, it is * up to the actual job to exit from execution * @return {@code true} if default grid instance was indeed stopped, * {@code false} otherwise (if it was not started). */ public static boolean stop(boolean cancel) { return stop(null, cancel, false); }
IgnitionEx.loadConfigurations(cfgUrl); Ignite ignite = IgnitionEx.start(adapter, t.get2());
/** * Create configuration. * * @param springCfgPath Path to Spring XML. * @return Configuration. */ private static IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> configuration( @Nullable String springCfgPath) { if (springCfgPath == null) return new T2<>(new IgniteConfiguration(), null); try { URL url = U.resolveSpringUrl(springCfgPath); return IgnitionEx.loadConfiguration(url); } catch (IgniteCheckedException e) { throw new IgniteException("Failed to instantiate configuration from Spring XML: " + springCfgPath, e); } }
cfgMap = loadConfigurations(springCfgUrl); return startConfigurations(cfgMap, springCfgUrl, igniteInstanceName, springCtx, ldr);
/** * Gets state of grid default grid. * * @return Default grid state. */ public static IgniteState state() { return state(null); }
/** * This method is used to address a local {@link Ignite} instance, principally from closure. * <p> * According to contract this method has to be called only under {@link IgniteThread}. * An {@link IllegalArgumentException} will be thrown otherwise. * * @return A current {@link Ignite} instance to address from closure. * @throws IgniteIllegalStateException Thrown if grid was not properly * initialized or grid instance was stopped or was not started * @throws IllegalArgumentException Thrown if current thread is not an {@link IgniteThread}. */ public static Ignite localIgnite() throws IgniteIllegalStateException, IllegalArgumentException { return IgnitionEx.localIgnite(); }
/** * Starts grid with default configuration. By default this method will * use grid configuration defined in {@code IGNITE_HOME/config/default-config.xml} * configuration file. If such file is not found, then all system defaults will be used. * * @param springCtx Optional Spring application context, possibly {@code null}. * 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. * @return Started grid. * @throws IgniteCheckedException If default grid could not be started. This exception will be thrown * also if default grid has already been started. */ public static Ignite start(@Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException { URL url = U.resolveIgniteUrl(DFLT_CFG); if (url != null) return start(DFLT_CFG, null, springCtx, null); U.warn(null, "Default Spring XML file not found (is IGNITE_HOME set?): " + DFLT_CFG); return start0(new GridStartContext(new IgniteConfiguration(), null, springCtx), true) .get1().grid(); }
throws IgniteCheckedException { IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> cfgPair = IgnitionEx.loadConfiguration(igniteCfgPath); T2<Ignite, Boolean> startRes = IgnitionEx.getOrStart(cfg);
/** * Gets a list of all grids started so far. * * @return List of all grids started so far. */ public static List<Ignite> allGrids() { return IgnitionEx.allGrids(); }
t = IgnitionEx.loadConfigurations(cfgUrl); ignite = IgnitionEx.start(new IgniteConfiguration(cfg), rsrcCtx);
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> cfgPair = IgnitionEx.loadConfiguration(cfgPath(getTestIgniteInstanceIndex(gridName))); IgniteConfiguration cfg = cfgPair.get1(); cfg.setIgniteInstanceName(gridName); return cfg; }
cfgMap = loadConfigurations(springCfgStream); return startConfigurations(cfgMap, null, igniteInstanceName, springCtx, ldr);
/** * Gets state of grid default grid. * * @return Default grid state. */ public static IgniteState state() { return IgnitionEx.state(); }
/** * @return IgniteKernal instance. * @throws ObjectStreamException If failed. */ protected Object readResolve() throws ObjectStreamException { try { return IgnitionEx.localIgnite(); } catch (IllegalStateException e) { throw U.withCause(new InvalidObjectException(e.getMessage()), e); } }
/** * Gets a list of all grids started so far. * * @return List of all grids started so far. */ public static List<Ignite> allGridsx() { return allGrids(false); }
/** * Starts all grids specified within given Spring XML configuration input stream. 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 input stream will contain only one Grid definition. Note that * Grid configuration bean(s) is retrieved form configuration input stream by type, so the name of * the Grid configuration bean is ignored. * * @param springCfgStream Input stream containing Spring XML configuration. This cannot be {@code null}. * @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(InputStream springCfgStream) throws IgniteCheckedException { return start(springCfgStream, null, null, null); }
/** * Starts new grid with given name. * * @param gridName Grid name. * @param client Client mode. * @param cfgUrl Config URL. * @return Started grid. * @throws Exception If failed. */ protected Ignite startGridWithSpringCtx(String gridName, boolean client, String cfgUrl) throws Exception { IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> cfgMap = IgnitionEx.loadConfigurations(cfgUrl); IgniteConfiguration cfg = F.first(cfgMap.get1()); cfg.setIgniteInstanceName(gridName); cfg.setClientMode(client); return IgnitionEx.start(cfg, cfgMap.getValue()); }
/** * Stops default grid. This method is identical to {@code G.stop(null, cancel)} apply. * Note that method does not wait for all tasks to be completed. * * @param cancel If {@code true} then all jobs currently executing on * default grid will be cancelled by calling {@link org.apache.ignite.compute.ComputeJob#cancel()} * method. Note that just like with {@link Thread#interrupt()}, it is * up to the actual job to exit from execution * @return {@code true} if default grid instance was indeed stopped, * {@code false} otherwise (if it was not started). */ public static boolean stop(boolean cancel) { return IgnitionEx.stop(cancel); }