Search in sources :

Example 36 with ClosedByInterruptException

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));
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) SegmentIO(org.apache.ignite.internal.processors.cache.persistence.wal.io.SegmentIO) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) FailureContext(org.apache.ignite.failure.FailureContext) IOException(java.io.IOException) FileWriteHandle(org.apache.ignite.internal.processors.cache.persistence.wal.filehandle.FileWriteHandle) File(java.io.File) StorageException(org.apache.ignite.internal.processors.cache.persistence.StorageException) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO)

Example 37 with ClosedByInterruptException

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);
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) SocketChannel(java.nio.channels.SocketChannel) ClosedChannelException(java.nio.channels.ClosedChannelException) NotYetConnectedException(java.nio.channels.NotYetConnectedException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 38 with ClosedByInterruptException

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();
}
Also used : Setting(com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputFormatter(com.google.devtools.build.lib.query2.output.OutputFormatter) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Target(com.google.devtools.build.lib.packages.Target) QueryException(com.google.devtools.build.lib.query2.engine.QueryException) SkyframeRestartQueryException(com.google.devtools.build.lib.query2.engine.SkyframeRestartQueryException) BlazeQueryEnvironment(com.google.devtools.build.lib.query2.BlazeQueryEnvironment) QueryFunction(com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction) SkyframeRestartQueryException(com.google.devtools.build.lib.query2.engine.SkyframeRestartQueryException) Nullable(javax.annotation.Nullable)

Example 39 with ClosedByInterruptException

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");
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) Test(org.testng.annotations.Test)

Example 40 with ClosedByInterruptException

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);
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) Test(org.junit.Test)

Aggregations

ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)79 IOException (java.io.IOException)48 ByteBuffer (java.nio.ByteBuffer)15 ClosedChannelException (java.nio.channels.ClosedChannelException)11 SocketTimeoutException (java.net.SocketTimeoutException)9 InetSocketAddress (java.net.InetSocketAddress)7 MappedByteBuffer (java.nio.MappedByteBuffer)7 SocketChannel (java.nio.channels.SocketChannel)7 File (java.io.File)6 ServerSocketChannel (java.nio.channels.ServerSocketChannel)6 ServerSocket (java.net.ServerSocket)5 FileChannel (java.nio.channels.FileChannel)5 FileLockInterruptionException (java.nio.channels.FileLockInterruptionException)5 InterruptedIOException (java.io.InterruptedIOException)4 Path (java.nio.file.Path)4 Test (org.junit.Test)4 BuildId (com.facebook.buck.model.BuildId)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 SocketException (java.net.SocketException)3