List of usage examples for com.google.common.base Throwables propagateIfPossible
public static <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible( @Nullable Throwable throwable, Class<X1> declaredType1, Class<X2> declaredType2) throws X1, X2
From source file:com.google.devtools.build.lib.worker.SimpleWorkerPool.java
@Override public Worker borrowObject(WorkerKey key) throws IOException, InterruptedException { try {/*from ww w .j a v a 2 s.com*/ return super.borrowObject(key); } catch (Throwable t) { Throwables.propagateIfPossible(t, IOException.class, InterruptedException.class); throw new RuntimeException("unexpected", t); } }
From source file:org.sonatype.nexus.maven.m2settings.MojoSupport.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { checkState(getLog() != null, "Mojo.log not installed"); try {/*w ww . j a va 2 s. c om*/ doExecute(); } catch (Exception e) { Throwables.propagateIfPossible(e, MojoExecutionException.class, MojoFailureException.class); throw Throwables.propagate(e); } finally { doCleanup(); } }
From source file:org.apache.gobblin.runtime.fork.SynchronousFork.java
@Override protected void processRecords() throws IOException, DataConversionException { try {/*w w w .ja v a 2 s .c o m*/ this.autoResetEvent.waitOne(); if (this.throwable != null) { Throwables.propagateIfPossible(this.throwable, IOException.class, DataConversionException.class); throw new RuntimeException(throwable); } } catch (InterruptedException ie) { Throwables.propagate(ie); } }
From source file:com.google.devtools.build.lib.worker.SimpleWorkerPool.java
@Override public void invalidateObject(WorkerKey key, Worker obj) throws IOException, InterruptedException { try {//from w ww . j ava2 s .c om super.invalidateObject(key, obj); } catch (Throwable t) { Throwables.propagateIfPossible(t, IOException.class, InterruptedException.class); throw new RuntimeException("unexpected", t); } }
From source file:org.grouplens.lenskit.util.parallel.ParallelTaskGraphExecutor.java
@Override public <T extends Callable<?>, E> void execute(DAGNode<T, E> graph) throws ExecutionException, InterruptedException { logger.info("{}: executing {} tasks on {} threads", name, graph.getReachableNodes().size(), threadCount); TaskGraphManager<T, E> manager = new TaskGraphManager<T, E>(name, graph); List<Thread> threads = Lists.newArrayListWithCapacity(threadCount); for (int i = 1; i <= threadCount; i++) { Thread thread = new TaskGraphThread<T, E>(manager, String.format("%s-%d", name, i)); threads.add(thread);/* ww w.ja va 2s .c o m*/ manager.addThread(thread); thread.start(); } try { manager.waitForFinished(); } catch (Exception ex) { for (Thread th : threads) { th.interrupt(); } Throwables.propagateIfPossible(ex, ExecutionException.class, InterruptedException.class); throw new RuntimeException(ex); } }
From source file:com.streamsets.datacollector.util.LambdaUtil.java
/** * Runs a Supplier within the context of a specified ClassLoader and in priviledged mode. * * @param classLoader the ClassLoader to run the Supplier. * @param e1 Exception class that should be propagated as-is * @param e2 Exception class that should be propagated as-is * @param supplier the Supplier to run within the context of a specified ClassLoader. */// w w w. ja va 2 s .c om public static <T, E1 extends Exception, E2 extends Exception> T privilegedWithClassLoader( ClassLoader classLoader, Class<E1> e1, Class<E2> e2, ExceptionSupplier<T> supplier) throws E1, E2 { try { return AccessController.doPrivileged( (PrivilegedExceptionAction<T>) () -> withClassLoaderInternal(classLoader, supplier)); } catch (PrivilegedActionException e) { Throwables.propagateIfPossible(e.getCause(), e1, e2); Throwables.propagate(e); } return null; }
From source file:com.android.tools.idea.welcome.install.InstallOperation.java
/** * Runs the operation under progress indicator that only gives access to progress portion. *///from w w w.j av a 2s. c om @NotNull public final Return execute(@NotNull final Argument argument) throws WizardException, InstallationCancelledException { myContext.checkCanceled(); if (myProgressRatio == 0) { return perform(new EmptyProgressIndicator(), argument); } else { try { return myContext.run(new ThrowableComputable<Return, Exception>() { @Override @Nullable public Return compute() throws Exception { ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator == null) { indicator = new EmptyProgressIndicator(); } return perform(indicator, argument); } }, myProgressRatio); } catch (ProcessCanceledException e) { throw new InstallationCancelledException(); } catch (Exception e) { Throwables.propagateIfPossible(e, WizardException.class, InstallationCancelledException.class); throw Throwables.propagate(e); } } }
From source file:com.google.autoesc.MemoizingHTMLEscapingWriter.java
@Override public void writeSafe(String safeContent) throws IOException, TemplateException { MemoTuple key = new MemoTuple(getContext(), safeContent, getRtable()); if (USE_GLOBAL_CACHE) { try {//www . j a v a2 s .c o m MemoTuple value = MEMO_TABLE.get(key); getWriter().write(value.safeContent); setContextAndRtable(value.context, value.rtable); } catch (ExecutionException ex) { Throwables.propagateIfPossible(ex, IOException.class, TemplateException.class); Throwables.propagate(ex); } } else { MemoTuple value = memoTable.get(key); if (value == null) { StringWriter normalizedSafeContent = new StringWriter(safeContent.length() + 16); @SuppressWarnings("resource") // Not allocated here Writer oout = getWriter(); replaceWriter(normalizedSafeContent); super.writeSafe(safeContent); replaceWriter(oout); value = new MemoTuple(getContext(), normalizedSafeContent.toString(), getRtable()); memoTable.put(key, value); } getWriter().write(value.safeContent); setContextAndRtable(value.context, value.rtable); } }
From source file:org.sonatype.nexus.repository.httpbridge.internal.ViewServlet.java
@Override protected void service(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws ServletException, IOException { String uri = httpRequest.getRequestURI(); if (httpRequest.getQueryString() != null) { uri = uri + "?" + httpRequest.getQueryString(); }/*from w w w .j av a 2 s. c o m*/ if (log.isDebugEnabled()) { log.debug("Servicing: {} {} ({})", httpRequest.getMethod(), uri, httpRequest.getRequestURL()); } MDC.put(getClass().getName(), uri); try { doService(httpRequest, httpResponse); log.debug("Service completed"); } catch (Exception e) { if (!(e instanceof AuthorizationException)) { log.warn("Service failure", e); } Throwables.propagateIfPossible(e, ServletException.class, IOException.class); throw new ServletException(e); } finally { MDC.remove(getClass().getName()); } }
From source file:com.cubeia.backend.firebase.AccountLookupUtil.java
private long lookupUniqueAccountId(AccountQuery query) { try {//from w w w. j av a 2 s . c o m return accountIdCache.get(query); } catch (Exception e) { Throwables.propagateIfPossible(e.getCause(), NoSuchAccountException.class, TooManyAccountsFoundException.class); throw new IllegalStateException(e); } }