@Override public void run() { try { //some code that throws checked exception } catch(Exception e) { throw new UncheckedException(e); } }
@Override public T getOrNull() { try { return value.call(); } catch (Exception e) { throw new UncheckedException(e); } } }
public static boolean hasDefaultToString(Object object) { try { return object.getClass().getMethod("toString").getDeclaringClass() == Object.class; } catch (java.lang.NoSuchMethodException e) { throw new UncheckedException(e); } }
@Override public void visitClassPath(URL[] classPath) { for (URL url : classPath) { try { implementationClassPath.add(new File(toURI(url))); } catch (URISyntaxException e) { throw new UncheckedException(e); } } } }.visit(classLoader);
@Override public void visitClassPath(URL[] classPath) { for (URL url : classPath) { try { implementationClassPath.add(new File(toURI(url))); } catch (URISyntaxException e) { throw new UncheckedException(e); } } } }.visit(classLoader);
public static boolean hasDefaultToString(Object object) { try { return object.getClass().getMethod("toString").getDeclaringClass() == Object.class; } catch (java.lang.NoSuchMethodException e) { throw new UncheckedException(e); } }
private static URI toURI(URL url) throws URISyntaxException { try { return url.toURI(); } catch (URISyntaxException e) { try { return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile().replace(" ", "%20")).toURI(); } catch (MalformedURLException e1) { throw new UncheckedException(e1); } } } }
private static URI toURI(URL url) throws URISyntaxException { try { return url.toURI(); } catch (URISyntaxException e) { try { return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile().replace(" ", "%20")).toURI(); } catch (MalformedURLException e1) { throw new UncheckedException(e1); } } } }
public void dispatch(final T message) { lock.lock(); try { while (state != State.Stopped && queue.size() >= maxQueueSize) { try { condition.await(); } catch (InterruptedException e) { throw new UncheckedException(e); } } if (state == State.Stopped) { throw new IllegalStateException("Cannot dispatch message, as this message dispatch has been stopped. Message: " + message); } queue.add(message); condition.signalAll(); } finally { lock.unlock(); } }
/** * Note: always throws the failure in some form. The return value is to keep the compiler happy. */ public static RuntimeException throwAsUncheckedException(Throwable t, boolean preserveMessage) { if (t instanceof RuntimeException) { throw (RuntimeException) t; } if (t instanceof Error) { throw (Error) t; } if (t instanceof IOException) { if (preserveMessage) { throw new UncheckedIOException(t.getMessage(), t); } else { throw new UncheckedIOException(t); } } if (preserveMessage) { throw new UncheckedException(t.getMessage(), t); } else { throw new UncheckedException(t); } }
/** * Note: always throws the failure in some form. The return value is to keep the compiler happy. */ public static RuntimeException throwAsUncheckedException(Throwable t, boolean preserveMessage) { if (t instanceof RuntimeException) { throw (RuntimeException) t; } if (t instanceof Error) { throw (Error) t; } if (t instanceof IOException) { if (preserveMessage) { throw new UncheckedIOException(t.getMessage(), t); } else { throw new UncheckedIOException(t); } } if (preserveMessage) { throw new UncheckedException(t.getMessage(), t); } else { throw new UncheckedException(t); } }
public void stop(int timeoutValue, TimeUnit timeoutUnits) throws IllegalStateException { requestStop(); if (executing.get() != null) { throw new IllegalStateException("Cannot stop this executor from an executor thread."); } try { if (!executor.awaitTermination(timeoutValue, timeoutUnits)) { executor.shutdownNow(); throw new IllegalStateException("Timeout waiting for concurrent jobs to complete."); } } catch (InterruptedException e) { throw new UncheckedException(e); } executorPolicy.onStop(); }
public void stop(int timeoutValue, TimeUnit timeoutUnits) throws IllegalStateException { requestStop(); if (executing.get() != null) { throw new IllegalStateException("Cannot stop this executor from an executor thread."); } try { if (!executor.awaitTermination(timeoutValue, timeoutUnits)) { executor.shutdownNow(); throw new IllegalStateException("Timeout waiting for concurrent jobs to complete."); } } catch (InterruptedException e) { throw new UncheckedException(e); } executorPolicy.onStop(); }
/** * Stops accepting new messages, and blocks until all queued messages have been dispatched. */ public void stop() { lock.lock(); try { setState(State.Stopped); while (dispatchers > 0) { condition.await(); } if (!queue.isEmpty()) { throw new IllegalStateException( "Cannot wait for messages to be dispatched, as there are no dispatch threads running."); } } catch (InterruptedException e) { throw new UncheckedException(e); } finally { lock.unlock(); } } }
private void dispatchMessages(Dispatch<? super T> dispatch) { while (true) { T message = null; lock.lock(); try { while (state != State.Stopped && queue.isEmpty()) { try { condition.await(); } catch (InterruptedException e) { throw new UncheckedException(e); } } if (!queue.isEmpty()) { message = queue.remove(); condition.signalAll(); } } finally { lock.unlock(); } if (message == null) { // Have been stopped and nothing to deliver return; } dispatch.dispatch(message); } }
public static ClassPath getClasspath(ClassLoader classLoader) { final List<File> implementationClassPath = new ArrayList<File>(); new ClassLoaderVisitor() { @Override public void visitClassPath(URL[] classPath) { for (URL url : classPath) { try { implementationClassPath.add(new File(toURI(url))); } catch (URISyntaxException e) { throw new UncheckedException(e); } } } }.visit(classLoader); return DefaultClassPath.of(implementationClassPath); }
public static ClassPath getClasspath(ClassLoader classLoader) { final List<File> implementationClassPath = new ArrayList<File>(); new ClassLoaderVisitor() { @Override public void visitClassPath(URL[] classPath) { for (URL url : classPath) { try { implementationClassPath.add(new File(toURI(url))); } catch (URISyntaxException e) { throw new UncheckedException(e); } } } }.visit(classLoader); return DefaultClassPath.of(implementationClassPath); }
@Override public <T> T withoutLocks(Iterable<? extends ResourceLock> locks, Callable<T> action) { if (!allLockedByCurrentThread(locks)) { throw new IllegalStateException("Not all of the locks specified are currently held by the current thread. This could lead to orphaned locks."); } coordinationService.withStateLock(unlock(locks)); try { return action.call(); } catch (Exception e) { throw new UncheckedException(e); } finally { if (!coordinationService.withStateLock(tryLock(locks))) { releaseWorkerLeaseAndWaitFor(locks); } } }