@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); } } }
@SuppressWarnings("unchecked") public static <T> ReferenceWithError<InterruptingImmediateSupplier<T>> ofSafe(final Object o) { if (o instanceof Supplier) { return ReferenceWithError.newInstanceWithoutError(new InterruptingImmediateSupplier<T>((Supplier<T>)o)); } else if (o instanceof Callable) { return ReferenceWithError.newInstanceWithoutError(new InterruptingImmediateSupplier<T>(new Supplier<T>() { @Override public T get() { try { return ((Callable<T>)o).call(); } catch (Exception e) { throw Exceptions.propagate(e); } } })); } else if (o instanceof Runnable) { return ReferenceWithError.newInstanceWithoutError(new InterruptingImmediateSupplier<T>(new Supplier<T>() { @Override public T get() { ((Runnable)o).run(); return null; } })); } else { return ReferenceWithError.newInstanceThrowingError(null, new InterruptingImmediateSupplierNotSupportedForObject(o)); } }
protected ReferenceWithError<Optional<Entity>> addInSingleLocation(@Nullable Location location, Map<?,?> flags) { ReferenceWithError<Collection<Entity>> added = addInEachLocation(Arrays.asList(location), flags); Optional<Entity> result = Iterables.isEmpty(added.getWithoutError()) ? Optional.<Entity>absent() : Optional.of(Iterables.getOnlyElement(added.get())); if (!added.hasError()) { return ReferenceWithError.newInstanceWithoutError( result ); } else { if (added.masksErrorIfPresent()) { return ReferenceWithError.newInstanceMaskingError( result, added.getError() ); } else { return ReferenceWithError.newInstanceThrowingError( result, added.getError() ); } } }
return ReferenceWithError.newInstanceWithoutError(newBundle); } catch (Exception e) { Exceptions.propagateIfFatal(e);
private static <T> ReferenceWithError<Maybe<? extends T>> deepMerge(Maybe<? extends T> val1, Maybe<? extends T> val2) { if (val2.isAbsent() || val2.isNull()) { return ReferenceWithError.newInstanceWithoutError(val1); } else if (val1.isAbsent()) { return ReferenceWithError.newInstanceWithoutError(val2); } else if (val1.isNull()) { return ReferenceWithError.newInstanceWithoutError(val1); // an explicit null means an override; don't merge } else if (val1.get() instanceof Map && val2.get() instanceof Map) { @SuppressWarnings({ "unchecked", "rawtypes" }) Maybe<T> result = (Maybe)Maybe.of(CollectionMerger.builder().build().merge((Map<?,?>)val1.get(), (Map<?,?>)val2.get())); return ReferenceWithError.newInstanceWithoutError(result); } else { // cannot merge; just return val1 return ReferenceWithError.newInstanceThrowingError(val1, new IllegalArgumentException("Cannot merge '"+val1.get()+"' and '"+val2.get()+"'")); } }
@Override public <TContainer,TValue> ReferenceWithError<ConfigValueAtContainer<TContainer,TValue>> resolveWithParent( ConfigValueAtContainer<TContainer,TValue> local, ConfigValueAtContainer<TContainer,TValue> parent, ConfigInheritanceContext context) { // parent can be assumed to be set, but might not have a value if (!parent.isValueExplicitlySet()) return ReferenceWithError.newInstanceWithoutError(new BasicConfigValueAtContainer<TContainer,TValue>(local)); if (!local.isValueExplicitlySet()) return ReferenceWithError.newInstanceWithoutError(new BasicConfigValueAtContainer<TContainer,TValue>(parent)); // both explicitly set, and not overwrite or none if (getMode()==InheritanceMode.DEEP_MERGE) { BasicConfigValueAtContainer<TContainer, TValue> result = new BasicConfigValueAtContainer<TContainer,TValue>(local); result.setValue( deepMerge(local.asMaybe(), parent.asMaybe()) ); return ReferenceWithError.newInstanceWithoutError(result); } throw new IllegalStateException("Unknown config conflict resolution strategy '"+getMode()+"' evaluating "+local+"/"+parent); } private static <T> Maybe<? extends T> deepMerge(Maybe<? extends T> val1, Maybe<? extends T> val2) {
/** Starts hot standby or hot backup, in foreground * <p> * In the case of the former, the caller is responsible for publishing health afterwards, * but if it fails, this method will {@link #demoteTo(ManagementNodeState)} {@link ManagementNodeState#FAILED}. * <p> * @return whether the requested {@link ManagementNodeState} was possible; * (if not, errors should be stored elsewhere), callers may want to rethrow */ protected ReferenceWithError<Boolean> activateHotProxy(ManagementNodeState toState) { try { Preconditions.checkState(nodeStateTransitionComplete==false, "Must be in transitioning state to go into "+toState); setInternalNodeState(toState); managementContext.getRebindManager().startReadOnly(toState); return ReferenceWithError.newInstanceWithoutError(true); } catch (Exception e) { Exceptions.propagateIfFatal(e); LOG.warn("Unable to change "+ownNodeId+" to "+toState+", switching to FAILED: "+e, e); demoteTo(ManagementNodeState.FAILED); return ReferenceWithError.newInstanceThrowingError(false, e); } }
return ReferenceWithError.newInstanceWithoutError(true); } else { if (log.isDebugEnabled()) {
return ReferenceWithError.newInstanceWithoutError(result);
vlr = ReferenceWithError.newInstanceWithoutError(vl);
return ReferenceWithError.newInstanceWithoutError(new BasicConfigValueAtContainer<TContainer,TValue>(parent)); return ReferenceWithError.newInstanceWithoutError(new BasicConfigValueAtContainer<TContainer,TValue>(local)); return ReferenceWithError.newInstanceWithoutError(new BasicConfigValueAtContainer<TContainer,TValue>(parent));
RegisteredTypes.addSuperTypes(resultT, supers); return ReferenceWithError.newInstanceWithoutError(resultT);
init(); makeLocalZipFileFromInputStreamOrUrl(); if (result.code!=null) return ReferenceWithError.newInstanceWithoutError(result); discoverManifestFromCatalogBom(false); if (result.code!=null) return ReferenceWithError.newInstanceWithoutError(result); updateManifestFromAllSourceInformation(); if (result.code!=null) return ReferenceWithError.newInstanceWithoutError(result); assert inferredMetadata.isNameResolved() : "Should have resolved "+inferredMetadata; assert inferredMetadata instanceof BasicManagedBundle : "Only BasicManagedBundles supported"; return ReferenceWithError.newInstanceWithoutError(result); return ReferenceWithError.newInstanceWithoutError(result);
return ReferenceWithError.newInstanceWithoutError(result);