Search in sources :

Example 1 with TransmissionDisabledException

use of org.apache.nifi.remote.exception.TransmissionDisabledException in project nifi by apache.

the class StandardRootGroupPort method onTrigger.

@Override
public void onTrigger(final ProcessContext context, final ProcessSessionFactory sessionFactory) {
    final FlowFileRequest flowFileRequest;
    try {
        flowFileRequest = requestQueue.poll(100, TimeUnit.MILLISECONDS);
    } catch (final InterruptedException ie) {
        return;
    }
    if (flowFileRequest == null) {
        return;
    }
    flowFileRequest.setServiceBegin();
    requestLock.lock();
    try {
        if (shutdown) {
            final CommunicationsSession commsSession = flowFileRequest.getPeer().getCommunicationsSession();
            if (commsSession != null) {
                commsSession.interrupt();
            }
        }
        activeRequests.add(flowFileRequest);
    } finally {
        requestLock.unlock();
    }
    final ProcessSession session = sessionFactory.createSession();
    try {
        onTrigger(context, session, flowFileRequest);
    // we leave the session open, because we send it back to the caller of #receiveFlowFile or #transmitFlowFile,
    // so that they can perform appropriate actions to commit or rollback the transaction.
    } catch (final TransmissionDisabledException e) {
        session.rollback();
    } catch (final Exception e) {
        logger.error("{} Failed to process data due to {}", new Object[] { this, e });
        if (logger.isDebugEnabled()) {
            logger.error("", e);
        }
        session.rollback();
    } finally {
        requestLock.lock();
        try {
            activeRequests.remove(flowFileRequest);
        } finally {
            requestLock.unlock();
        }
    }
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) TransmissionDisabledException(org.apache.nifi.remote.exception.TransmissionDisabledException) CommunicationsSession(org.apache.nifi.remote.protocol.CommunicationsSession) BadRequestException(org.apache.nifi.remote.exception.BadRequestException) ProtocolException(org.apache.nifi.remote.exception.ProtocolException) TransmissionDisabledException(org.apache.nifi.remote.exception.TransmissionDisabledException) NotAuthorizedException(org.apache.nifi.remote.exception.NotAuthorizedException) ProcessException(org.apache.nifi.processor.exception.ProcessException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) RequestExpiredException(org.apache.nifi.remote.exception.RequestExpiredException)

Example 2 with TransmissionDisabledException

use of org.apache.nifi.remote.exception.TransmissionDisabledException in project nifi by apache.

the class SSLSocketChannel method writeFully.

private void writeFully(final ByteBuffer src) throws IOException {
    long lastByteWrittenTime = System.currentTimeMillis();
    int bytesWritten = 0;
    while (src.hasRemaining()) {
        if (interrupted) {
            throw new TransmissionDisabledException();
        }
        final int written = channel.write(src);
        bytesWritten += written;
        final long now = System.currentTimeMillis();
        long sleepNanos = 1L;
        if (written > 0) {
            lastByteWrittenTime = now;
        } else {
            if (now > lastByteWrittenTime + timeoutMillis) {
                throw new SocketTimeoutException("Timed out writing to socket connected to " + hostname + ":" + port);
            }
            try {
                TimeUnit.NANOSECONDS.sleep(sleepNanos);
            } catch (final InterruptedException e) {
                close();
                // set the interrupt status
                Thread.currentThread().interrupt();
                throw new ClosedByInterruptException();
            }
            sleepNanos = Math.min(sleepNanos * 2, BUFFER_FULL_EMPTY_WAIT_NANOS);
        }
    }
    logger.trace("{} Wrote {} bytes", this, bytesWritten);
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) SocketTimeoutException(java.net.SocketTimeoutException) TransmissionDisabledException(org.apache.nifi.remote.exception.TransmissionDisabledException)

Example 3 with TransmissionDisabledException

use of org.apache.nifi.remote.exception.TransmissionDisabledException in project nifi by apache.

the class SSLSocketChannel method readData.

private int readData(final ByteBuffer dest) throws IOException {
    final long startTime = System.currentTimeMillis();
    while (true) {
        if (interrupted) {
            throw new TransmissionDisabledException();
        }
        if (dest.remaining() == 0) {
            return 0;
        }
        final int readCount = channel.read(dest);
        long sleepNanos = 1L;
        if (readCount == 0) {
            if (System.currentTimeMillis() > startTime + timeoutMillis) {
                throw new SocketTimeoutException("Timed out reading from socket connected to " + hostname + ":" + port);
            }
            try {
                TimeUnit.NANOSECONDS.sleep(sleepNanos);
            } catch (InterruptedException e) {
                close();
                // set the interrupt status
                Thread.currentThread().interrupt();
                throw new ClosedByInterruptException();
            }
            sleepNanos = Math.min(sleepNanos * 2, BUFFER_FULL_EMPTY_WAIT_NANOS);
            continue;
        }
        logger.trace("{} Read {} bytes", this, readCount);
        return readCount;
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) SocketTimeoutException(java.net.SocketTimeoutException) TransmissionDisabledException(org.apache.nifi.remote.exception.TransmissionDisabledException)

Aggregations

SocketTimeoutException (java.net.SocketTimeoutException)3 TransmissionDisabledException (org.apache.nifi.remote.exception.TransmissionDisabledException)3 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)2 IOException (java.io.IOException)1 ProcessSession (org.apache.nifi.processor.ProcessSession)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1 BadRequestException (org.apache.nifi.remote.exception.BadRequestException)1 NotAuthorizedException (org.apache.nifi.remote.exception.NotAuthorizedException)1 ProtocolException (org.apache.nifi.remote.exception.ProtocolException)1 RequestExpiredException (org.apache.nifi.remote.exception.RequestExpiredException)1 CommunicationsSession (org.apache.nifi.remote.protocol.CommunicationsSession)1