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