use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class GridCacheQueryFutureAdapter method internalIterator.
/**
* @return Iterator.
* @throws IgniteCheckedException In case of error.
*/
private Iterator<R> internalIterator() throws IgniteCheckedException {
checkError();
Iterator<R> it = null;
while (it == null || !it.hasNext()) {
Collection<R> c;
synchronized (this) {
it = iter;
if (it != null && it.hasNext())
break;
c = queue.poll();
if (c != null)
it = iter = c.iterator();
if (isDone() && queue.peek() == null)
break;
}
if (c == null && !isDone()) {
loadPage();
long timeout = qry.query().timeout();
long waitTime = timeout == 0 ? Long.MAX_VALUE : timeout - (U.currentTimeMillis() - startTime);
if (waitTime <= 0) {
it = Collections.<R>emptyList().iterator();
break;
}
synchronized (this) {
try {
if (queue.isEmpty() && !isDone())
wait(waitTime);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteCheckedException("Query was interrupted: " + qry, e);
}
}
}
}
checkError();
return it;
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class IpcSharedMemoryNativeLoader method doLoad.
/**
* @throws IgniteCheckedException If failed.
*/
private static void doLoad(IgniteLogger log) throws IgniteCheckedException {
assert Thread.holdsLock(IpcSharedMemoryNativeLoader.class);
Collection<Throwable> errs = new ArrayList<>();
try {
// Load native library (the library directory should be in java.library.path).
System.loadLibrary(LIB_NAME);
return;
} catch (UnsatisfiedLinkError e) {
errs.add(e);
}
File tmpDir = getUserSpecificTempDir();
File lockFile = new File(tmpDir, "igniteshmem.lock");
// Obtain lock on file to prevent concurrent extracts.
try (RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile, "rws");
FileLock ignored = randomAccessFile.getChannel().lock()) {
if (extractAndLoad(errs, tmpDir, platformSpecificResourcePath()))
return;
if (extractAndLoad(errs, tmpDir, osSpecificResourcePath()))
return;
if (extractAndLoad(errs, tmpDir, resourcePath()))
return;
try {
if (log != null)
LT.warn(log, "Failed to load 'igniteshmem' library from classpath. Will try to load it from IGNITE_HOME.");
String igniteHome = X.resolveIgniteHome();
File shmemJar = findShmemJar(errs, igniteHome);
if (shmemJar != null) {
try (JarFile jar = new JarFile(shmemJar, false, JarFile.OPEN_READ)) {
if (extractAndLoad(errs, jar, tmpDir, platformSpecificResourcePath()))
return;
if (extractAndLoad(errs, jar, tmpDir, osSpecificResourcePath()))
return;
if (extractAndLoad(errs, jar, tmpDir, resourcePath()))
return;
}
}
} catch (IgniteCheckedException ignore) {
// No-op.
}
// Failed to find the library.
assert !errs.isEmpty();
throw new IgniteCheckedException("Failed to load native IPC library: " + errs);
} catch (IOException e) {
throw new IgniteCheckedException("Failed to obtain file lock: " + lockFile, e);
}
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class IpcSharedMemoryNativeLoader method getUserSpecificTempDir.
/**
* Gets temporary directory unique for each OS user.
* The directory guaranteed to exist, though may not be empty.
*/
private static File getUserSpecificTempDir() throws IgniteCheckedException {
String tmp = System.getProperty("java.io.tmpdir");
String userName = System.getProperty("user.name");
File tmpDir = new File(tmp, userName);
if (!tmpDir.exists())
// noinspection ResultOfMethodCallIgnored
tmpDir.mkdirs();
if (!(tmpDir.exists() && tmpDir.isDirectory()))
throw new IgniteCheckedException("Failed to create temporary directory [dir=" + tmpDir + ']');
return tmpDir;
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class IpcSharedMemoryServerEndpoint method accept.
/**
* {@inheritDoc}
*/
@SuppressWarnings("ErrorNotRethrown")
@Override
public IpcEndpoint accept() throws IgniteCheckedException {
while (!Thread.currentThread().isInterrupted()) {
Socket sock = null;
boolean accepted = false;
try {
sock = srvSock.accept();
accepted = true;
InputStream inputStream = sock.getInputStream();
ObjectInputStream in = new ObjectInputStream(inputStream);
ObjectOutputStream out = new ObjectOutputStream(sock.getOutputStream());
IpcSharedMemorySpace inSpace = null;
IpcSharedMemorySpace outSpace = null;
boolean err = true;
try {
IpcSharedMemoryInitRequest req = (IpcSharedMemoryInitRequest) in.readObject();
if (log.isDebugEnabled())
log.debug("Processing request: " + req);
IgnitePair<String> p = inOutToken(req.pid(), size);
String file1 = p.get1();
String file2 = p.get2();
assert file1 != null;
assert file2 != null;
// Create tokens.
new File(file1).createNewFile();
new File(file2).createNewFile();
if (log.isDebugEnabled())
log.debug("Created token files: " + p);
inSpace = new IpcSharedMemorySpace(file1, req.pid(), pid, size, true, log);
outSpace = new IpcSharedMemorySpace(file2, pid, req.pid(), size, false, log);
IpcSharedMemoryClientEndpoint ret = new IpcSharedMemoryClientEndpoint(inSpace, outSpace, log);
out.writeObject(new IpcSharedMemoryInitResponse(file2, outSpace.sharedMemoryId(), file1, inSpace.sharedMemoryId(), pid, size));
err = !in.readBoolean();
endpoints.add(ret);
return ret;
} catch (UnsatisfiedLinkError e) {
throw IpcSharedMemoryUtils.linkError(e);
} catch (IOException e) {
if (log.isDebugEnabled())
log.debug("Failed to process incoming connection " + "(was connection closed by another party):" + e.getMessage());
} catch (ClassNotFoundException e) {
U.error(log, "Failed to process incoming connection.", e);
} catch (ClassCastException e) {
String msg = "Failed to process incoming connection (most probably, shared memory " + "rest endpoint has been configured by mistake).";
LT.warn(log, msg);
sendErrorResponse(out, e);
} catch (IpcOutOfSystemResourcesException e) {
if (!omitOutOfResourcesWarn)
LT.warn(log, OUT_OF_RESOURCES_MSG);
sendErrorResponse(out, e);
} catch (IgniteCheckedException e) {
LT.error(log, e, "Failed to process incoming shared memory connection.");
sendErrorResponse(out, e);
} finally {
// Exception has been thrown, need to free system resources.
if (err) {
if (inSpace != null)
inSpace.forceClose();
// Safety.
if (outSpace != null)
outSpace.forceClose();
}
}
} catch (IOException e) {
if (!Thread.currentThread().isInterrupted() && !accepted)
throw new IgniteCheckedException("Failed to accept incoming connection.", e);
if (!closed)
LT.error(log, null, "Failed to process incoming shared memory connection: " + e.getMessage());
} finally {
U.closeQuiet(sock);
}
}
throw new IgniteInterruptedCheckedException("Socket accept was interrupted.");
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class GridShmemCommunicationClient method sendMessage.
/**
* {@inheritDoc}
*/
@Override
public synchronized boolean sendMessage(UUID nodeId, Message msg, IgniteInClosure<IgniteException> c) throws IgniteCheckedException {
assert nodeId != null;
if (closed())
throw new IgniteCheckedException("Communication client was closed: " + this);
assert writeBuf.hasArray();
try {
int cnt = U.writeMessageFully(msg, shmem.outputStream(), writeBuf, formatter.writer(nodeId));
metricsLsnr.onBytesSent(cnt);
} catch (IOException e) {
throw new IgniteCheckedException("Failed to send message to remote node: " + shmem, e);
}
markUsed();
if (c != null)
c.apply(null);
return false;
}
Aggregations