@Override public FluentFuture<? extends T> getSource(final SourceIdentifier sourceIdentifier) { final T present = cache.getIfPresent(sourceIdentifier); return present != null ? FluentFutures.immediateFluentFuture(present) : FluentFutures.immediateFailedFluentFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier)); }
/** * Return a {@link FluentFuture} which is immediately completed, reporting specified {@code result}. * * @param result boolean result * @return An immediately-completed FluentFuture reporting specified {@code result} * @throws NullPointerException if {@code result} is null */ public static FluentFuture<Boolean> immediateBooleanFluentFuture(final Boolean result) { return immediateBooleanFluentFuture(result.booleanValue()); }
@Override public FluentFuture<Boolean> apply(final SchemaSourceRepresentation schemaSource) { return FluentFutures.immediateTrueFluentFuture(); } };
private void registerFallback(final Class<RpcService> interfaceClass) { final Collection<SchemaPath> paths = RpcUtil.decomposeRpcService(interfaceClass, schemaService.getGlobalContext(), RpcRoutingStrategy::isContextBasedRouted); if (paths.isEmpty()) { LOG.warn("{}: interface {} has no actions defined", ACTION_PROVIDER, interfaceClass); return; } final Set<DOMRpcIdentifier> rpcs = ImmutableSet.copyOf(Collections2.transform(paths, DOMRpcIdentifier::create)); reg = domRpcProvider.registerRpcImplementation( (rpc, input) -> FluentFutures.immediateFailedFluentFuture(new DOMRpcImplementationNotAvailableException( "Action %s has no instance matching %s", rpc, input)), rpcs); LOG.debug("Registered provider for {}", interfaceName); }
if (existing != null) { LOG.debug("Returning cached context {}", existing); return immediateFluentFuture(existing);
sources.get(id); if (srcs == null) { return immediateFailedFluentFuture(new MissingSchemaSourceException( "No providers registered for source" + id, id)); return immediateFailedFluentFuture(new MissingSchemaSourceException( "No providers for source " + id + " representation " + representation + " available", id));
if (existing != null) { LOG.debug("Returning cached context {}", existing); return immediateFluentFuture(existing);
@Override public FluentFuture<? extends T> getSource(final SourceIdentifier sourceIdentifier) { final T present = cache.getIfPresent(sourceIdentifier); return present != null ? FluentFutures.immediateFluentFuture(present) : FluentFutures.immediateFailedFluentFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier)); }
@CheckReturnValue @SuppressWarnings("checkstyle:IllegalCatch") protected <D extends Datastore, X extends WriteTransaction, W, R, E extends Exception> FluentFuture<R> applyWithNewTransactionAndSubmit( final Class<D> datastoreType, final Supplier<X> txSupplier, final BiFunction<Class<D>, X, W> txWrapper, final InterruptibleCheckedFunction<W, R, E> txFunction, final BiFunction<X, W, FluentFuture<?>> txSubmitter) { X realTx = txSupplier.get(); W wrappedTx = txWrapper.apply(datastoreType, realTx); R result; try { // We must store the result before submitting the transaction; if we inline the next line in the // transform lambda, that's not guaranteed result = txFunction.apply(wrappedTx); } catch (Exception e) { // catch Exception for both the <E extends Exception> thrown by accept() as well as any RuntimeException if (!realTx.cancel()) { LOG.error("Transaction.cancel() returned false - this should never happen (here)"); } return FluentFutures.immediateFailedFluentFuture(e); } return txSubmitter.apply(realTx, wrappedTx).transform(v -> result, MoreExecutors.directExecutor()); }
return immediateFluentFuture(schemaContext);
@Override public FluentFuture<Boolean> apply(final SchemaSourceRepresentation schemaSource) { return FluentFutures.immediateTrueFluentFuture(); } };
/** * Return a {@link FluentFuture} which is immediately completed, reporting specified {@code result}. * * @param result boolean result * @return An immediately-completed FluentFuture reporting specified {@code result} * @throws NullPointerException if {@code result} is null */ public static FluentFuture<Boolean> immediateBooleanFluentFuture(final Boolean result) { return immediateBooleanFluentFuture(result.booleanValue()); }
@Override public synchronized FluentFuture<YangTextSchemaSource> getSource( final SourceIdentifier sourceIdentifier) { final Collection<YangTextSchemaSource> ret = texts.get(sourceIdentifier); LOG.debug("Lookup {} result {}", sourceIdentifier, ret); if (ret.isEmpty()) { return immediateFailedFluentFuture(new MissingSchemaSourceException("URL for " + sourceIdentifier + " not registered", sourceIdentifier)); } return immediateFluentFuture(ret.iterator().next()); }
sources.get(id); if (srcs == null) { return immediateFailedFluentFuture(new MissingSchemaSourceException( "No providers registered for source" + id, id)); return immediateFailedFluentFuture(new MissingSchemaSourceException( "No providers for source " + id + " representation " + representation + " available", id));
return immediateFluentFuture(schemaContext);
@Override public synchronized FluentFuture<YangTextSchemaSource> getSource( final SourceIdentifier sourceIdentifier) { final Collection<YangTextSchemaSource> ret = texts.get(sourceIdentifier); LOG.debug("Lookup {} result {}", sourceIdentifier, ret); if (ret.isEmpty()) { return immediateFailedFluentFuture(new MissingSchemaSourceException("URL for " + sourceIdentifier + " not registered", sourceIdentifier)); } return immediateFluentFuture(ret.iterator().next()); }
@Override public synchronized FluentFuture<? extends T> getSource(final SourceIdentifier sourceIdentifier) { final File file = sourceIdToFile(sourceIdentifier, storageDirectory); if (file.exists() && file.canRead()) { LOG.trace("Source {} found in cache as {}", sourceIdentifier, file); final SchemaSourceRepresentation restored = STORAGE_ADAPTERS.get(representation).restore(sourceIdentifier, file); return immediateFluentFuture(representation.cast(restored)); } LOG.debug("Source {} not found in cache as {}", sourceIdentifier, file); return immediateFailedFluentFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier)); }
@Override public synchronized FluentFuture<? extends T> getSource(final SourceIdentifier sourceIdentifier) { final File file = sourceIdToFile(sourceIdentifier, storageDirectory); if (file.exists() && file.canRead()) { LOG.trace("Source {} found in cache as {}", sourceIdentifier, file); final SchemaSourceRepresentation restored = STORAGE_ADAPTERS.get(representation).restore(sourceIdentifier, file); return immediateFluentFuture(representation.cast(restored)); } LOG.debug("Source {} not found in cache as {}", sourceIdentifier, file); return immediateFailedFluentFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier)); }
@SuppressWarnings("checkstyle:IllegalCatch") @Override public FluentFuture<Optional<NormalizedNode<?,?>>> read(final YangInstanceIdentifier path) { LOG.debug("Tx: {} Read: {}", getIdentifier(), path); requireNonNull(path, "Path must not be null."); final DataTreeSnapshot snapshot = stableSnapshot; if (snapshot == null) { return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Transaction is closed")); } try { return FluentFutures.immediateFluentFuture(snapshot.readNode(path)); } catch (Exception e) { LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e); return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Read failed", e)); } }
@SuppressWarnings("checkstyle:IllegalCatch") @Override public FluentFuture<Optional<NormalizedNode<?,?>>> read(final YangInstanceIdentifier path) { LOG.debug("Tx: {} Read: {}", getIdentifier(), path); requireNonNull(path, "Path must not be null."); final Optional<NormalizedNode<?, ?>> result; try { result = readSnapshotNode(path); } catch (Exception e) { LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e); return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Read failed", e)); } if (result == null) { return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Transaction is closed")); } return FluentFutures.immediateFluentFuture(result); }