Search in sources :

Example 46 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project yamcs-studio by yamcs.

the class ResourceUtil method pathToInputStreamInJob.

/**
 * Get inputstream from path. Run in a Job. The uiTask is responsible for closing the inputstream
 *
 * @param path
 *            the path to load
 * @param uiTask
 *            the task to be executed in UI thread after path is loaded.
 * @param jobName
 *            name of the job
 * @param errorHandler
 *            the handler to handle IO exception.
 */
public static void pathToInputStreamInJob(String path, AbstractInputStreamRunnable uiTask, String jobName, IJobErrorHandler errorHandler) {
    var display = Display.getCurrent() != null ? Display.getCurrent() : Display.getDefault();
    var job = new Job(jobName) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask("Connecting to " + path, IProgressMonitor.UNKNOWN);
            try {
                InputStream inputStream = null;
                if (!path.contains("://")) {
                    inputStream = workspaceFileToInputStream(Path.fromPortableString(path));
                }
                if (inputStream == null) {
                    inputStream = new ByteArrayInputStream(cache.getUnchecked(path));
                }
                uiTask.setInputStream(inputStream);
                display.asyncExec(uiTask);
            } catch (UncheckedExecutionException e) {
                errorHandler.handleError(e.getCause());
            } catch (Exception e) {
                errorHandler.handleError(e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Job(org.eclipse.core.runtime.jobs.Job) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException)

Example 47 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project oap by oaplatform.

the class TemplateEngine method getTemplate.

@SuppressWarnings("unchecked")
public <TIn, TOut, TOutMutable, TA extends TemplateAccumulator<TOut, TOutMutable, TA>> Template<TIn, TOut, TOutMutable, TA> getTemplate(String name, TypeRef<TIn> type, String template, TA acc, Map<String, String> aliases, ErrorStrategy errorStrategy, Consumer<Ast> postProcess) {
    assert template != null;
    assert acc != null;
    var id = name + "_" + getHash(template) + "_" + aliases.hashCode() + "_" + acc.getClass().hashCode() + (postProcess != null ? "_" + postProcess.getClass().hashCode() : "");
    log.trace("id '{}' acc '{}' template '{}' aliases '{}'", id, acc.getClass(), template, aliases);
    try {
        TemplateFunction tFunc = templates.get(id, () -> {
            var lexer = new TemplateLexer(CharStreams.fromString(template));
            var grammar = new TemplateGrammar(new BufferedTokenStream(lexer), builtInFunction, errorStrategy);
            if (errorStrategy == ErrorStrategy.ERROR) {
                lexer.addErrorListener(ThrowingErrorListener.INSTANCE);
                grammar.addErrorListener(ThrowingErrorListener.INSTANCE);
            }
            var ast = grammar.template(new TemplateType(type.type()), aliases).rootAst;
            log.trace("\n" + ast.print());
            if (postProcess != null)
                postProcess.accept(ast);
            var tf = new JavaTemplate<>(name, type, tmpPath, acc, ast);
            return new TemplateFunction(tf, new Exception().getStackTrace());
        });
        return (Template<TIn, TOut, TOutMutable, TA>) tFunc.template;
    } catch (UncheckedExecutionException | ExecutionException e) {
        if (e.getCause() instanceof TemplateException) {
            throw (TemplateException) e.getCause();
        }
        throw new TemplateException(e.getCause());
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BufferedTokenStream(org.antlr.v4.runtime.BufferedTokenStream) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 48 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project spf4j by zolyfarkas.

the class ExecutionContext method popFirstAvail.

public Object popFirstAvail(final int nr) throws SuspendedException {
    int nrErrors = 0;
    ExecutionException e = null;
    List<VMFuture<Object>> futures = null;
    for (int i = 0; i < nr; i++) {
        Object obj = stack.peekFromTop(i);
        if (obj instanceof VMFuture<?>) {
            final VMFuture<Object> resFut = (VMFuture<Object>) obj;
            Either<Object, ? extends ExecutionException> resultStore = resFut.getResult();
            if (resultStore != null) {
                if (resultStore.isLeft()) {
                    stack.removeFromTop(nr);
                    return resultStore.getLeft();
                } else {
                    nrErrors++;
                    ExecutionException exRes = resultStore.getRight();
                    if (e != null) {
                        Throwables.suppressLimited(exRes, e);
                    }
                    e = exRes;
                }
            } else {
                if (futures == null) {
                    futures = new ArrayList<>(nr);
                }
                futures.add(resFut);
            }
        } else {
            stack.removeFromTop(nr);
            return obj;
        }
    }
    if (nrErrors == nr) {
        if (e == null) {
            throw new IllegalStateException();
        } else {
            throw new UncheckedExecutionException(e);
        }
    }
    if (futures == null || futures.isEmpty()) {
        throw new IllegalStateException();
    }
    suspend(futures);
    throw new IllegalStateException();
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException)

Example 49 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project qpid-broker-j by apache.

the class HousekeepingExecutor method afterExecute.

@Override
protected void afterExecute(Runnable r, Throwable t) {
    super.afterExecute(r, t);
    if (t == null && r instanceof Future<?>) {
        Future future = (Future<?>) r;
        try {
            if (future.isDone()) {
                Object result = future.get();
            }
        } catch (CancellationException ce) {
            LOGGER.debug("Housekeeping task got cancelled");
        // Ignore cancellation of task
        } catch (ExecutionException | UncheckedExecutionException ee) {
            t = ee.getCause();
        } catch (InterruptedException ie) {
            // ignore/reset
            Thread.currentThread().interrupt();
        } catch (Throwable t1) {
            t = t1;
        }
    }
    if (t != null) {
        LOGGER.error("Housekeeping task threw an exception:", t);
        final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
        if (uncaughtExceptionHandler != null) {
            uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), t);
        } else {
            Runtime.getRuntime().halt(1);
        }
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) CancellationException(java.util.concurrent.CancellationException) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException)

Example 50 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project incubator-gobblin by apache.

the class HiveSource method createWorkunitsForPartitionedTable.

protected void createWorkunitsForPartitionedTable(HiveDataset hiveDataset, AutoReturnableObject<IMetaStoreClient> client, boolean disableAvroCheck) throws IOException {
    long tableProcessTime = new DateTime().getMillis();
    this.watermarker.onTableProcessBegin(hiveDataset.getTable(), tableProcessTime);
    Optional<String> partitionFilter = Optional.fromNullable(this.partitionFilterGenerator.getFilter(hiveDataset));
    List<Partition> sourcePartitions = HiveUtils.getPartitions(client.get(), hiveDataset.getTable(), partitionFilter);
    for (Partition sourcePartition : sourcePartitions) {
        if (isOlderThanLookback(sourcePartition)) {
            continue;
        }
        LongWatermark lowWatermark = watermarker.getPreviousHighWatermark(sourcePartition);
        try {
            if (!shouldCreateWorkUnit(new Path(sourcePartition.getLocation()))) {
                log.info(String.format("Not creating workunit for partition %s as partition path %s contains data path tokens to ignore %s", sourcePartition.getCompleteName(), sourcePartition.getLocation(), this.ignoreDataPathIdentifierList));
                continue;
            }
            long updateTime = this.updateProvider.getUpdateTime(sourcePartition);
            if (shouldCreateWorkunit(sourcePartition, lowWatermark)) {
                log.debug(String.format("Processing partition: %s", sourcePartition));
                long partitionProcessTime = new DateTime().getMillis();
                this.watermarker.onPartitionProcessBegin(sourcePartition, partitionProcessTime, updateTime);
                LongWatermark expectedPartitionHighWatermark = this.watermarker.getExpectedHighWatermark(sourcePartition, tableProcessTime, partitionProcessTime);
                HiveWorkUnit hiveWorkUnit = workUnitForPartition(hiveDataset, sourcePartition, disableAvroCheck);
                hiveWorkUnit.setWatermarkInterval(new WatermarkInterval(lowWatermark, expectedPartitionHighWatermark));
                EventWorkunitUtils.setPartitionSlaEventMetadata(hiveWorkUnit, hiveDataset.getTable(), sourcePartition, updateTime, lowWatermark.getValue(), this.beginGetWorkunitsTime);
                workunits.add(hiveWorkUnit);
                log.info(String.format("Creating workunit for partition %s as updateTime %s is greater than low watermark %s", sourcePartition.getCompleteName(), updateTime, lowWatermark.getValue()));
            } else {
                // If watermark tracking at a partition level is necessary, create a dummy workunit for this partition here.
                log.info(String.format("Not creating workunit for partition %s as updateTime %s is lesser than low watermark %s", sourcePartition.getCompleteName(), updateTime, lowWatermark.getValue()));
            }
        } catch (UpdateNotFoundException e) {
            log.error(String.format("Not creating workunit for %s as update time was not found. %s", sourcePartition.getCompleteName(), e.getMessage()));
        } catch (SchemaNotFoundException e) {
            log.error(String.format("Not creating workunit for %s as schema was not found. %s", sourcePartition.getCompleteName(), e.getMessage()));
        } catch (UncheckedExecutionException e) {
            log.error(String.format("Not creating workunit for %s because an unchecked exception occurred. %s", sourcePartition.getCompleteName(), e.getMessage()));
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) UpdateNotFoundException(org.apache.gobblin.data.management.conversion.hive.provider.UpdateNotFoundException) Partition(org.apache.hadoop.hive.ql.metadata.Partition) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) DateTime(org.joda.time.DateTime) WatermarkInterval(org.apache.gobblin.source.extractor.WatermarkInterval) SchemaNotFoundException(org.apache.gobblin.data.management.conversion.hive.avro.SchemaNotFoundException) LongWatermark(org.apache.gobblin.source.extractor.extract.LongWatermark)

Aggregations

UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)101 ExecutionException (java.util.concurrent.ExecutionException)60 IOException (java.io.IOException)31 InvalidCacheLoadException (com.google.common.cache.CacheLoader.InvalidCacheLoadException)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Test (org.junit.Test)9 Map (java.util.Map)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 TimeoutException (java.util.concurrent.TimeoutException)6 Stopwatch (com.google.common.base.Stopwatch)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 HashMap (java.util.HashMap)5 List (java.util.List)5 NoSuchElementException (java.util.NoSuchElementException)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 InputStream (java.io.InputStream)4 Callable (java.util.concurrent.Callable)4 SirixIOException (org.sirix.exception.SirixIOException)4 TypeSignature (com.facebook.presto.common.type.TypeSignature)3