/** * Starts grid with given configuration. Note that this method is no-op if grid with the name * provided in given configuration is already started. * * @param cfg Grid configuration. This cannot be {@code null}. * @return Started grid. * @throws GridException If grid could not be started. This exception will be thrown * also if named grid has already been started. */ public static Grid start(GridConfiguration cfg) throws GridException { return GridGainEx.start(cfg); }
/** * Adds a lsnr for grid life cycle events. * <p> * Note that unlike other listeners in GridGain this listener will be * notified from the same thread that triggers the state change. Because of * that it is the responsibility of the user to make sure that listener logic * is light-weight and properly handles (catches) any runtime exceptions, if any * are expected. * * @param lsnr Listener for grid life cycle events. If this listener was already added * this method is no-op. */ public static void addListener(GridGainListener lsnr) { GridGainEx.addListener(lsnr); }
/** * Gets a list of all grids started so far. * * @return List of all grids started so far. */ public static List<Grid> allGrids() { return GridGainEx.allGrids(); }
/** * Start Grid for interop scenario. * * @param springCfgPath Spring config path. * @param gridName Grid name. * @param cfgClo Configuration closure. * @return Started Grid. * @throws GridException If failed. */ public static Grid startInterop(@Nullable String springCfgPath, @Nullable String gridName, GridClosure<GridConfiguration, GridConfiguration> cfgClo) throws GridException { URL url = resolveSpringUrl(springCfgPath); return start(url, gridName, null, cfgClo); }
/** * Starts grid with default configuration. By default this method will * use grid configuration defined in {@code GRIDGAIN_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 GridSpringApplicationContextResource @GridSpringApplicationContextResource} annotation. * @return Started grid. * @throws GridException If default grid could not be started. This exception will be thrown * also if default grid has already been started. */ public static Grid start(@Nullable GridSpringResourceContext springCtx) throws GridException { URL url = U.resolveGridGainUrl(DFLT_CFG); if (url != null) return start(DFLT_CFG, null, springCtx); U.warn(null, "Default Spring XML file not found (is GRIDGAIN_HOME set?): " + DFLT_CFG); return start0(new GridStartContext(new GridConfiguration(), null, springCtx)).grid(); }
/** * Reconstructs object on unmarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of unmarshalling error. */ protected Object readResolve() throws ObjectStreamException { try { return GridGainEx.gridx(stash.get()).nodeLocalMap(); } catch (IllegalStateException e) { throw U.withCause(new InvalidObjectException(e.getMessage()), e); } finally { stash.remove(); } }
cfgMap = loadConfigurations(springCfgUrl); GridNamedInstance grid = start0( new GridStartContext(cfg, springCfgUrl, springCtx == null ? cfgMap.get2() : springCtx));
/** * Gets an instance of default no-name grid. Note that * caller of this method should not assume that it will return the same * instance every time. * <p> * This method is identical to {@code G.grid(null)} apply. * * @return An instance of default no-name grid. This method never returns * {@code null}. * @throws GridIllegalStateException Thrown if default grid was not properly * initialized or grid instance was stopped or was not started. */ public static Grid grid() throws GridIllegalStateException { return grid((String)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 GridException 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 GridBiTuple<Collection<GridConfiguration>, ? extends GridSpringResourceContext> loadConfigurations( String springCfgPath) throws GridException { A.notNull(springCfgPath, "springCfgPath"); URL url; try { url = new URL(springCfgPath); } catch (MalformedURLException e) { url = U.resolveGridGainUrl(springCfgPath); if (url == null) throw new GridException("Spring XML configuration path is invalid: " + springCfgPath + ". Note that this path should be either absolute or a relative local file system path, " + "relative to META-INF in classpath or valid URL to GRIDGAIN_HOME.", e); } return loadConfigurations(url); }
notifyStateChange(dfltGrid0.getName(), dfltGrid0.state()); notifyStateChange(grid.getName(), grid.state());
/** * Removes lsnr added by {@link #addListener(GridGainListener)} method. * * @param lsnr Listener to remove. * @return {@code true} if lsnr was added before, {@code false} otherwise. */ public static boolean removeListener(GridGainListener lsnr) { return GridGainEx.removeListener(lsnr); } }
/** * Gets daemon flag. * <p> * If daemon flag it set then all grid instances created by the factory will be * daemon, i.e. the local node for these instances will be a daemon node. Note that * if daemon flag is set - it will override the same settings in {@link GridConfiguration#isDaemon()}. * Note that you can set on and off daemon flag at will. * * @return Daemon flag. */ public static boolean isDaemon() { return GridGainEx.isDaemon(); }
/** * Stops <b>all</b> started grids. If {@code cancel} flag is set to {@code true} then * all jobs currently executing on the local node will be interrupted. * If {@code wait} parameter is set to {@code true} then grid will wait for all * tasks to be finished. * <p> * <b>Note:</b> it is usually safer and more appropriate to stop grid instances individually * instead of blanket operation. In most cases, the party that started the grid instance * should be responsible for stopping it. * <p> * Note that upon completion of this method, the JVM with forcefully exist with * exit code {@link #KILL_EXIT_CODE}. * * @param cancel If {@code true} then all jobs currently executing on * all grids will be cancelled by calling {@link GridComputeJob#cancel()} * method. Note that just like with {@link Thread#interrupt()}, it is * up to the actual job to exit from execution. * @see #KILL_EXIT_CODE */ public static void kill(boolean cancel) { GridGainEx.kill(cancel); }
/** * Starts all grids specified within given Spring XML configuration file. 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 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}. * 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 GridSpringApplicationContextResource @GridSpringApplicationContextResource} annotation. * @return Started grid. If Spring configuration contains multiple grid instances, * then the 1st found instance is returned. * @throws GridException 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 Grid start(String springCfgPath, @Nullable String gridName, @Nullable GridSpringResourceContext springCtx) throws GridException { URL url = resolveSpringUrl(springCfgPath); return start(url, gridName, springCtx); }
/** * Reconstructs object on unmarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of unmarshalling error. */ protected Object readResolve() throws ObjectStreamException { try { return GridGainEx.gridx(stash.get()).context(); } catch (IllegalStateException e) { throw U.withCause(new InvalidObjectException(e.getMessage()), e); } finally { stash.remove(); } }
/** * Gets an instance of default no-name grid. Note that * caller of this method should not assume that it will return the same * instance every time. * <p> * This method is identical to {@code G.grid(null)} apply. * * @return An instance of default no-name grid. This method never returns * {@code null}. * @throws GridIllegalStateException Thrown if default grid was not properly * initialized or grid instance was stopped or was not started. */ public static Grid grid() throws GridIllegalStateException { return GridGainEx.grid(); }
/** * Loads first found grid configuration 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 springCfgUrl Spring XML configuration file path or URL. This cannot be {@code null}. * @return First found configuration and Spring context used to load it. * @throws GridException 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 GridBiTuple<GridConfiguration, GridSpringResourceContext> loadConfiguration(URL springCfgUrl) throws GridException { GridBiTuple<Collection<GridConfiguration>, ? extends GridSpringResourceContext> t = loadConfigurations(springCfgUrl); return F.t(F.first(t.get1()), t.get2()); }
notifyStateChange(grid.getName(), grid.state());
/** * Starts grid with default configuration. By default this method will * use grid configuration defined in {@code GRIDGAIN_HOME/config/default-config.xml} * configuration file. If such file is not found, then all system defaults will be used. * * @return Started grid. * @throws GridException If default grid could not be started. This exception will be thrown * also if default grid has already been started. */ public static Grid start() throws GridException { return GridGainEx.start(); }
/** * Reconstructs object on unmarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of unmarshalling error. */ protected Object readResolve() throws ObjectStreamException { try { GridBiTuple<String, String> t = stash.get(); return GridGainEx.gridx(t.get1()).cachex(t.get2()); } catch (IllegalStateException e) { throw U.withCause(new InvalidObjectException(e.getMessage()), e); } finally { stash.remove(); } }