Example usage for java.util.concurrent ExecutorCompletionService poll

List of usage examples for java.util.concurrent ExecutorCompletionService poll

Introduction

In this page you can find the example usage for java.util.concurrent ExecutorCompletionService poll.

Prototype

public Future<V> poll() 

Source Link

Usage

From source file:com.streamsets.pipeline.stage.origin.jdbc.AbstractTableJdbcSource.java

/**
 * Checks whether any of the {@link TableJdbcRunnable} workers completed
 * and whether there is any error that needs to be handled from them.
 * @param completionService {@link ExecutorCompletionService} used to detect completion
 * @throws StageException if {@link StageException} is thrown by the workers (if the error handling is stop pipeline)
 *///ww  w.  ja  va  2 s.com
private void checkWorkerStatus(ExecutorCompletionService<Future> completionService) throws StageException {
    Future future = completionService.poll();
    if (future != null) {
        try {
            future.get();
        } catch (InterruptedException e) {
            LOG.error("Thread interrupted", e);
        } catch (ExecutionException e) {
            Throwable cause = Throwables.getRootCause(e);
            if (cause != null && cause instanceof StageException) {
                throw (StageException) cause;
            } else {
                LOG.error("Internal Error", e);
                throw new StageException(JdbcErrors.JDBC_75, e.toString(), e);
            }
        }
    }
}