/** As {@link #propagate(String, Throwable)} but unlike earlier deprecated version * this always re-wraps including the given message, until semantics of that method change to match this. * See {@link #propagateAnnotateIfWrapping(String, Throwable)} if the message * should be omitted and the given throwable preserved if it can already be propagated. */ public static RuntimeException propagateAnnotated(String msg, Throwable throwable) { return propagate(msg, throwable, true); }
public static KeyPairGenerator newKeyPairGenerator(String algorithm, int bits) { KeyPairGenerator keyPairGenerator; try { keyPairGenerator = KeyPairGenerator.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw Exceptions.propagate(e); } keyPairGenerator.initialize(bits); return keyPairGenerator; }
private void jitterThreadStart(Task<?> task) { if (jitterThreads) { try { Thread.sleep(ThreadLocalRandom.current().nextInt(jitterThreadsMaxDelay)); } catch (InterruptedException e) { log.warn("Task " + task + " got cancelled before starting because of jitter."); throw Exceptions.propagate(e); } } }
/** returns keystore of default type read from given source */ public static KeyStore newKeyStore(InputStream source, String passphrase) { try { KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType()); store.load(source, passphrase!=null ? passphrase.toCharArray() : new char[0]); return store; } catch (Exception e) { throw Exceptions.propagate(e); } }
@Override public T getUnchecked(Duration duration) { try { return get(duration); } catch (Exception e) { throw Exceptions.propagate(e); } }
@SuppressWarnings("unchecked") public <T> Class<? extends T> loadClass(String classname, Class<T> superType) { try { return (Class<? extends T>) loadClass(classname); } catch (ClassNotFoundException e) { throw Exceptions.propagate(e); } }
public synchronized DataUriSchemeParser parse() { try { return parseChecked(); } catch (Exception e) { throw Exceptions.propagate(e); } }
public static BrooklynDynamicType<?,?> getDefinedBrooklynType(Class<? extends BrooklynObject> brooklynClass) { try { return cache.get(brooklynClass, new DefinedBrooklynTypeLoader(brooklynClass)); } catch (ExecutionException e) { throw Exceptions.propagate(e); } }
@Override public T call() { try { return get(key); } catch (RuntimeInterruptedException e) { throw Exceptions.propagate(e); // expected; return gracefully } } };
/** Processes template contents according to {@link EntityAndMapTemplateModel}. */ public static String processTemplateFile(String templateFileName, EntityDriver driver, Map<String, ? extends Object> extraSubstitutions) { String templateContents; try { templateContents = Files.toString(new File(templateFileName), Charsets.UTF_8); } catch (IOException e) { log.warn("Error loading file " + templateFileName, e); throw Exceptions.propagate(e); } return processTemplateContents(templateContents, driver, extraSubstitutions); }
@Beta public static void copyTo(InputStream in, File dest) { FileOutputStream out = null; try { out = new FileOutputStream(dest); Streams.copy(in, out); } catch (FileNotFoundException e) { throw Exceptions.propagate(e); } finally { Streams.closeQuietly(out); } }
public String getUrl() { try { if (server==null) { // guess the URL, in those cases where the server is not started yet return new URL("http", getLocalAddress().getHostAddress(), basePort, "").toExternalForm(); } return new URL("http", server.getInetAddress().getHostAddress(), server.getLocalPort(), "").toExternalForm(); } catch (MalformedURLException e) { throw Exceptions.propagate(e); } }
public void run() { try { latch.await(); } catch (InterruptedException e) { throw Exceptions.propagate(e); } }});
@Override public Maybe<Iterable<URL>> tryLoadFrom(Bundle bundle, String name) { try { return emptyToMaybeNull(SystemFrameworkLoader.get().getResourcesFromBundle(name, bundle)); } catch (IOException e) { throw Exceptions.propagate(e); } }
@Override protected Object visitSpec() { try { AbstractBrooklynObjectSpec<?, ?> result = createSpec(type, context); result.stackCatalogItemId(type.getId()); return result; } catch (Exception e) { throw Exceptions.propagate(e); } } @Override protected Object visitBean() {
@Override public void run() { try { Thread.sleep(SHORT_WAIT_MS); GeneralisedDynamicMBean mbean = jmxService.registerMBean(objectName); } catch (InterruptedException e) { return; // graceful return } catch (Exception e) { throw Exceptions.propagate(e); } }}); try {
private BrooklynNodeSshDriver getDriver(BrooklynNode brooklynNode) { try { EntityProxyImpl entityProxy = (EntityProxyImpl)Proxy.getInvocationHandler(brooklynNode); Method getDriver = BrooklynNodeImpl.class.getMethod("getDriver"); return (BrooklynNodeSshDriver)entityProxy.invoke(brooklynNode, getDriver, new Object[]{}); } catch (Throwable e) { throw Exceptions.propagate(e); } }
@Override public void run() { try { Thread.sleep(2000); jmxService = new JmxService("localhost", 40123); jmxService.registerMBean(ImmutableMap.of(attributeName, "myval"), objectName); } catch (Exception e) { LOG.error("Error in testEntityWithDelayedJmxStartupWillKeepRetrying", e); throw Exceptions.propagate(e); } }});
private static <T> void assertAttributeEquals(Entity x, AttributeSensor<T> sensor, T value) { try { EntityAsserts.assertAttributeEquals(x, sensor, value); } catch (Throwable e) { log.warn("Expected "+x+" to have "+sensor+" = "+value+"; instead:"); Entities.dumpInfo(x); throw Exceptions.propagate(e); } }
@Override public void copyCustomizeResources() { getLocation().acquireMutex("customizing " + elvis(entity, this), "installation lock at host for files and templates"); try { super.copyCustomizeResources(); } catch (Exception e) { log.warn("Error copying customize resources", e); throw Exceptions.propagate(e); } finally { getLocation().releaseMutex("customizing " + elvis(entity, this)); } }