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();
}
}
}
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);
}
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;
}
}
Aggregations