use of java.nio.channels.ClosedByInterruptException in project ignite by apache.
the class FileWriteAheadLogManager method initNextWriteHandle.
/**
* Fills the file header for a new segment. Calling this method signals we are done with the segment and it can be
* archived. If we don't have prepared file yet and achiever is busy this method blocks.
*
* @param cur Current file write handle released by WAL writer.
* @return Initialized file handle.
* @throws IgniteCheckedException If exception occurred.
*/
private FileWriteHandle initNextWriteHandle(FileWriteHandle cur) throws IgniteCheckedException {
IgniteCheckedException error = null;
try {
File nextFile = pollNextFile(cur.getSegmentId());
if (log.isDebugEnabled())
log.debug("Switching to a new WAL segment: " + nextFile.getAbsolutePath());
SegmentIO fileIO = null;
FileWriteHandle hnd;
boolean interrupted = false;
if (switchSegmentRecordOffset != null)
switchSegmentRecordOffset.set((int) ((cur.getSegmentId() + 1) % dsCfg.getWalSegments()), 0);
while (true) {
try {
fileIO = new SegmentIO(cur.getSegmentId() + 1, ioFactory.create(nextFile));
IgniteInClosure<FileIO> lsnr = createWalFileListener;
if (lsnr != null)
lsnr.apply(fileIO);
hnd = fileHandleManager.nextHandle(fileIO, serializer);
if (interrupted)
Thread.currentThread().interrupt();
break;
} catch (ClosedByInterruptException ignore) {
interrupted = true;
Thread.interrupted();
if (fileIO != null) {
try {
fileIO.close();
} catch (IOException ignored) {
// No-op.
}
fileIO = null;
}
}
}
hnd.writeHeader();
return hnd;
} catch (IgniteCheckedException e) {
throw error = e;
} catch (IOException e) {
throw error = new StorageException("Unable to initialize WAL segment", e);
} finally {
if (error != null)
cctx.kernalContext().failure().process(new FailureContext(CRITICAL_ERROR, error));
}
}
use of java.nio.channels.ClosedByInterruptException in project ToyShark by LipiLee.
the class SocketDataReaderWorker method readTCP.
private void readTCP(@NonNull Session session) {
if (session.isAbortingConnection()) {
return;
}
SocketChannel channel = (SocketChannel) session.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(DataConst.MAX_RECEIVE_BUFFER_SIZE);
int len;
try {
do {
if (!session.isClientWindowFull()) {
len = channel.read(buffer);
if (len > 0) {
// -1 mean it reach the end of stream
// Log.d(TAG,"SocketDataService received "+len+" from remote server: "+name);
sendToRequester(buffer, len, session);
buffer.clear();
} else if (len == -1) {
Log.d(TAG, "End of data from remote server, will send FIN to client");
Log.d(TAG, "send FIN to: " + sessionKey);
sendFin(session);
session.setAbortingConnection(true);
}
} else {
Log.e(TAG, "*** client window is full, now pause for " + sessionKey);
break;
}
} while (len > 0);
} catch (NotYetConnectedException e) {
Log.e(TAG, "socket not connected");
} catch (ClosedByInterruptException e) {
Log.e(TAG, "ClosedByInterruptException reading SocketChannel: " + e.getMessage());
// session.setAbortingConnection(true);
} catch (ClosedChannelException e) {
Log.e(TAG, "ClosedChannelException reading SocketChannel: " + e.getMessage());
// session.setAbortingConnection(true);
} catch (IOException e) {
Log.e(TAG, "Error reading data from SocketChannel: " + e.getMessage());
session.setAbortingConnection(true);
}
}
use of java.nio.channels.ClosedByInterruptException in project bazel by bazelbuild.
the class GenQuery method doQuery.
@SuppressWarnings("unchecked")
@Nullable
private byte[] doQuery(QueryOptions queryOptions, PackageProvider packageProvider, Predicate<Label> labelFilter, TargetPatternEvaluator evaluator, String query, RuleContext ruleContext) throws InterruptedException {
DigraphQueryEvalResult<Target> queryResult;
OutputFormatter formatter;
AggregateAllOutputFormatterCallback<Target> targets = QueryUtil.newOrderedAggregateAllOutputFormatterCallback();
try {
Set<Setting> settings = queryOptions.toSettings();
// Turns out, if we have two targets with a cycle of length 2 were one of
// the edges is of type NODEP_LABEL type, the targets both show up in
// each other's result for deps(X) when the query is executed using
// 'blaze query'. This obviously does not fly when doing the query as a
// part of the build, thus, there is a slight discrepancy between the
// behavior of the query engine in these two use cases.
settings.add(Setting.NO_NODEP_DEPS);
ImmutableList<OutputFormatter> outputFormatters = QUERY_OUTPUT_FORMATTERS.get(ruleContext.getAnalysisEnvironment().getSkyframeEnv());
// This is a precomputed value so it should have been injected by the rules module by the
// time we get there.
formatter = OutputFormatter.getFormatter(Preconditions.checkNotNull(outputFormatters), queryOptions.outputFormat);
// All the packages are already loaded at this point, so there is no need
// to start up many threads. 4 are started up to make good use of multiple
// cores.
BlazeQueryEnvironment queryEnvironment = (BlazeQueryEnvironment) QUERY_ENVIRONMENT_FACTORY.create(/*transitivePackageLoader=*/
null, /*graph=*/
null, packageProvider, evaluator, /*keepGoing=*/
false, ruleContext.attributes().get("strict", Type.BOOLEAN), /*orderedResults=*/
!QueryOutputUtils.shouldStreamResults(queryOptions, formatter), /*universeScope=*/
ImmutableList.<String>of(), /*loadingPhaseThreads=*/
4, labelFilter, getEventHandler(ruleContext), settings, ImmutableList.<QueryFunction>of(), /*packagePath=*/
null, /*blockUniverseEvaluationErrors=*/
false);
queryResult = (DigraphQueryEvalResult<Target>) queryEnvironment.evaluateQuery(query, targets);
} catch (SkyframeRestartQueryException e) {
// inconsistent from run to run, and make detecting legitimate errors more difficult.
return null;
} catch (QueryException e) {
ruleContext.ruleError("query failed: " + e.getMessage());
return null;
} catch (IOException e) {
throw new RuntimeException(e);
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
QueryOutputUtils.output(queryOptions, queryResult, targets.getResult(), formatter, outputStream, queryOptions.aspectDeps.createResolver(packageProvider, getEventHandler(ruleContext)));
} catch (ClosedByInterruptException e) {
throw new InterruptedException(e.getMessage());
} catch (IOException e) {
throw new RuntimeException(e);
}
return outputStream.toByteArray();
}
use of java.nio.channels.ClosedByInterruptException in project che by eclipse.
the class CompositeLineConsumerTest method stopsWritingOnceInterrupted.
@Test
public void stopsWritingOnceInterrupted() throws Exception {
doThrow(new ClosedByInterruptException()).when(lineConsumer2).writeLine("test");
compositeLineConsumer.writeLine("test");
assertTrue(Thread.interrupted());
verify(lineConsumer1).writeLine("test");
verify(lineConsumer2).writeLine("test");
verify(lineConsumer3, never()).writeLine("test");
}
use of java.nio.channels.ClosedByInterruptException in project buck by facebook.
the class MoreThrowablesTest method closedByInterruptException.
@Test
public void closedByInterruptException() throws InterruptedException {
ClosedByInterruptException e = new ClosedByInterruptException();
expected.expect(InterruptedException.class);
expected.expect(CausedBy.causedBy(e));
MoreThrowables.propagateIfInterrupt(e);
}
Aggregations