use of org.apache.ignite.IgniteIllegalStateException in project ignite by apache.
the class IgnitionEx method grid.
/**
* Gets an named grid instance. If grid name is {@code null} or empty string,
* then default no-name grid will be returned. Note that caller of this method
* should not assume that it will return the same instance every time.
* <p>
* Note that Java VM can run multiple grid instances and every grid instance (and its
* node) can belong to a different grid. Grid name defines what grid a particular grid
* instance (and correspondingly its node) belongs to.
*
* @param name Grid name to which requested grid instance belongs to. If {@code null},
* then grid instance belonging to a default no-name grid will be returned.
* @return An instance of named grid. This method never returns
* {@code null}.
* @throws IgniteIllegalStateException Thrown if default grid was not properly
* initialized or grid instance was stopped or was not started.
*/
public static Ignite grid(@Nullable String name) throws IgniteIllegalStateException {
IgniteNamedInstance grid = name != null ? grids.get(name) : dfltGrid;
Ignite res;
if (grid == null || (res = grid.grid()) == null)
throw new IgniteIllegalStateException("Ignite instance with provided name doesn't exist. " + "Did you call Ignition.start(..) to start an Ignite instance? [name=" + name + ']');
return res;
}
use of org.apache.ignite.IgniteIllegalStateException in project ignite by apache.
the class GridBinaryMarshaller method threadLocalContext.
/**
* @return Thread-bound context.
*/
public static BinaryContext threadLocalContext() {
BinaryContext ctx = GridBinaryMarshaller.BINARY_CTX.get();
if (ctx == null) {
IgniteKernal ignite = IgnitionEx.localIgnite();
IgniteCacheObjectProcessor proc = ignite.context().cacheObjects();
if (proc instanceof CacheObjectBinaryProcessorImpl)
return ((CacheObjectBinaryProcessorImpl) proc).binaryContext();
else
throw new IgniteIllegalStateException("Ignite instance must be started with " + BinaryMarshaller.class.getName() + " [name=" + ignite.name() + ']');
}
return ctx;
}
use of org.apache.ignite.IgniteIllegalStateException in project ignite by apache.
the class TcpDiscoverySelfTest method waitNodeStop.
/**
* @param nodeName Node name.
* @throws Exception If failed.
*/
private void waitNodeStop(final String nodeName) throws Exception {
boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
Ignition.ignite(nodeName);
return false;
} catch (IgniteIllegalStateException ignored) {
return true;
}
}
}, 30_000);
if (!wait)
U.dumpThreads(log);
assertTrue("Failed to wait for node stop.", wait);
}
use of org.apache.ignite.IgniteIllegalStateException in project ignite by apache.
the class ServletContextListenerStartup method contextInitialized.
/** {@inheritDoc} */
@Override
public void contextInitialized(ServletContextEvent evt) {
ServletContext ctx = evt.getServletContext();
String cfgFile = ctx.getInitParameter(IGNITE_CFG_FILE_PATH_PARAM);
Collection<IgniteConfiguration> cfgs;
GridSpringResourceContext rsrcCtx = null;
if (cfgFile != null) {
URL cfgUrl = null;
try {
cfgUrl = evt.getServletContext().getResource("/META-INF/" + cfgFile);
} catch (MalformedURLException ignored) {
// Ignore, we still need to try with IGNITE_HOME.
}
if (cfgUrl == null)
// Try with IGNITE_HOME and with context class loader.
cfgUrl = U.resolveIgniteUrl(cfgFile);
if (cfgUrl == null)
throw new IgniteException("Failed to find Spring configuration file (path provided should be " + "either absolute, relative to IGNITE_HOME, or relative to META-INF folder): " + cfgFile);
IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> t;
try {
t = IgnitionEx.loadConfigurations(cfgUrl);
} catch (IgniteCheckedException e) {
throw new IgniteException("Failed to load Ignite configuration.", e);
}
cfgs = t.get1();
rsrcCtx = t.get2();
if (cfgs.isEmpty())
throw new IgniteException("Can't find grid factory configuration in: " + cfgUrl);
} else
cfgs = Collections.<IgniteConfiguration>singleton(new IgniteConfiguration());
try {
assert !cfgs.isEmpty();
for (IgniteConfiguration cfg : cfgs) {
assert cfg != null;
Ignite ignite;
synchronized (ServletContextListenerStartup.class) {
try {
ignite = G.ignite(cfg.getIgniteInstanceName());
} catch (IgniteIllegalStateException ignored) {
ignite = IgnitionEx.start(new IgniteConfiguration(cfg), rsrcCtx);
}
}
// Check if grid is not null - started properly.
if (ignite != null)
igniteInstanceNames.add(ignite.name());
}
} catch (IgniteCheckedException e) {
// Stop started grids only.
for (String name : igniteInstanceNames) G.stop(name, true);
throw new IgniteException("Failed to start Ignite.", e);
}
}
use of org.apache.ignite.IgniteIllegalStateException in project ignite by apache.
the class IgnitionEx method gridx.
/**
* Gets grid instance without waiting its initialization.
*
* @param name Grid name.
* @return Grid instance.
*/
public static IgniteKernal gridx(@Nullable String name) {
IgniteNamedInstance grid = name != null ? grids.get(name) : dfltGrid;
IgniteKernal res;
if (grid == null || (res = grid.gridx()) == null)
throw new IgniteIllegalStateException("Ignite instance with provided name doesn't exist. " + "Did you call Ignition.start(..) to start an Ignite instance? [name=" + name + ']');
return res;
}
Aggregations