/** * Perform write. * * @param data Data to be written. * @return {@code True} in case operation was enqueued. */ boolean write(final byte[] data) { return addTask(new GridGgfsFileWorkerTask() { @Override public void execute() throws GridException { try { out.write(data); } catch (IOException e) { throw new GridException("Failed to write data to the file due to secondary file system " + "exception: " + path, e); } } }); }
/** * Await for that worker batch to complete in case it was marked as finished. * * @throws GridException In case any exception has occurred during batch tasks processing. */ void awaitIfFinished() throws GridException { if (finishGuard.get()) await(); }
/** {@inheritDoc} */ @Override protected void cleanup() { assert cancelled; // Cleanup can only be performed on a cancelled worker. // Clear interrupted flag. boolean interrupted = interrupted(); // Process the last batch if any. if (nextBatch != null) nextBatch.process(); onFinish(); // Reset interrupted flag. if (interrupted) interrupt(); }
/** * Forcefully finish execution of all batches. */ void cancel() { lock.lock(); try { cancelled = true; if (curBatch != null) curBatch.finish(); if (nextBatch != null) nextBatch.finish(); cond.signalAll(); // Awake the main loop in case it is still waiting for the next batch. } finally { lock.unlock(); } }
/** * Await for any pending finished writes on the children paths. * * @param paths Paths to check. */ void await(GridGgfsPath... paths) { assert paths != null; for (Map.Entry<GridGgfsPath, GridGgfsFileWorker> workerEntry : workerMap.entrySet()) { GridGgfsPath workerPath = workerEntry.getKey(); boolean await = false; for (GridGgfsPath path : paths) { if (workerPath.isSubDirectoryOf(path) || workerPath.isSame(path)) { await = true; break; } } if (await) { GridGgfsFileWorkerBatch batch = workerEntry.getValue().currentBatch(); if (batch != null) { try { batch.awaitIfFinished(); } catch (GridException ignore) { // No-op. } } } } }
GridGgfsFileWorkerBatch batch = new GridGgfsFileWorkerBatch(path, out);
/** {@inheritDoc} */ @Override protected void cleanup() { assert cancelled; // Cleanup can only be performed on a cancelled worker. // Clear interrupted flag. boolean interrupted = interrupted(); // Process the last batch if any. if (nextBatch != null) nextBatch.process(); onFinish(); // Reset interrupted flag. if (interrupted) interrupt(); }
/** * Forcefully finish execution of all batches. */ void cancel() { lock.lock(); try { cancelled = true; if (curBatch != null) curBatch.finish(); if (nextBatch != null) nextBatch.finish(); cond.signalAll(); // Awake the main loop in case it is still waiting for the next batch. } finally { lock.unlock(); } }
/** * Await for any pending finished writes on the children paths. * * @param paths Paths to check. */ void await(GridGgfsPath... paths) { assert paths != null; for (Map.Entry<GridGgfsPath, GridGgfsFileWorker> workerEntry : workerMap.entrySet()) { GridGgfsPath workerPath = workerEntry.getKey(); boolean await = false; for (GridGgfsPath path : paths) { if (workerPath.isSubDirectoryOf(path) || workerPath.isSame(path)) { await = true; break; } } if (await) { GridGgfsFileWorkerBatch batch = workerEntry.getValue().currentBatch(); if (batch != null) { try { batch.awaitIfFinished(); } catch (GridException ignore) { // No-op. } } } } }
GridGgfsFileWorkerBatch batch = new GridGgfsFileWorkerBatch(path, out);
/** * Await for that worker batch to complete in case it was marked as finished. * * @throws GridException In case any exception has occurred during batch tasks processing. */ void awaitIfFinished() throws GridException { if (finishGuard.get()) await(); }
/** * Perform write. * * @param data Data to be written. * @return {@code True} in case operation was enqueued. */ boolean write(final byte[] data) { return addTask(new GridGgfsFileWorkerTask() { @Override public void execute() throws GridException { try { out.write(data); } catch (IOException e) { throw new GridException("Failed to write data to the file due to secondary file system " + "exception: " + path, e); } } }); }