use of org.apache.ignite.IgniteException in project ignite by apache.
the class WebSessionV2 method getAttribute.
/**
* {@inheritDoc}
*/
@Override
public Object getAttribute(final String name) {
assertValid();
Object attr = attributes().get(name);
if (attr == REMOVED_ATTR)
return null;
if (attr == null) {
final byte[] bytes = entity.attributes().get(name);
if (bytes != null) {
// deserialize
try {
attr = unmarshal(bytes);
} catch (IOException e) {
throw new IgniteException(e);
}
attributes().put(name, attr);
}
}
return attr;
}
use of org.apache.ignite.IgniteException 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.IgniteException in project ignite by apache.
the class IgniteIoTestAbstractBenchmark method setUp.
/**
* {@inheritDoc}
*/
@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
super.setUp(cfg);
ignite = (IgniteKernal) ignite();
ClusterNode loc = ignite().cluster().localNode();
Collection<ClusterNode> nodes = ignite().cluster().forServers().nodes();
for (ClusterNode node : nodes) {
if (!loc.equals(node))
targetNodes.add(node);
}
if (targetNodes.isEmpty())
throw new IgniteException("Failed to find remote server nodes [nodes=" + nodes + ']');
BenchmarkUtils.println(cfg, "Initialized target nodes: " + F.nodeIds(targetNodes) + ']');
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class IgniteJdbcSqlQueryBenchmark method createStatement.
/**
* @return Prepared statement.
* @throws Exception
*/
private PreparedStatement createStatement() throws Exception {
Class.forName("org.apache.ignite.IgniteJdbcDriver");
Connection conn = null;
try {
conn = DriverManager.getConnection(args.jdbcUrl());
return conn.prepareStatement("select * from Person where salary >= ? and salary <= ?");
} catch (Exception e) {
if (conn != null)
conn.close();
throw new IgniteException("Failed to create prepare statement.", e);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class RocketMQStreamer method start.
/**
* Starts streamer.
*
* @throws IgniteException If failed.
*/
public void start() {
if (!stopped)
throw new IgniteException("Attempted to start an already started RocketMQ streamer");
// validate parameters.
A.notNull(getStreamer(), "streamer");
A.notNull(getIgnite(), "ignite");
A.notNull(topic, "topic");
A.notNull(consumerGrp, "consumer group");
A.notNullOrEmpty(nameSrvAddr, "nameserver address");
A.ensure(null != getMultipleTupleExtractor(), "Multiple tuple extractor must be configured");
log = getIgnite().log();
consumer = new DefaultMQPushConsumer(consumerGrp);
consumer.setNamesrvAddr(nameSrvAddr);
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
try {
consumer.subscribe(topic, "*");
} catch (MQClientException e) {
throw new IgniteException("Failed to subscribe to " + topic, e);
}
consumer.registerMessageListener(this);
try {
consumer.start();
} catch (MQClientException e) {
throw new IgniteException("Failed to start the streamer", e);
}
stopped = false;
}
Aggregations