use of org.apache.ignite.IgniteException in project ignite by apache.
the class GridTaskSessionImpl method removeCheckpoint0.
/**
* @param ses Session.
* @param key Key.
* @return {@code True} if removed.
* @throws IgniteException If failed.
*/
protected boolean removeCheckpoint0(GridTaskSessionInternal ses, String key) throws IgniteException {
// Internal call, so assert should be enough.
assert ses != null;
A.notNull(key, "key");
if (closed)
throw new IgniteException("Failed to remove checkpoint (session closed): " + ses);
checkFullSupport();
return ctx.checkpoint().removeCheckpoint(ses, key);
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class GridTaskSessionImpl method saveCheckpoint0.
/**
* @param ses Session.
* @param key Key.
* @param state State.
* @param scope Scope.
* @param timeout Timeout.
* @param overwrite Overwrite.
* @throws IgniteException If failed.
*/
protected void saveCheckpoint0(GridTaskSessionInternal ses, String key, Object state, ComputeTaskSessionScope scope, long timeout, boolean overwrite) throws IgniteException {
// Internal call, so assert should be enough.
assert ses != null;
A.notNull(key, "key");
A.ensure(timeout >= 0, "timeout >= 0");
if (closed)
throw new IgniteException("Failed to save checkpoint (session closed): " + ses);
checkFullSupport();
try {
ctx.checkpoint().storeCheckpoint(ses, key, state, scope, timeout, overwrite);
} catch (IgniteCheckedException e) {
throw U.convertException(e);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class BinaryContext method userTypeMapper.
/**
* @param clsName Type name.
* @return Instance of ID mapper.
*/
BinaryInternalMapper userTypeMapper(String clsName) {
BinaryInternalMapper mapper = cls2Mappers.get(clsName);
if (mapper != null)
return mapper;
mapper = resolveMapper(clsName, igniteCfg.getBinaryConfiguration());
BinaryInternalMapper prevMap = cls2Mappers.putIfAbsent(clsName, mapper);
if (prevMap != null && !mapper.equals(prevMap))
throw new IgniteException("Different mappers [clsName=" + clsName + ", newMapper=" + mapper + ", prevMap=" + prevMap + "]");
prevMap = typeId2Mapper.putIfAbsent(mapper.typeId(clsName), mapper);
if (prevMap != null && !mapper.equals(prevMap))
throw new IgniteException("Different mappers [clsName=" + clsName + ", newMapper=" + mapper + ", prevMap=" + prevMap + "]");
return mapper;
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class GridTcpRouterImpl method start.
/**
* Starts router.
*
* @throws IgniteException If failed.
*/
@Override
public void start() throws IgniteException {
try {
client = createClient(cfg);
} catch (GridClientException e) {
throw new IgniteException("Failed to initialise embedded client.", e);
}
GridNioServerListener<GridClientMessage> lsnr;
try {
Class<?> cls = Class.forName(ENT_NIO_LSNR_CLS);
Constructor<?> cons = cls.getDeclaredConstructor(IgniteLogger.class, GridRouterClientImpl.class);
cons.setAccessible(true);
lsnr = (GridNioServerListener<GridClientMessage>) cons.newInstance(log, client);
} catch (ClassNotFoundException ignored) {
lsnr = new GridTcpRouterNioListenerOsImpl(log, client);
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new IgniteException("Failed to create NIO listener.", e);
}
parser = new GridTcpRouterNioParser();
final InetAddress hostAddr;
try {
hostAddr = InetAddress.getByName(cfg.getHost());
} catch (UnknownHostException e) {
throw new IgniteException("Failed to resolve grid address for configured host: " + cfg.getHost(), e);
}
SSLContext sslCtx;
try {
GridSslContextFactory sslCtxFactory = cfg.getSslContextFactory();
sslCtx = sslCtxFactory == null ? null : sslCtxFactory.createSslContext();
} catch (SSLException e) {
throw new IgniteException("Failed to create SSL context.", e);
}
for (int port = cfg.getPort(), last = port + cfg.getPortRange(); port <= last; port++) {
if (startTcpServer(hostAddr, port, lsnr, parser, cfg.isNoDelay(), sslCtx, cfg.isSslClientAuth(), cfg.isSslClientAuth())) {
if (log.isInfoEnabled())
log.info("TCP router successfully started for endpoint: " + hostAddr.getHostAddress() + ":" + port);
bindPort = port;
bindHost = hostAddr.getHostName();
break;
} else
U.warn(log, "TCP REST router failed to start on endpoint: " + hostAddr.getHostAddress() + ":" + port + ". Will try next port within allowed port range.");
}
if (bindPort == 0)
throw new IgniteException("Failed to bind TCP router server (possibly all ports in range " + "are in use) [firstPort=" + cfg.getPort() + ", lastPort=" + (cfg.getPort() + cfg.getPortRange()) + ", addr=" + hostAddr + ']');
try {
ObjectName objName = U.registerMBean(ManagementFactory.getPlatformMBeanServer(), "Router", "TCP Router " + id, getClass().getSimpleName(), this, GridTcpRouterMBean.class);
if (log.isDebugEnabled())
log.debug("Registered MBean: " + objName);
mbeanName = objName;
} catch (JMException e) {
U.error(log, "Failed to register MBean.", e);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class GridIoManager method addMessageListener.
/**
* @param topic Listener's topic.
* @param lsnr Listener to add.
*/
@SuppressWarnings({ "deprecation", "SynchronizationOnLocalVariableOrMethodParameter" })
public void addMessageListener(Object topic, final GridMessageListener lsnr) {
assert lsnr != null;
assert topic != null;
// Make sure that new topic is not in the list of closed topics.
closedTopics.remove(topic);
GridMessageListener lsnrs;
for (; ; ) {
lsnrs = listenerPutIfAbsent0(topic, lsnr);
if (lsnrs == null) {
lsnrs = lsnr;
break;
}
assert lsnrs != null;
if (!(lsnrs instanceof ArrayListener)) {
// We are putting the second listener, creating array.
GridMessageListener arrLsnr = new ArrayListener(lsnrs, lsnr);
if (listenerReplace0(topic, lsnrs, arrLsnr)) {
lsnrs = arrLsnr;
break;
}
} else {
if (((ArrayListener) lsnrs).add(lsnr))
break;
// Add operation failed because array is already empty and is about to be removed, helping and retrying.
listenerRemove0(topic, lsnrs);
}
}
Map<UUID, GridCommunicationMessageSet> map = msgSetMap.get(topic);
Collection<GridCommunicationMessageSet> msgSets = map != null ? map.values() : null;
if (msgSets != null) {
final GridMessageListener lsnrs0 = lsnrs;
try {
for (final GridCommunicationMessageSet msgSet : msgSets) {
pools.poolForPolicy(msgSet.policy()).execute(new Runnable() {
@Override
public void run() {
unwindMessageSet(msgSet, lsnrs0);
}
});
}
} catch (RejectedExecutionException e) {
U.error(log, "Failed to process delayed message due to execution rejection. Increase the upper bound " + "on executor service provided in 'IgniteConfiguration.getPublicThreadPoolSize()'). Will attempt to " + "process message in the listener thread instead.", e);
for (GridCommunicationMessageSet msgSet : msgSets) unwindMessageSet(msgSet, lsnr);
} catch (IgniteCheckedException ice) {
throw new IgniteException(ice);
}
}
}
Aggregations