/** Same as {@link #destroy(Location)} but catching all errors. */ public static void destroyCatching(Location loc) { try { destroy(loc); } catch (Exception e) { log.warn("ERROR destroying "+loc+" (ignoring): "+e, e); Exceptions.propagateIfFatal(e); } }
@Override public void onCreateFailed(BrooklynObjectType type, String id, String instanceType, Exception e) { Exceptions.propagateIfFatal(e); String errmsg = "problem creating "+type+" "+id+" of type "+instanceType; creationFailedIds.add(id); exceptions.add(new IllegalStateException(errmsg, e)); onErrorImpl(errmsg, e); }
/** Same as {@link #destroy(Entity)} but catching all errors. */ public static void destroyCatching(Entity entity) { try { destroy(entity); } catch (Exception e) { log.warn("ERROR destroying "+entity+" (ignoring): "+e, e); Exceptions.propagateIfFatal(e); } }
private void emitAssociationDeletedEvent(AssociationMetadata metadata) { for (Map.Entry<AssociationListener, Predicate<? super AssociationMetadata>> entry : associationListeners.entrySet()) { if (entry.getValue().apply(metadata)) { try { entry.getKey().onAssociationDeleted(metadata); } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("Exception thrown when emitting association creation event " + metadata, e); } } } }
/** Implements the return behavior for {@link #expectedFailureOfType(Throwable, Class...)} and others, * to log interesting earlier errors but to suppress those which are internal or redundant. */ private static void rethrowPreferredException(Throwable earlierPreferredIfFatalElseLogged, Throwable laterPreferredOtherwise) throws AssertionError { if (!(earlierPreferredIfFatalElseLogged instanceof AssertionError)) { Exceptions.propagateIfFatal(earlierPreferredIfFatalElseLogged); } log.warn("Detail of unexpected error: "+earlierPreferredIfFatalElseLogged, earlierPreferredIfFatalElseLogged); throw Exceptions.propagate(laterPreferredOtherwise); }
public void handleException(Throwable throwable) throws Exception { Exceptions.propagateIfFatal(throwable); if (throwable instanceof Exception) { // allow checked exceptions to be passed through throw (Exception)throwable; } throw Exceptions.propagate(throwable); }
@Override public void run() { try { rescanEntities(); } catch (Exception e) { log.warn("Error rescanning entities on management of "+DynamicGroupImpl.this+"; may be a group set against an unknown entity: "+e); log.debug("Trace for rescan entities error", e); Exceptions.propagateIfFatal(e); } } }).build();
private void emitAssociationCreatedEvent(String publicIpId, HostAndPort publicEndpoint, Location location, int privatePort) { AssociationMetadata metadata = new AssociationMetadata(publicIpId, publicEndpoint, location, privatePort); for (Map.Entry<AssociationListener, Predicate<? super AssociationMetadata>> entry : associationListeners.entrySet()) { if (entry.getValue().apply(metadata)) { try { entry.getKey().onAssociationCreated(metadata); } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("Exception thrown when emitting association creation event " + metadata, e); } } } }
protected void handleSubsystemStartupError(boolean ignoreSuchErrors, String system, Exception e) { Exceptions.propagateIfFatal(e); if (ignoreSuchErrors) { LOG.error("Subsystem for "+system+" had startup error (continuing with startup): "+e, e); if (managementContext!=null) ((ManagementContextInternal)managementContext).errors().add(e); } else { throw Exceptions.propagate(e); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) protected <D extends EntityDriver> ReferenceWithError<Class<? extends D>> loadClass(String className, ClassLoader classLoader) { try { return (ReferenceWithError) ReferenceWithError.newInstanceWithoutError((Class<? extends EntityDriver>)classLoader.loadClass(className)); } catch (Exception e) { Exceptions.propagateIfFatal(e); return ReferenceWithError.newInstanceThrowingError(null, e); } } }
private <T> T constructWithSpecial(Class<? extends SpecialBrooklynObjectConstructor> special, Class<? extends T> clazz, AbstractBrooklynObjectSpec<?, ?> spec) { try { return special.newInstance().create(managementContext, clazz, spec); } catch (Exception e) { Exceptions.propagateIfFatal(e); throw Exceptions.propagateAnnotated("Unable to create "+clazz+" "+spec+" using special "+special, e); } }
@Test public void testPropagateIfFatalPropagatesInterruptedException() throws Exception { InterruptedException tothrow = new InterruptedException("simulated"); try { Exceptions.propagateIfFatal(tothrow); fail(); } catch (RuntimeException e) { assertTrue(Thread.interrupted()); // note this clears the interrupted flag as well assertEquals(e.getCause(), tothrow); } }
private void populateInitialFromUri(BasicBrooklynCatalog catalog, String catalogUrl) { log.debug("Loading initial catalog from {}", catalogUrl); try { String contents = new ResourceUtils(this).getResourceAsString(catalogUrl); catalog.reset(MutableList.<CatalogItem<?,?>>of()); Object result = catalog.addItems(contents); log.debug("Loaded initial catalog from {}: {}", catalogUrl, result); } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("Error importing catalog from " + catalogUrl + ": " + e, e); } }
@Override public <D extends EntityDriver> ReferenceWithError<Class<? extends D>> resolve(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) { try { String newName = inferDriverClassName(entity, driverInterface, location); if (newName==null) return null; return loadDriverClass(newName, entity, driverInterface); } catch (Exception e) { Exceptions.propagateIfFatal(e); return ReferenceWithError.newInstanceThrowingError(null, e); } }
private void assertLoadSucceeds(String bundledClassName, Class<?> expectedClass, ClassLoaderUtils... clua) throws ClassNotFoundException { for (ClassLoaderUtils clu : clua) { try { assertLoadSucceeds(clu, bundledClassName, expectedClass); } catch (Exception e) { Exceptions.propagateIfFatal(e); throw new IllegalStateException("Load failed for " + clu, e); } } }
@Test public void testPropagateIfFatalPropagatesRuntimeInterruptedException() throws Exception { RuntimeInterruptedException tothrow = new RuntimeInterruptedException(new InterruptedException("simulated")); try { Exceptions.propagateIfFatal(tothrow); fail(); } catch (RuntimeInterruptedException e) { assertTrue(Thread.interrupted()); // note this clears the interrupted flag as well assertEquals(e, tothrow); } }
@AfterMethod(alwaysRun = true) @Override public void tearDown() throws Exception { try { if (server != null) server.stop(); } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("failed to stop server: "+e); } super.tearDown(); }
@Override protected double scoreForNullFormat(Object planData, RegisteredType type, RegisteredTypeLoadingContext context) { if (!(planData instanceof String)) return 0; try { // if it's XML, accept it parseXml((String)planData); return 0.3; } catch (Exception e) { Exceptions.propagateIfFatal(e); return 0; } }
protected Class<?> loadClass(String jType) throws ClassNotFoundException { try { return reflections.loadClass(jType); } catch (Exception e) { Exceptions.propagateIfFatal(e); } return new ClassLoaderUtils(reflections.getClassLoader(), managementContext).loadClass(jType); }
@Override public TemplateModel get(String key) throws TemplateModelException { try { Object result = mgmt.getConfig().getConfig(ConfigKeys.builder(Object.class).name(key).build()); if (result!=null) return wrapAsTemplateModel( result ); } catch (Exception e) { Exceptions.propagateIfFatal(e); throw new IllegalStateException("Error accessing config '"+key+"': "+e, e); } return null; }