import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
/**
* Provides access to registered Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG
* models. {@link RpcProviderService} is this inferface's counterpart allowing registering RPC implementations.
*/
public interface RpcConsumerRegistry extends BindingService {
- /**
- * Returns an implementation of a requested RPC service.
- *
- * <p>
- * The returned instance is not an actual implementation of the RPC service interface, but a proxy implementation of
- * the interface that forwards to an actual implementation, if any.
- *
- * <p>
- * The following describes the behavior of the proxy when invoking RPC methods:
- * <ul>
- * <li>If an actual implementation is registered with the MD-SAL, all invocations are forwarded to the registered
- * implementation.</li>
- * <li>If no actual implementation is registered, all invocations will fail by throwing
- * {@link IllegalStateException}.</li>
- * <li>Prior to invoking the actual implementation, the method arguments are are validated. If any are invalid, an
- * {@link IllegalArgumentException} is thrown.</li>
- * </ul>
- * The returned proxy is automatically updated with the most recent registered implementation.
- *
- * <p>
- * The generated RPC method APIs require implementors to return a
- * {@link java.util.concurrent.Future Future} instance that wraps the
- * {@link org.opendaylight.yangtools.yang.common.RpcResult RpcResult}. Since RPC methods may be
- * implemented asynchronously, callers should avoid blocking on the
- * {@link java.util.concurrent.Future Future} result. Instead, it is recommended to use
- * {@link com.google.common.util.concurrent.JdkFutureAdapters#listenInPoolThread(java.util.concurrent.Future)}
- * or
- * {@link com.google.common.util.concurrent.JdkFutureAdapters#listenInPoolThread(java.util.concurrent.Future,
- * java.util.concurrent.Executor)} to listen for Rpc Result. This will asynchronously listen for future result
- * in executor and will not block current thread.
- *
- * <pre>
- * final Future<RpcResult<SomeRpcOutput>> future = someRpcService.someRpc( ... );
- * Futures.addCallback(JdkFutureAdapters.listenInThreadPool(future), new FutureCallback<RpcResult<
- * SomeRpcOutput>>() {
- *
- * public void onSuccess(RpcResult<SomeRpcOutput> result) {
- * // process result ...
- * }
- *
- * public void onFailure(Throwable t) {
- * // RPC failed
- * }
- * );
- * </pre>
- *
- * @param <S> {@link RpcService} type
- * @param serviceInterface the interface of the RPC Service. Typically this is an interface
- * generated from a YANG model.
- * @return the proxy for the requested RPC service. This method never returns null.
- * @deprecated Use {@link #getRpc(Class)} instead.
- */
- @Deprecated(since = "11.0.0", forRemoval = true)
- <S extends RpcService> @NonNull S getRpcService(@NonNull Class<S> serviceInterface);
-
/**
* Returns an implementation of a requested RPC service.
*
import com.google.common.collect.ClassToInstanceMap;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
/**
* Provides ability to registered Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG
* models.
*/
public interface RpcProviderService extends BindingService {
- /**
- * Register RPCs combined in a {@link RpcService} interface.
- *
- * @param <R> {@link RpcService} type
- * @param <I> {@link RpcService} implementation type
- * @param type {@link RpcService} class
- * @param implementation implementation object
- * @return An {@link ObjectRegistration} controlling unregistration
- * @throws NullPointerException if any argument is {@code null}
- * @deprecated Use {@link #registerRpcImplementation(Rpc)} or
- * {@link #registerRpcImplementations(ClassToInstanceMap)} instead.
- */
- @Deprecated(since = "11.0.0", forRemoval = true)
- <R extends RpcService, I extends R> @NonNull ObjectRegistration<I> registerRpcImplementation(Class<R> type,
- I implementation);
-
- /**
- * Register RPCs combined in a {@link RpcService} interface on a set of datastore context paths.
- *
- * @param <R> {@link RpcService} type
- * @param <I> {@link RpcService} implementation type
- * @param type {@link RpcService} class
- * @param implementation implementation object
- * @param paths Datastore paths to service
- * @return An {@link ObjectRegistration} controlling unregistration
- * @throws NullPointerException if any argument is {@code null}
- * @deprecated Use {@link #registerRpcImplementation(Rpc, Set)} or
- * {@link #registerRpcImplementations(ClassToInstanceMap, Set)} instead.
- */
- @Deprecated(since = "11.0.0", forRemoval = true)
- <R extends RpcService, I extends R> @NonNull ObjectRegistration<I> registerRpcImplementation(Class<R> type,
- I implementation, Set<InstanceIdentifier<?>> paths);
-
/**
* Register an {@link Rpc} implementation.
*
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+import org.opendaylight.mdsal.binding.api.query.QueryFactory;
import org.opendaylight.mdsal.binding.dom.adapter.AdapterContext;
import org.opendaylight.mdsal.binding.dom.adapter.BindingAdapterFactory;
import org.opendaylight.mdsal.binding.dom.adapter.ConstantAdapterContext;
import org.opendaylight.mdsal.binding.dom.adapter.spi.AdapterFactory;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecFactory;
-import org.opendaylight.mdsal.binding.api.query.QueryFactory;
module org.opendaylight.mdsal.binding.dom.adapter {
exports org.opendaylight.mdsal.binding.dom.adapter;
+++ /dev/null
-/*
- * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Verify.verifyNotNull;
-import static java.util.Objects.requireNonNull;
-import static org.opendaylight.mdsal.binding.dom.adapter.StaticConfiguration.ENABLE_CODEC_SHORTCUT;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingLazyContainerNode;
-import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.yangtools.yang.binding.RpcInput;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.YangConstants;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-
-abstract sealed class AbstractDOMRpcImplementationAdapter implements DOMRpcImplementation
- permits BindingDOMRpcImplementationAdapter, LegacyDOMRpcImplementationAdapter {
- private final AdapterContext adapterContext;
- private final @NonNull QName inputName;
- private final @NonNull QName rpcName;
-
- AbstractDOMRpcImplementationAdapter(final AdapterContext adapterContext, final QName rpcName) {
- this.adapterContext = requireNonNull(adapterContext);
- this.rpcName = requireNonNull(rpcName);
- inputName = YangConstants.operationInputQName(rpcName.getModule()).intern();
- }
-
- @Override
- public final long invocationCost() {
- // Default implementations are 0, we need to perform some translation, hence we have a slightly higher cost
- return 1;
- }
-
- @Override
- public final ListenableFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
- final var serializer = adapterContext.currentSerializer();
- return LazyDOMRpcResultFuture.create(serializer, invokeRpc(deserialize(serializer, input)));
- }
-
- abstract @NonNull ListenableFuture<RpcResult<?>> invokeRpc(@NonNull RpcInput input);
-
- private @NonNull RpcInput deserialize(final @NonNull CurrentAdapterSerializer serializer,
- final @NonNull ContainerNode input) {
- if (ENABLE_CODEC_SHORTCUT && input instanceof BindingLazyContainerNode<?> lazy) {
- return (RpcInput) lazy.getDataObject();
- }
-
- checkArgument(inputName.equals(input.name().getNodeType()),
- "Unexpected RPC %s input %s", rpcName, input);
-
- // TODO: this is a bit inefficient: typically we get the same CurrentAdapterSerializer and the path is also
- // constant, hence we should be able to cache this lookup and just have the appropriate
- // BindingDataObjectCodecTreeNode and reuse it directly
- // FIXME: should be a guaranteed return, as innput is @NonNull
- return verifyNotNull((RpcInput) serializer.fromNormalizedNodeRpcData(Absolute.of(rpcName, inputName), input));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static java.util.Objects.requireNonNull;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.binding.dom.adapter.RpcInvocationStrategy.ContentRouted;
-import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.mdsal.dom.spi.ContentRoutedRpcContext;
-
-abstract sealed class AbstractRpcAdapter implements InvocationHandler permits RpcAdapter, RpcServiceAdapter {
- private final @NonNull DOMRpcService delegate;
- private final @NonNull AdapterContext adapterContext;
- private final @NonNull Object facade;
- private final String name;
-
- AbstractRpcAdapter(final AdapterContext adapterContext, final DOMRpcService delegate, final Class<?> type) {
- this.adapterContext = requireNonNull(adapterContext);
- this.delegate = requireNonNull(delegate);
- facade = Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[] { type }, this);
- name = type.getName();
- }
-
- final @NonNull CurrentAdapterSerializer currentSerializer() {
- return adapterContext.currentSerializer();
- }
-
- final @NonNull DOMRpcService delegate() {
- return delegate;
- }
-
- final @NonNull Object facade() {
- return facade;
- }
-
- final @NonNull RpcInvocationStrategy createStrategy(final CurrentAdapterSerializer serializer,
- final RpcRuntimeType rpcType) {
- final var rpc = rpcType.statement();
- final var contentContext = ContentRoutedRpcContext.forRpc(rpc);
- if (contentContext != null) {
- final var extractor = serializer.findExtractor(rpcType.input());
- if (extractor != null) {
- return new ContentRouted(this, rpc.argument(), contentContext.leaf(), extractor);
- }
- }
- return new RpcInvocationStrategy(this, rpc.argument());
- }
-
- @SuppressWarnings("checkstyle:illegalThrows")
- final Object defaultInvoke(final Object proxy, final Method method, final Object [] args) throws Throwable {
- switch (method.getName()) {
- case "toString":
- if (method.getReturnType().equals(String.class) && method.getParameterCount() == 0) {
- return name + "$Adapter{delegate=" + delegate() + "}";
- }
- break;
- case "hashCode":
- if (method.getReturnType().equals(int.class) && method.getParameterCount() == 0) {
- return System.identityHashCode(proxy);
- }
- break;
- case "equals":
- if (method.getReturnType().equals(boolean.class) && method.getParameterCount() == 1
- && method.getParameterTypes()[0] == Object.class) {
- return proxy == args[0];
- }
- break;
- default:
- break;
- }
-
- if (method.isDefault()) {
- return InvocationHandler.invokeDefault(proxy, method, args);
- }
- throw new UnsupportedOperationException("Method " + method.toString() + " is not supported");
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementationRegistration;
-import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-class BindingDOMRpcAdapterRegistration<T extends RpcService> extends AbstractObjectRegistration<T> {
- private final DOMRpcImplementationRegistration<?> reg;
-
- BindingDOMRpcAdapterRegistration(T instance, DOMRpcImplementationRegistration<?> reg) {
- super(instance);
- this.reg = reg;
- }
-
- @Override
- protected void removeRegistration() {
- reg.close();
- }
-}
*/
package org.opendaylight.mdsal.binding.dom.adapter;
+import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
+import static org.opendaylight.mdsal.binding.dom.adapter.StaticConfiguration.ENABLE_CODEC_SHORTCUT;
import com.google.common.util.concurrent.ListenableFuture;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingLazyContainerNode;
+import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
+import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
+import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.binding.RpcInput;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-final class BindingDOMRpcImplementationAdapter extends AbstractDOMRpcImplementationAdapter {
+final class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation {
+ private final @NonNull AdapterContext adapterContext;
+ private final @NonNull QName rpcName;
@SuppressWarnings("rawtypes")
private final @NonNull Rpc delegate;
BindingDOMRpcImplementationAdapter(final AdapterContext adapterContext, final QName rpcName,
final Rpc<?, ?> delegate) {
- super(adapterContext, rpcName);
+ this.adapterContext = requireNonNull(adapterContext);
+ this.rpcName = requireNonNull(rpcName);
this.delegate = requireNonNull(delegate);
}
@Override
- @SuppressWarnings("unchecked")
- ListenableFuture<RpcResult<?>> invokeRpc(final RpcInput input) {
- return delegate.invoke(input);
+ public long invocationCost() {
+ // Default implementations are 0, we need to perform some translation, hence we have a slightly higher cost
+ return 1;
+ }
+
+ @Override
+ public ListenableFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
+ final var serializer = adapterContext.currentSerializer();
+ @SuppressWarnings("unchecked")
+ final var future = delegate.invoke(deserialize(serializer, input));
+ return LazyDOMRpcResultFuture.create(serializer, future);
+ }
+
+ private @NonNull RpcInput deserialize(final @NonNull CurrentAdapterSerializer serializer,
+ final @NonNull ContainerNode input) {
+ if (ENABLE_CODEC_SHORTCUT && input instanceof BindingLazyContainerNode<?> lazy) {
+ return (RpcInput) lazy.getDataObject();
+ }
+
+ final var inputName = input.name().getNodeType();
+ if (!"input".equals(inputName.getLocalName()) || !rpcName.getModule().equals(inputName.getModule())) {
+ throw new IllegalArgumentException("Unexpected RPC " + rpcName + " input " + input.prettyTree());
+ }
+
+ // TODO: this is a bit inefficient: typically we get the same CurrentAdapterSerializer and the path is also
+ // constant, hence we should be able to cache this lookup and just have the appropriate
+ // BindingDataObjectCodecTreeNode and reuse it directly
+ // FIXME: should be a guaranteed return, as input is @NonNull
+ return verifyNotNull((RpcInput) serializer.fromNormalizedNodeRpcData(Absolute.of(rpcName, inputName), input));
}
}
*/
package org.opendaylight.mdsal.binding.dom.adapter;
-import static java.util.Objects.requireNonNull;
-
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.ImmutableClassToInstanceMap;
import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
super(adapterContext, domRpcRegistry);
}
- @Override
- @Deprecated
- public <R extends RpcService, I extends R> ObjectRegistration<I> registerRpcImplementation(final Class<R> type,
- final I implementation) {
- return register(currentSerializer(), type, implementation, GLOBAL);
- }
-
- @Override
- @Deprecated
- public <R extends RpcService, I extends R> ObjectRegistration<I> registerRpcImplementation(final Class<R> type,
- final I implementation, final Set<InstanceIdentifier<?>> paths) {
- final var serializer = currentSerializer();
- return register(serializer, type, implementation, toYangInstanceIdentifiers(serializer, paths));
- }
-
@Override
public Registration registerRpcImplementation(final Rpc<?, ?> implementation) {
return register(currentSerializer(), implementation, GLOBAL);
});
}
- @Deprecated
- private <S extends RpcService, T extends S> ObjectRegistration<T> register(
- final CurrentAdapterSerializer serializer, final Class<S> type, final T implementation,
- // Note: unique items are implied
- final Collection<YangInstanceIdentifier> paths) {
- return new BindingRpcAdapterRegistration<>(implementation, register(
- serializer.getRpcMethods(requireNonNull(type)), paths, (rpcName, mh) -> new Impl(requireNonNull(rpcName),
- new LegacyDOMRpcImplementationAdapter(adapterContext(), rpcName, mh.bindTo(implementation)))));
- }
-
private <K, V> @NonNull Registration register(final Map<K, V> map, final Collection<YangInstanceIdentifier> paths,
final BiFunction<K, V, Impl> implFactory) {
final var builder = ImmutableMap.<DOMRpcIdentifier, DOMRpcImplementation>builderWithExpectedSize(map.size());
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.api.DOMService;
import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
@VisibleForTesting
public final class BindingDOMRpcServiceAdapter
- extends AbstractBindingLoadingAdapter<DOMRpcService, Class<?>, AbstractRpcAdapter>
- implements RpcConsumerRegistry {
+ extends AbstractBindingLoadingAdapter<DOMRpcService, Class<?>, RpcAdapter> implements RpcConsumerRegistry {
static final Factory<RpcConsumerRegistry> BUILDER_FACTORY = Builder::new;
public BindingDOMRpcServiceAdapter(final AdapterContext adapterContext, final DOMRpcService domService) {
}
@Override
- @Deprecated
- public <T extends RpcService> T getRpcService(final Class<T> rpcService) {
- return rpcService.cast(getAdapter(requireNonNull(rpcService)).facade());
- }
-
- @Override
- AbstractRpcAdapter loadAdapter(final Class<?> key) {
+ RpcAdapter loadAdapter(final Class<?> key) {
checkArgument(BindingReflections.isBindingClass(key));
checkArgument(key.isInterface(), "Supplied RPC service type must be interface.");
- if (RpcService.class.isAssignableFrom(key)) {
- return new RpcServiceAdapter(key.asSubclass(RpcService.class), adapterContext(), getDelegate());
- } else if (Rpc.class.isAssignableFrom(key)) {
- return new RpcAdapter<>(adapterContext(), getDelegate(), key.asSubclass(Rpc.class));
+ if (Rpc.class.isAssignableFrom(key)) {
+ return new RpcAdapter(adapterContext(), getDelegate(), key.asSubclass(Rpc.class));
} else {
throw new IllegalStateException("Unhandled key " + key);
}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
-import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-class BindingRpcAdapterRegistration<T extends RpcService> extends AbstractObjectRegistration<T> {
- private final Registration reg;
-
- BindingRpcAdapterRegistration(final T instance, final Registration reg) {
- super(instance);
- this.reg = reg;
- }
-
- @Override
- protected void removeRegistration() {
- reg.close();
- }
-}
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
-import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.RpcInput;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-import org.opendaylight.yangtools.yang.binding.contract.Naming;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@VisibleForTesting
public final class CurrentAdapterSerializer extends ForwardingBindingDOMCodecServices {
private static final Logger LOG = LoggerFactory.getLogger(CurrentAdapterSerializer.class);
- @Deprecated
- private static final MethodType RPC_SERVICE_METHOD_SIGNATURE = MethodType.methodType(ListenableFuture.class,
- RpcService.class, RpcInput.class);
private final LoadingCache<InstanceIdentifier<?>, YangInstanceIdentifier> cache = CacheBuilder.newBuilder()
.softValues().build(new CacheLoader<InstanceIdentifier<?>, YangInstanceIdentifier>() {
});
private final ConcurrentMap<JavaTypeName, ContextReferenceExtractor> extractors = new ConcurrentHashMap<>();
- @Deprecated
- private final ConcurrentMap<Class<? extends RpcService>, ImmutableMap<QName, MethodHandle>> rpcMethods =
- new ConcurrentHashMap<>();
private final @NonNull BindingDOMCodecServices delegate;
public CurrentAdapterSerializer(final BindingDOMCodecServices delegate) {
return raced != null ? raced : created;
}
- @Deprecated
- @NonNull ImmutableMap<QName, MethodHandle> getRpcMethods(final @NonNull Class<? extends RpcService> serviceType) {
- return rpcMethods.computeIfAbsent(serviceType, ignored -> {
- final var lookup = MethodHandles.publicLookup();
- return ImmutableMap.copyOf(Maps.transformValues(createQNameToMethod(serviceType), method -> {
- final MethodHandle raw;
- try {
- raw = lookup.unreflect(method);
- } catch (IllegalAccessException e) {
- throw new IllegalStateException("Lookup on public method failed", e);
- }
- return raw.asType(RPC_SERVICE_METHOD_SIGNATURE);
- }));
- });
- }
-
- @Deprecated
- @VisibleForTesting
- // FIXME: This should be probably part of Binding Runtime context
- ImmutableMap<QName, Method> createQNameToMethod(final Class<? extends RpcService> key) {
- final var moduleName = BindingReflections.getQNameModule(key);
- final var runtimeContext = getRuntimeContext();
- final var module = runtimeContext.getEffectiveModelContext().findModule(moduleName).orElse(null);
- if (module == null) {
- LOG.trace("Schema for {} is not available; expected module name: {}; BindingRuntimeContext: {}",
- key, moduleName, runtimeContext);
- throw new IllegalStateException(String.format("Schema for %s is not available; expected module name: %s;"
- + " full BindingRuntimeContext available in trace log", key, moduleName));
- }
-
- final var ret = ImmutableBiMap.<QName, Method>builder();
- try {
- for (var rpcDef : module.getRpcs()) {
- final var rpcName = rpcDef.getQName();
- ret.put(rpcName, key.getMethod(Naming.getRpcMethodName(rpcName), runtimeContext.getRpcInput(rpcName)));
- }
- } catch (NoSuchMethodException e) {
- throw new IllegalStateException("Rpc defined in model does not have representation in generated class.", e);
- }
- return ret.build();
- }
-
private @NonNull Entry<SchemaInferenceStack, QNameModule> resolvePath(final @NonNull InstanceIdentifier<?> path) {
final var stack = SchemaInferenceStack.of(getRuntimeContext().getEffectiveModelContext());
final var it = toYangInstanceIdentifier(path).getPathArguments().iterator();
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.base.Throwables;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.lang.invoke.MethodHandle;
-import org.opendaylight.yangtools.yang.binding.RpcInput;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-final class LegacyDOMRpcImplementationAdapter extends AbstractDOMRpcImplementationAdapter {
- private final MethodHandle handle;
-
- LegacyDOMRpcImplementationAdapter(final AdapterContext adapterContext, final QName rpcName,
- final MethodHandle handle) {
- super(adapterContext, rpcName);
- this.handle = requireNonNull(handle);
- }
-
- @Override
- @SuppressWarnings("checkstyle:illegalCatch")
- ListenableFuture<RpcResult<?>> invokeRpc(final RpcInput input) {
- try {
- return (ListenableFuture<RpcResult<?>>) handle.invokeExact(input);
- } catch (Throwable e) {
- Throwables.throwIfUnchecked(e);
- throw new IllegalStateException(e);
- }
- }
-}
import static java.util.Objects.requireNonNull;
+import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.dom.adapter.RpcInvocationStrategy.ContentRouted;
+import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.spi.ContentRoutedRpcContext;
import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.binding.RpcInput;
import org.opendaylight.yangtools.yang.binding.contract.Naming;
-final class RpcAdapter<T extends Rpc<?, ?>> extends AbstractRpcAdapter {
+final class RpcAdapter implements InvocationHandler {
+ private final @NonNull AdapterContext adapterContext;
+ private final @NonNull DOMRpcService delegate;
private final RpcInvocationStrategy strategy;
+ private final @NonNull Rpc<?, ?> facade;
private final Method invokeMethod;
+ private final String name;
- RpcAdapter(final AdapterContext adapterContext, final DOMRpcService delegate, final Class<T> type) {
- super(adapterContext, delegate, type);
+ <T extends Rpc<?, ?>> RpcAdapter(final AdapterContext adapterContext, final DOMRpcService delegate,
+ final Class<T> type) {
+ this.adapterContext = requireNonNull(adapterContext);
+ this.delegate = requireNonNull(delegate);
final var serializer = adapterContext.currentSerializer();
final var rpcType = serializer.getRuntimeContext().getRpcDefinition(type);
throw new IllegalStateException("Failed to find invoke method in " + type, e);
}
+ facade = type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[] { type }, this));
+ name = type.getName();
+
strategy = createStrategy(serializer, rpcType);
}
+ private @NonNull RpcInvocationStrategy createStrategy(final CurrentAdapterSerializer serializer,
+ final RpcRuntimeType rpcType) {
+ final var rpc = rpcType.statement();
+ final var contentContext = ContentRoutedRpcContext.forRpc(rpc);
+ if (contentContext != null) {
+ final var extractor = serializer.findExtractor(rpcType.input());
+ if (extractor != null) {
+ return new ContentRouted(this, rpc.argument(), contentContext.leaf(), extractor);
+ }
+ }
+ return new RpcInvocationStrategy(this, rpc.argument());
+ }
+
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
- return invokeMethod.equals(method) ? strategy.invoke((RpcInput) requireNonNull(args[0]))
- : defaultInvoke(proxy, method, args);
+ if (invokeMethod.equals(method)) {
+ return strategy.invoke((RpcInput) requireNonNull(args[0]));
+ }
+
+ switch (method.getName()) {
+ case "toString":
+ if (method.getReturnType().equals(String.class) && method.getParameterCount() == 0) {
+ return name + "$Adapter{delegate=" + delegate + "}";
+ }
+ break;
+ case "hashCode":
+ if (method.getReturnType().equals(int.class) && method.getParameterCount() == 0) {
+ return System.identityHashCode(proxy);
+ }
+ break;
+ case "equals":
+ if (method.getReturnType().equals(boolean.class) && method.getParameterCount() == 1
+ && method.getParameterTypes()[0] == Object.class) {
+ return proxy == args[0];
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (method.isDefault()) {
+ return InvocationHandler.invokeDefault(proxy, method, args);
+ }
+ throw new UnsupportedOperationException("Method " + method.toString() + " is not supported");
+ }
+
+ @NonNull CurrentAdapterSerializer currentSerializer() {
+ return adapterContext.currentSerializer();
+ }
+
+ @NonNull DOMRpcService delegate() {
+ return delegate;
+ }
+
+ @NonNull Rpc<?, ?> facade() {
+ return facade;
}
}
private final ContextReferenceExtractor refExtractor;
private final NodeIdentifier contextName;
- ContentRouted(final AbstractRpcAdapter adapter, final QName rpcName, final QName leafName,
+ ContentRouted(final RpcAdapter adapter, final QName rpcName, final QName leafName,
final ContextReferenceExtractor refExtractor) {
super(adapter, rpcName);
contextName = NodeIdentifier.create(leafName);
}
}
- private final @NonNull AbstractRpcAdapter adapter;
+ private final @NonNull RpcAdapter adapter;
private final @NonNull NodeIdentifier inputIdentifier;
private final @NonNull Absolute outputPath;
- RpcInvocationStrategy(final AbstractRpcAdapter adapter, final QName rpcName) {
+ RpcInvocationStrategy(final RpcAdapter adapter, final QName rpcName) {
this.adapter = requireNonNull(adapter);
final var namespace = rpcName.getModule();
outputPath = Absolute.of(rpcName, YangConstants.operationOutputQName(namespace).intern()).intern();
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.ImmutableMap;
-import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
-import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.yangtools.yang.binding.RpcInput;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-import org.opendaylight.yangtools.yang.binding.contract.Naming;
-import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
-
-@Deprecated
-final class RpcServiceAdapter extends AbstractRpcAdapter {
- private final ImmutableMap<Method, RpcInvocationStrategy> rpcNames;
-
- RpcServiceAdapter(final Class<? extends RpcService> type, final AdapterContext adapterContext,
- final DOMRpcService domService) {
- super(adapterContext, domService, type);
-
- // FIXME: This should be probably part of BindingRuntimeContext and RpcServices perhaps should have their own
- // RuntimeType. At any rate, we are dancing around to reconstruct information RpcServiceRuntimeType would
- // carry and the runtime context would bind to actual classes.
- final var serializer = adapterContext.currentSerializer();
- final var runtimeContext = serializer.getRuntimeContext();
- final var types = runtimeContext.getTypes();
- final var qnameModule = BindingReflections.getQNameModule(type);
-
- // We are dancing a bit here to reconstruct things a RpcServiceRuntimeType could easily hold
- final var module = runtimeContext.getEffectiveModelContext().findModuleStatement(qnameModule)
- .orElseThrow(() -> new IllegalStateException("No module found for " + qnameModule + " service " + type));
- rpcNames = module.streamEffectiveSubstatements(RpcEffectiveStatement.class)
- .map(rpc -> {
- final var rpcName = rpc.argument();
- final var inputClz = runtimeContext.getRpcInput(rpcName);
- final var methodName = Naming.getRpcMethodName(rpcName);
-
- final Method method;
- try {
- method = type.getMethod(methodName, inputClz);
- } catch (NoSuchMethodException e) {
- throw new IllegalStateException("Cannot find RPC method for " + rpc, e);
- }
-
- final var runtimeType = types.schemaTreeChild(rpcName);
- if (!(runtimeType instanceof RpcRuntimeType rpcType)) {
- throw new IllegalStateException("Unexpected run-time type " + runtimeType + " for " + rpcName);
- }
-
- return Map.entry(method, createStrategy(serializer, rpcType));
- })
- .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue));
- }
-
- @Override
- public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
- final var strategy = rpcNames.get(method);
- return strategy != null ? strategy.invoke((RpcInput) requireNonNull(args[0]))
- : defaultInvoke(proxy, method, args);
- }
-}
}
private StaticConfiguration() {
-
+ // Hidden on purpose
}
}
import java.util.Map;
import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
return delegate().getRpc(rpcInterface);
}
- @Override
- @Deprecated
- public <T extends RpcService> T getRpcService(final Class<T> serviceInterface) {
- return delegate().getRpcService(serviceInterface);
- }
-
@Activate
void activate(final Map<String, ?> properties) {
start(properties);
import java.util.Map;
import java.util.Set;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.Rpc;
-import org.opendaylight.yangtools.yang.binding.RpcService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
super(RpcProviderService.class);
}
- @Override
- @Deprecated
- public <R extends RpcService, I extends R> ObjectRegistration<I> registerRpcImplementation(final Class<R> type,
- final I implementation) {
- return delegate().registerRpcImplementation(type, implementation);
- }
-
- @Override
- @Deprecated
- public <R extends RpcService, I extends R> ObjectRegistration<I> registerRpcImplementation(final Class<R> type,
- final I implementation, final Set<InstanceIdentifier<?>> paths) {
- return delegate().registerRpcImplementation(type, implementation, paths);
- }
-
@Override
public Registration registerRpcImplementation(final Rpc<?, ?> implementation) {
return delegate().registerRpcImplementation(implementation);
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import org.junit.Test;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementationRegistration;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-public class BindingDOMRpcAdapterRegistrationTest {
- @Test
- public void removeRegistration() {
- final DOMRpcImplementationRegistration<?> registration = mock(DOMRpcImplementationRegistration.class);
- final BindingDOMRpcAdapterRegistration<?> adapterReg =
- new BindingDOMRpcAdapterRegistration<>(mock(RpcService.class), registration);
- adapterReg.close();
- verify(registration).close();
- }
-}
\ No newline at end of file
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
-import java.util.concurrent.Future;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnock;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.OpendaylightKnockKnockRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
private DOMRpcProviderService biRpcProviderService;
private BindingTestContext testContext;
private DOMRpcService biRpcService;
- private final OpendaylightKnockKnockRpcServiceImpl knockRpcImpl = new OpendaylightKnockKnockRpcServiceImpl();
+ private final KnockKnockImpl knockRpcImpl = new KnockKnockImpl();
@Before
public void setup() throws Exception {
testContext = testFactory.getTestContext();
testContext.setSchemaModuleInfos(ImmutableSet.of(
- BindingRuntimeHelpers.getYangModuleInfo(OpendaylightKnockKnockRpcService.class),
+ BindingRuntimeHelpers.getYangModuleInfo(KnockKnock.class),
BindingRuntimeHelpers.getYangModuleInfo(Top.class)));
testContext.start();
baRpcProviderService = testContext.getBindingRpcProviderRegistry();
public void testBindingRegistrationWithDOMInvocation() throws Exception {
knockRpcImpl.registerTo(baRpcProviderService, BA_NODE_ID).setKnockKnockResult(knockResult(true, "open"));
- final OpendaylightKnockKnockRpcService baKnockService =
- baRpcConsumerService.getRpcService(OpendaylightKnockKnockRpcService.class);
+ final var baKnockService = baRpcConsumerService.getRpc(KnockKnock.class);
assertNotSame(knockRpcImpl, baKnockService);
- KnockKnockInput baKnockKnockInput = knockKnock(BA_NODE_ID).setQuestion("who's there?").build();
+ final var baKnockKnockInput = knockKnock(BA_NODE_ID).setQuestion("who's there?").build();
- ContainerNode biKnockKnockInput = toDOMKnockKnockInput(baKnockKnockInput);
- DOMRpcResult domResult = Futures.getDone(biRpcService.invokeRpc(KNOCK_KNOCK_QNAME, biKnockKnockInput));
+ final var biKnockKnockInput = toDOMKnockKnockInput(baKnockKnockInput);
+ final var domResult = Futures.getDone(biRpcService.invokeRpc(KNOCK_KNOCK_QNAME, biKnockKnockInput));
assertNotNull(domResult);
assertNotNull(domResult.value());
assertTrue("Binding KnockKnock service was not invoked",
@Test
public void testDOMRegistrationWithBindingInvocation() throws Exception {
- KnockKnockOutput baKnockKnockOutput = new KnockKnockOutputBuilder().setAnswer("open").build();
+ final var baKnockKnockOutput = new KnockKnockOutputBuilder().setAnswer("open").build();
biRpcProviderService.registerRpcImplementation((rpc, input) ->
FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(testContext.getCodec()
DOMRpcIdentifier.create(KNOCK_KNOCK_QNAME, testContext.getCodec().currentSerializer()
.toYangInstanceIdentifier(BA_NODE_ID)));
- final OpendaylightKnockKnockRpcService baKnockService =
- baRpcConsumerService.getRpcService(OpendaylightKnockKnockRpcService.class);
- Future<RpcResult<KnockKnockOutput>> baResult = baKnockService.knockKnock(knockKnock(BA_NODE_ID)
- .setQuestion("Who's there?").build());
+ final var baKnockService = baRpcConsumerService.getRpc(KnockKnock.class);
+ final var baResult = baKnockService.invoke(knockKnock(BA_NODE_ID).setQuestion("Who's there?").build());
assertNotNull(baResult);
assertEquals(baKnockKnockOutput, Futures.getDone(baResult).getResult());
}
@Test
public void testBindingRpcShortcut() throws Exception {
- final ListenableFuture<RpcResult<KnockKnockOutput>> baKnockResult = knockResult(true, "open");
+ final var baKnockResult = knockResult(true, "open");
knockRpcImpl.registerTo(baRpcProviderService, BA_NODE_ID).setKnockKnockResult(baKnockResult);
- final OpendaylightKnockKnockRpcService baKnockService =
- baRpcConsumerService.getRpcService(OpendaylightKnockKnockRpcService.class);
+ final var baKnockService = baRpcConsumerService.getRpc(KnockKnock.class);
- KnockKnockInput baKnockKnockInput = knockKnock(BA_NODE_ID).setQuestion("who's there?").build();
+ final var baKnockKnockInput = knockKnock(BA_NODE_ID).setQuestion("who's there?").build();
- final RpcResult<KnockKnockOutput> rpcResult = Futures.getDone(baKnockService.knockKnock(baKnockKnockInput));
+ final var rpcResult = Futures.getDone(baKnockService.invoke(baKnockKnockInput));
assertEquals(baKnockResult.get().getResult().getClass(), rpcResult.getResult().getClass());
assertSame(baKnockResult.get().getResult(), rpcResult.getResult());
public void testSimpleRpc() throws Exception {
baRpcProviderService.registerRpcImplementation((KnockKnock) input -> knockResult(true, "open"));
- final KnockKnock baKnockService = baRpcConsumerService.getRpc(KnockKnock.class);
- final RpcResult<KnockKnockOutput> rpcResult = Futures.getDone(
+ final var baKnockService = baRpcConsumerService.getRpc(KnockKnock.class);
+ final var rpcResult = Futures.getDone(
baKnockService.invoke(knockKnock(BA_NODE_ID).setQuestion("who's there?").build()));
assertEquals(rpcResult.getResult().getClass(), rpcResult.getResult().getClass());
return testContext.getCodec().currentSerializer().toNormalizedNodeRpcData(from);
}
- private static final class OpendaylightKnockKnockRpcServiceImpl implements OpendaylightKnockKnockRpcService {
+ private static final class KnockKnockImpl implements KnockKnock {
private final Multimap<InstanceIdentifier<?>, KnockKnockInput> receivedKnocks = HashMultimap.create();
private ListenableFuture<RpcResult<KnockKnockOutput>> knockKnockResult;
- private ObjectRegistration<OpendaylightKnockKnockRpcServiceImpl> registration;
+ private Registration registration;
- OpendaylightKnockKnockRpcServiceImpl setKnockKnockResult(
+ KnockKnockImpl setKnockKnockResult(
final ListenableFuture<RpcResult<KnockKnockOutput>> kkOutput) {
knockKnockResult = kkOutput;
return this;
return receivedKnocks;
}
- OpendaylightKnockKnockRpcServiceImpl registerTo(final RpcProviderService registry,
- final InstanceIdentifier<?>... paths) {
- registration = registry.registerRpcImplementation(OpendaylightKnockKnockRpcService.class, this,
- ImmutableSet.copyOf(paths));
+ KnockKnockImpl registerTo(final RpcProviderService registry, final InstanceIdentifier<?>... paths) {
+ registration = registry.registerRpcImplementation(this, ImmutableSet.copyOf(paths));
assertNotNull(registration);
return this;
}
@Override
- public ListenableFuture<RpcResult<KnockKnockOutput>> knockKnock(final KnockKnockInput input) {
+ public ListenableFuture<RpcResult<KnockKnockOutput>> invoke(final KnockKnockInput input) {
receivedKnocks.put(input.getKnockerId(), input);
return knockKnockResult;
}
+++ /dev/null
-/*
- * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static org.junit.Assert.assertTrue;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSetMultimap;
-import com.google.common.collect.SetMultimap;
-import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.Set;
-import org.junit.Test;
-import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractSchemaAwareTest;
-import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecFactory;
-import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.spi.AbstractSchemaContext;
-
-public class BindingNormalizedCodecTest extends AbstractSchemaAwareTest {
-
- private CurrentAdapterSerializer serializer;
-
- @Override
- protected void setupWithRuntimeContext(final BindingRuntimeContext runtimeContext) {
- serializer = new CurrentAdapterSerializer(ServiceLoader.load(BindingDOMCodecFactory.class)
- .findFirst().orElseThrow().createBindingDOMCodec(runtimeContext));
- }
-
- @Test
- public void testGetRpcMethodToQName() {
- assertTrue(serializer.createQNameToMethod(OpendaylightTestRpcServiceService.class)
- .values().stream()
- .map(Method::getName)
- .anyMatch("rockTheHouse"::equals));
- }
-
- static class EmptyEffectiveModelContext extends AbstractSchemaContext implements EffectiveModelContext {
- @Override
- public Set<Module> getModules() {
- return ImmutableSet.of();
- }
-
- @Override
- protected Map<QNameModule, Module> getModuleMap() {
- return ImmutableMap.of();
- }
-
- @Override
- protected SetMultimap<XMLNamespace, Module> getNamespaceToModules() {
- return ImmutableSetMultimap.of();
- }
-
- @Override
- protected SetMultimap<String, Module> getNameToModules() {
- return ImmutableSetMultimap.of();
- }
-
- @Override
- public Map<QNameModule, ModuleEffectiveStatement> getModuleStatements() {
- return ImmutableMap.of();
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import org.junit.Test;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementationRegistration;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-public class BindingRpcAdapterRegistrationTest {
- @Test
- public void removeRegistrationTest() throws Exception {
- final RpcService rpcService = mock(RpcService.class);
- final DOMRpcImplementationRegistration<?> domRpcImplementationRegistration =
- mock(DOMRpcImplementationRegistration.class);
- final BindingRpcAdapterRegistration<?> bindingRpcAdapterRegistration =
- new BindingRpcAdapterRegistration<>(rpcService, domRpcImplementationRegistration);
- doNothing().when(domRpcImplementationRegistration).close();
- bindingRpcAdapterRegistration.close();
- verify(domRpcImplementationRegistration).close();
- }
-}
\ No newline at end of file
import com.google.common.util.concurrent.MoreExecutors;
import java.util.Set;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.Before;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
-import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
-import org.opendaylight.yang.gen.v1.rpc.norev.Mdsal500Service;
+import org.opendaylight.yang.gen.v1.rpc.norev.$YangModuleInfoImpl;
+import org.opendaylight.yang.gen.v1.rpc.norev.Switch;
import org.opendaylight.yang.gen.v1.rpc.norev.SwitchInput;
import org.opendaylight.yang.gen.v1.rpc.norev.SwitchInputBuilder;
import org.opendaylight.yang.gen.v1.rpc.norev.SwitchOutput;
import org.opendaylight.yang.gen.v1.rpc.norev.SwitchOutputBuilder;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcResult;
private DOMRpcProviderService biRpcProviderService;
private BindingTestContext testContext;
private DOMRpcService biRpcService;
- private final Mdsal500ServiceImpl switchRpcImpl = new Mdsal500ServiceImpl();
+ private final SwitchImpl switchRpcImpl = new SwitchImpl();
@Before
public void setup() throws Exception {
testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
testContext = testFactory.getTestContext();
- testContext.setSchemaModuleInfos(Set.of(
- BindingRuntimeHelpers.getYangModuleInfo(Mdsal500Service.class)));
+ testContext.setSchemaModuleInfos(Set.of($YangModuleInfoImpl.getInstance()));
testContext.start();
baRpcProviderService = testContext.getBindingRpcProviderRegistry();
baRpcConsumerService = testContext.getBindingRpcConsumerRegistry();
public void testBindingRegistrationWithDOMInvocation() throws Exception {
switchRpcImpl.registerTo(baRpcProviderService).setSwitchResult(switchResult(true));
- final Mdsal500Service baSwitchService = baRpcConsumerService.getRpcService(Mdsal500Service.class);
+ final var baSwitchService = baRpcConsumerService.getRpc(Switch.class);
assertNotSame(switchRpcImpl, baSwitchService);
SwitchInput baSwitchInput = switchBuilder(FOO).build();
.toNormalizedNodeRpcData(baSwitchOutput))),
DOMRpcIdentifier.create(SWITCH_QNAME));
- final Mdsal500Service baSwitchService =
- baRpcConsumerService.getRpcService(Mdsal500Service.class);
- Future<RpcResult<SwitchOutput>> baResult = baSwitchService.switch$(switchBuilder(FOO)
- .build());
+ final var baSwitchService = baRpcConsumerService.getRpc(Switch.class);
+ final var baResult = baSwitchService.invoke(switchBuilder(FOO).build());
assertNotNull(baResult);
assertEquals(baSwitchOutput, baResult.get(5, TimeUnit.SECONDS).getResult());
}
@Test
public void testBindingRpcShortcut() throws InterruptedException, ExecutionException, TimeoutException {
- final ListenableFuture<RpcResult<SwitchOutput>> baSwitchResult = switchResult(true);
+ final var baSwitchResult = switchResult(true);
switchRpcImpl.registerTo(baRpcProviderService).setSwitchResult(baSwitchResult);
- final Mdsal500Service baSwitchService = baRpcConsumerService.getRpcService(Mdsal500Service.class);
+ final var baSwitchService = baRpcConsumerService.getRpc(Switch.class);
- SwitchInput baSwitchInput = switchBuilder(FOO).build();
- ListenableFuture<RpcResult<SwitchOutput>> future = baSwitchService.switch$(baSwitchInput);
+ final var baSwitchInput = switchBuilder(FOO).build();
+ final var future = baSwitchService.invoke(baSwitchInput);
- final RpcResult<SwitchOutput> rpcResult = future.get(5, TimeUnit.SECONDS);
+ final var rpcResult = future.get(5, TimeUnit.SECONDS);
assertEquals(baSwitchResult.get().getResult().getClass(), rpcResult.getResult().getClass());
assertSame(baSwitchResult.get().getResult(), rpcResult.getResult());
return testContext.getCodec().currentSerializer().toNormalizedNodeRpcData(from);
}
- private static final class Mdsal500ServiceImpl implements Mdsal500Service {
+ private static final class SwitchImpl implements Switch {
private final Multimap<String, SwitchInput> receivedSwitch = HashMultimap.create();
private ListenableFuture<RpcResult<SwitchOutput>> switchResult;
- Mdsal500ServiceImpl setSwitchResult(final ListenableFuture<RpcResult<SwitchOutput>> switchOutput) {
+ SwitchImpl setSwitchResult(final ListenableFuture<RpcResult<SwitchOutput>> switchOutput) {
switchResult = switchOutput;
return this;
}
return receivedSwitch;
}
- Mdsal500ServiceImpl registerTo(final RpcProviderService registry) {
- final ObjectRegistration<Mdsal500ServiceImpl> registration =
- registry.registerRpcImplementation(Mdsal500Service.class, this);
+ SwitchImpl registerTo(final RpcProviderService registry) {
+ final var registration = registry.registerRpcImplementation(this);
assertNotNull(registration);
return this;
}
@Override
- public ListenableFuture<RpcResult<SwitchOutput>> switch$(final SwitchInput switchInput) {
+ public ListenableFuture<RpcResult<SwitchOutput>> invoke(final SwitchInput switchInput) {
receivedSwitch.put(switchInput.getFoo(), switchInput);
return switchResult;
}
*/
package org.opendaylight.mdsal.binding.dom.adapter;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListeningExecutorService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
-import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouse;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
@ExtendWith(MockitoExtension.class)
-public class Mdsal739Test {
- private ListeningExecutorService executorService;
+class Mdsal739Test {
+ private final ListeningExecutorService executorService = MoreExecutors.newDirectExecutorService();
+
+ @Mock
+ private DOMRpcService rpcService;
+ @Captor
+ private ArgumentCaptor<ContainerNode> captor;
+
private AdapterContext adapterContext;
@BeforeEach
- public void before() {
- executorService = MoreExecutors.newDirectExecutorService();
-
- final BindingBrokerTestFactory bindingBrokerTestFactory = new BindingBrokerTestFactory();
+ void before() {
+ final var bindingBrokerTestFactory = new BindingBrokerTestFactory();
bindingBrokerTestFactory.setExecutor(executorService);
- final BindingTestContext bindingTestContext = bindingBrokerTestFactory.getTestContext();
+ final var bindingTestContext = bindingBrokerTestFactory.getTestContext();
bindingTestContext.start();
adapterContext = bindingTestContext.getCodec();
}
@AfterEach
- public void after() {
+ void after() {
executorService.shutdownNow();
}
@Test
- public void testRpcInputName() {
- final var rpcService = mock(DOMRpcService.class);
-
- final var captor = ArgumentCaptor.forClass(ContainerNode.class);
+ void testRpcInputName() {
doReturn(Futures.immediateFailedFuture(new Throwable())).when(rpcService).invokeRpc(any(), captor.capture());
- final var adapter = (OpendaylightTestRpcServiceService) new RpcServiceAdapter(
- OpendaylightTestRpcServiceService.class, adapterContext, rpcService).facade();
+ final var adapter = (RockTheHouse) new RpcAdapter(adapterContext, rpcService, RockTheHouse.class).facade();
- final var result = adapter.rockTheHouse(new RockTheHouseInputBuilder().setZipCode("12345").build());
+ final var result = adapter.invoke(new RockTheHouseInputBuilder().setZipCode("12345").build());
assertThrows(ExecutionException.class, () -> Futures.getDone(result));
final var input = captor.getValue();
- assertThat(input, instanceOf(ContainerNode.class));
assertSame(NodeIdentifier.create(RockTheHouseInput.QNAME), input.name());
final var body = input.body();
assertEquals(1, body.size());
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.adapter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import com.google.common.util.concurrent.MoreExecutors;
-import java.lang.reflect.Method;
-import org.junit.Test;
-import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
-import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.OpendaylightTestRoutedRpcService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-@Deprecated(since = "11.0.0", forRemoval = true)
-public class RpcServiceAdapterTest {
-
- @SuppressWarnings("checkstyle:IllegalThrows")
- @Test
- public void invoke() throws Throwable {
- final BindingBrokerTestFactory bindingBrokerTestFactory = new BindingBrokerTestFactory();
- bindingBrokerTestFactory.setExecutor(MoreExecutors.newDirectExecutorService());
- final BindingTestContext bindingTestContext = bindingBrokerTestFactory.getTestContext();
- bindingTestContext.start();
-
- RpcServiceAdapter rpcServiceAdapter = new RpcServiceAdapter(OpendaylightTestRpcServiceService.class,
- bindingTestContext.getCodec(), bindingTestContext.getDomRpcInvoker());
-
- Method method = TestRpcService.class.getMethod("equals", Object.class);
- assertTrue((boolean) rpcServiceAdapter.invoke(rpcServiceAdapter.facade(), method,
- new Object[]{ rpcServiceAdapter.facade() }));
- assertFalse((boolean) rpcServiceAdapter.invoke(rpcServiceAdapter.facade(), method,
- new Object[]{ new Object() }));
-
- method = TestRpcService.class.getMethod("hashCode");
- assertEquals(rpcServiceAdapter.facade().hashCode(), rpcServiceAdapter.invoke(rpcServiceAdapter.facade(),
- method, new Object[]{ }));
-
- method = TestRpcService.class.getMethod("toString");
- assertEquals(rpcServiceAdapter.facade().toString(), rpcServiceAdapter.invoke(rpcServiceAdapter.facade(),
- method, new Object[]{ }));
-
- method = OpendaylightTestRpcServiceService.class.getMethod("rockTheHouse", RockTheHouseInput.class);
- assertNotNull(rpcServiceAdapter.invoke(rpcServiceAdapter.facade(), method,
- new Object[]{ new RockTheHouseInputBuilder().build() }));
-
- rpcServiceAdapter = new RpcServiceAdapter(OpendaylightTestRoutedRpcService.class,
- bindingTestContext.getCodec(), bindingTestContext.getDomRpcInvoker());
- method = OpendaylightTestRoutedRpcService.class.getMethod("routedSimpleRoute", RoutedSimpleRouteInput.class);
- assertNotNull(rpcServiceAdapter.invoke(rpcServiceAdapter.facade(), method,
- new Object[]{ new RoutedSimpleRouteInputBuilder().build() }));
- }
-
- private interface TestRpcService extends RpcService {
-
- @Override
- String toString();
-
- @Override
- int hashCode();
-
- @Override
- boolean equals(Object object);
- }
-}
\ No newline at end of file
// Compatibility FooService and FooListener interfaces, only generated for modules.
if (this instanceof ModuleGenerator moduleGen) {
- final List<NotificationGenerator> notifs = tmp.stream()
+ final var notifs = tmp.stream()
.filter(NotificationGenerator.class::isInstance)
.map(NotificationGenerator.class::cast)
.collect(Collectors.toUnmodifiableList());
if (!notifs.isEmpty()) {
tmp.add(new NotificationServiceGenerator(moduleGen, notifs));
}
-
- final List<RpcGenerator> rpcs = tmp.stream()
- .filter(RpcGenerator.class::isInstance)
- .map(RpcGenerator.class::cast)
- .collect(Collectors.toUnmodifiableList());
- if (!rpcs.isEmpty()) {
- tmp.add(new RpcServiceGenerator(moduleGen, rpcs));
- }
}
return List.copyOf(tmp);
+++ /dev/null
-/*
- * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.generator.impl.reactor;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.List;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
-import org.opendaylight.mdsal.binding.model.api.TypeMemberComment;
-import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
-import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder;
-import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
-import org.opendaylight.mdsal.binding.model.ri.Types;
-import org.opendaylight.yangtools.yang.binding.contract.Naming;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
-
-/**
- * Aggregate service for top-level {@code rpc} statements for a particular module.
- */
-// FIXME: eventually remove this generator
-@Deprecated(since = "11.0.0", forRemoval = true)
-final class RpcServiceGenerator extends AbstractImplicitGenerator {
- private static final JavaTypeName CHECK_RETURN_VALUE_ANNOTATION =
- // Do not refer to annotation class, as it may not be available at runtime
- JavaTypeName.create("edu.umd.cs.findbugs.annotations", "CheckReturnValue");
-
- private final List<RpcGenerator> rpcs;
-
- RpcServiceGenerator(final ModuleGenerator parent, final List<RpcGenerator> rpcs) {
- super(parent);
- this.rpcs = requireNonNull(rpcs);
- }
-
- @Override
- StatementNamespace namespace() {
- return StatementNamespace.RPC_SERVICE;
- }
-
- @Override
- String classSuffix() {
- return Naming.RPC_SERVICE_SUFFIX;
- }
-
- @Override
- GeneratedType createTypeImpl(final TypeBuilderFactory builderFactory) {
- final GeneratedTypeBuilder builder = builderFactory.newGeneratedTypeBuilder(typeName());
- builder.addImplementsType(BindingTypes.RPC_SERVICE);
-
- for (RpcGenerator rpcGen : rpcs) {
- final RpcEffectiveStatement rpc = rpcGen.statement();
- final QName qname = rpc.argument();
-
- // FIXME: this may still conflict in theory
- final MethodSignatureBuilder method = builder.addMethod(Naming.getRpcMethodName(qname));
-
- method.addParameter(getChild(rpcGen, InputEffectiveStatement.class).getGeneratedType(builderFactory),
- "input");
- method.setReturnType(Types.listenableFutureTypeFor(BindingTypes.rpcResult(
- getChild(rpcGen, OutputEffectiveStatement.class).getGeneratedType(builderFactory))));
-
- // FIXME: this should not be part of runtime types
- method.addAnnotation(CHECK_RETURN_VALUE_ANNOTATION);
- final String rpcName = qname.getLocalName();
- method.setComment(new TypeMemberComment("Invoke {@code " + rpcName + "} RPC.",
- rpc.findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null),
- "@param input of {@code " + rpcName + "}\n"
- + "@return output of {@code " + rpcName + '}'));
- }
-
- // FIXME: activate this
- // addCodegenInformation(interfaceBuilder, module, "RPCs", rpcDefinitions);
-
- return builder.build();
- }
-}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.binding.NotificationListener;
-import org.opendaylight.yangtools.yang.binding.RpcService;
/**
* <a href="https://www.rfc-editor.org/rfc/rfc6020#section-6.2.1">YANG statement namespaces</a> which we process.
*/
// FIXME: MDSAL-497: remove this value
@Deprecated
- NOTIFICATION_LISTENER("$LL", true),
- /**
- * The namespace for combined {@link RpcService} interface. This typically does not conflict, but could in case of
- * <code>
- * <pre>
- * module foo {
- * container foo-service; // results in FooService
- * rpc bar; // Triggers FooService generation for module
- * }
- * </pre>
- * </code>
- * In this case the module-derived FooService gets shifted to {@code $LR}.
- *
- * @deprecated This will be removed once {@link RpcServiceGenerator} is gone.
- */
- // FIXME: MDSAL-497: remove this value
- @Deprecated
- RPC_SERVICE("$LR", true);
+ NOTIFICATION_LISTENER("$LL", true);
private final @NonNull String suffix;
private final boolean resistant;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.util.List;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.model.api.MethodSignature;
import org.opendaylight.yangtools.yang.binding.contract.Naming;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
@Test
public void testContainerResolving() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+ final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
"/simple-container-demo.yang"));
assertNotNull(genTypes);
assertEquals(3, genTypes.size());
- GeneratedType simpleContainer = genTypes.get(1);
- GeneratedType nestedContainer = genTypes.get(2);
- for (GeneratedType t : genTypes) {
+ var simpleContainer = genTypes.get(1);
+ var nestedContainer = genTypes.get(2);
+ for (var t : genTypes) {
if ("SimpleContainer".equals(t.getName())) {
simpleContainer = t;
} else if ("NestedContainer".equals(t.getName())) {
String getFooMethodReturnTypeName = "";
String getBarMethodReturnTypeName = "";
String getNestedContainerReturnTypeName = "";
- for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
+ for (var method : simpleContainer.getMethodDefinitions()) {
if (method.getName().equals("getFoo")) {
getFooMethodCounter++;
getFooMethodReturnTypeName = method.getReturnType().getName();
getFooMethodReturnTypeName = "";
getBarMethodReturnTypeName = "";
- for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
-
+ for (var method : nestedContainer.getMethodDefinitions()) {
if (method.getName().equals("getFoo")) {
getFooMethodCounter++;
getFooMethodReturnTypeName = method.getReturnType().getName();
@Test
public void testLeafListResolving() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+ final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
"/simple-leaf-list-demo.yang"));
assertNotNull(genTypes);
assertEquals(3, genTypes.size());
- GeneratedType simpleContainer = genTypes.get(1);
- GeneratedType nestedContainer = genTypes.get(2);
- for (GeneratedType t : genTypes) {
+ var simpleContainer = genTypes.get(1);
+ var nestedContainer = genTypes.get(2);
+ for (var t : genTypes) {
if ("SimpleContainer".equals(t.getName())) {
simpleContainer = t;
} else if ("NestedContainer".equals(t.getName())) {
String getFooMethodReturnTypeName = "";
String getBarMethodReturnTypeName = "";
String getNestedContainerReturnTypeName = "";
- for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
+ for (var method : simpleContainer.getMethodDefinitions()) {
if (method.isDefault()) {
continue;
}
getFooMethodReturnTypeName = "";
getBarMethodReturnTypeName = "";
- for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
+ for (var method : nestedContainer.getMethodDefinitions()) {
if (method.getName().equals("getFoo")) {
getFooMethodCounter++;
getFooMethodReturnTypeName = method.getReturnType().getName();
@Test
public void testListResolving() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+ final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
"/simple-list-demo.yang"));
assertNotNull(genTypes);
String getSimpleListKeyMethodReturnTypeName = "";
String getListChildContainerMethodReturnTypeName = "";
- for (final GeneratedType genType : genTypes) {
+ for (var genType : genTypes) {
if (!(genType instanceof GeneratedTransferObject genTO)) {
if (genType.getName().equals("ListParentContainer")) {
listParentContainerMethodsCount = genType.getMethodDefinitions().size();
} else if (genType.getName().equals("SimpleList")) {
simpleListMethodsCount = genType.getMethodDefinitions().size();
- final List<MethodSignature> methods = genType.getMethodDefinitions();
- for (final MethodSignature method : methods) {
+ for (var method : genType.getMethodDefinitions()) {
switch (method.getName()) {
case Naming.KEY_AWARE_KEY_NAME:
getSimpleListKeyMethodCount++;
listChildContainerMethodsCount = genType.getMethodDefinitions().size();
}
} else {
- final List<GeneratedProperty> properties = genTO.getProperties();
- final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();
- final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();
+ final var properties = genTO.getProperties();
+ final var hashProps = genTO.getHashCodeIdentifiers();
+ final var equalProps = genTO.getEqualsIdentifiers();
assertEquals("Unexpected key", 0, listKeyClassCount++);
assertEquals(1, properties.size());
@Test
public void testListCompositeKeyResolving() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+ final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
"/list-composite-key.yang"));
assertNotNull(genTypes);
int compositeKeyListKeyCount = 0;
int innerListKeyPropertyCount = 0;
- for (final GeneratedType type : genTypes) {
+ for (var type : genTypes) {
if (!(type instanceof GeneratedTransferObject genTO)) {
genTypesCount++;
} else if (genTO.getName().equals("CompositeKeyListKey")) {
compositeKeyListKeyCount++;
- final List<GeneratedProperty> properties = genTO.getProperties();
- for (final GeneratedProperty prop : properties) {
+ for (var prop : genTO.getProperties()) {
if (prop.getName().equals("key1") || prop.getName().equals("key2")) {
compositeKeyListKeyPropertyCount++;
}
}
genTOsCount++;
} else if (genTO.getName().equals("InnerListKey")) {
- final List<GeneratedProperty> properties = genTO.getProperties();
- innerListKeyPropertyCount = properties.size();
+ innerListKeyPropertyCount = genTO.getProperties().size();
genTOsCount++;
}
}
@Test
public void testGeneratedTypes() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+ final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
"/demo-topology.yang"));
assertNotNull(genTypes);
int genTypesCount = 0;
int genTOsCount = 0;
- for (final GeneratedType type : genTypes) {
+ for (var type : genTypes) {
if (type instanceof GeneratedTransferObject) {
genTOsCount++;
} else {
@Test
public void testAugmentRpcInput() {
- final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+ final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
"/augment-rpc-input.yang"));
- assertEquals(7, genTypes.size());
+ assertEquals(6, genTypes.size());
}
}
public void testRpcUsesAugment() {
final var types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource("/mdsal302.yang"));
assertNotNull(types);
- assertEquals(16, types.size());
+ assertEquals(15, types.size());
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import java.util.List;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.model.api.MethodSignature;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Mdsal500Test {
@Test
public void testAugmentedAction() {
- final List<GeneratedType> types = DefaultBindingGenerator.generateFor(
- YangParserTestUtils.parseYangResource("/mdsal500.yang"));
+ final var types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource("/mdsal500.yang"));
assertNotNull(types);
- assertEquals(5, types.size());
-
- final GeneratedType rpcService = types.get(4);
- assertEquals("Mdsal500Service", rpcService.getName());
- final List<MethodSignature> methods = rpcService.getMethodDefinitions();
- assertEquals(1, methods.size());
-
- final MethodSignature signature = methods.get(0);
- assertEquals("switch$", signature.getName());
+ assertEquals(4, types.size());
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import java.util.List;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
-import org.opendaylight.mdsal.binding.model.api.MethodSignature;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Mdsal552Test {
@Test
public void enumLeafrefTest() {
- final List<GeneratedType> types = DefaultBindingGenerator.generateFor(
- YangParserTestUtils.parseYangResource("/mdsal552.yang"));
+ final var types = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource("/mdsal552.yang"));
assertNotNull(types);
- assertEquals(6, types.size());
+ assertEquals(5, types.size());
- final GeneratedType baz = types.stream()
+ final var baz = types.stream()
.filter(type -> BAZ.equals(type.getIdentifier()))
.findFirst().orElseThrow();
- final MethodSignature bazGetRef = baz.getMethodDefinitions().stream()
+ final var bazGetRef = baz.getMethodDefinitions().stream()
.filter(method -> method.getName().equals("getRef"))
.findFirst().orElseThrow();
assertEquals(ENUMERATION, bazGetRef.getReturnType().getIdentifier());
- final GeneratedType input = types.stream()
+ final var input = types.stream()
.filter(type -> BAR_INPUT.equals(type.getIdentifier()))
.findFirst().orElseThrow();
- final MethodSignature inputGetRef = input.getMethodDefinitions().stream()
+ final var inputGetRef = input.getMethodDefinitions().stream()
.filter(method -> method.getName().equals("getRef"))
.findFirst().orElseThrow();
assertEquals(ENUMERATION, inputGetRef.getReturnType().getIdentifier());
final var generatedNames = DefaultBindingGenerator.generateFor(
YangParserTestUtils.parseYangResource("/mdsal666.yang")).stream().map(GeneratedType::getIdentifier)
.collect(Collectors.toUnmodifiableList());
- assertEquals(11, generatedNames.size());
+ assertEquals(10, generatedNames.size());
// 'rpc foo' ...
assertTrue(generatedNames.stream().anyMatch(FOO::equals));
import static org.junit.Assert.assertEquals;
-import java.util.Arrays;
+import java.util.List;
import org.junit.Test;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public void testServiceConflict() {
assertGeneratedNames("service-conflict.yang",
"org.opendaylight.yang.gen.v1.service.conflict.norev.ServiceConflictData",
- "org.opendaylight.yang.gen.v1.service.conflict.norev.ServiceConflictService$CO",
+ "org.opendaylight.yang.gen.v1.service.conflict.norev.ServiceConflictService",
"org.opendaylight.yang.gen.v1.service.conflict.norev.Bar",
"org.opendaylight.yang.gen.v1.service.conflict.norev.BarInput",
- "org.opendaylight.yang.gen.v1.service.conflict.norev.BarOutput",
- "org.opendaylight.yang.gen.v1.service.conflict.norev.ServiceConflictService");
+ "org.opendaylight.yang.gen.v1.service.conflict.norev.BarOutput");
}
@Test
"org.opendaylight.yang.gen.v1.io.conflict.norev.Foo$RPInput",
"org.opendaylight.yang.gen.v1.io.conflict.norev.Foo$RPOutput",
"org.opendaylight.yang.gen.v1.io.conflict.norev.FooInput",
- "org.opendaylight.yang.gen.v1.io.conflict.norev.FooOutput",
- "org.opendaylight.yang.gen.v1.io.conflict.norev.IoConflictService");
+ "org.opendaylight.yang.gen.v1.io.conflict.norev.FooOutput");
}
@Test
"org.opendaylight.yang.gen.v1.schema.conflict.norev.FooBar$RP",
"org.opendaylight.yang.gen.v1.schema.conflict.norev.FooBar$RPInput",
"org.opendaylight.yang.gen.v1.schema.conflict.norev.FooBar$RPOutput",
- "org.opendaylight.yang.gen.v1.schema.conflict.norev.SchemaConflictListener",
- "org.opendaylight.yang.gen.v1.schema.conflict.norev.SchemaConflictService");
+ "org.opendaylight.yang.gen.v1.schema.conflict.norev.SchemaConflictListener");
}
private static void assertGeneratedNames(final String yangFile, final String... fqcns) {
- assertEquals(Arrays.asList(fqcns),
+ assertEquals(List.of(fqcns),
DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource("/mdsal-810/" + yangFile))
.stream().map(type -> type.getIdentifier().toString()).toList());
}
import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.binding.RpcInput;
import org.opendaylight.yangtools.yang.binding.RpcOutput;
-import org.opendaylight.yangtools.yang.binding.RpcService;
import org.opendaylight.yangtools.yang.binding.ScalarTypeObject;
import org.opendaylight.yangtools.yang.binding.UnionTypeObject;
import org.opendaylight.yangtools.yang.binding.YangData;
public static final ConcreteType QNAME = typeForClass(QName.class);
public static final ConcreteType RPC_INPUT = typeForClass(RpcInput.class);
public static final ConcreteType RPC_OUTPUT = typeForClass(RpcOutput.class);
- @Deprecated(since = "11.0.0", forRemoval = true)
- public static final ConcreteType RPC_SERVICE = typeForClass(RpcService.class);
public static final ConcreteType SCALAR_TYPE_OBJECT = typeForClass(ScalarTypeObject.class);
public static final ConcreteType BITS_TYPE_OBJECT = typeForClass(BitsTypeObject.class);
public static final ConcreteType UNION_TYPE_OBJECT = typeForClass(UnionTypeObject.class);
import org.opendaylight.yangtools.yang.binding.KeyAware;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.binding.NotificationListener;
-import org.opendaylight.yangtools.yang.binding.RpcService;
public class BindingTypesTest {
@Test
assertEquals("INSTANCE_IDENTIFIER", typeForClass(InstanceIdentifier.class), BindingTypes.INSTANCE_IDENTIFIER);
assertEquals("NOTIFICATION_LISTENER", typeForClass(NotificationListener.class),
BindingTypes.NOTIFICATION_LISTENER);
- assertEquals("RPC_SERVICE", typeForClass(RpcService.class), BindingTypes.RPC_SERVICE);
}
@Test
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.util.List;
import org.junit.Test;
import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-import org.opendaylight.yangtools.yang.common.QName;
public class BindingReflectionsTest {
-
@Test
public void testBindingWithDummyObject() throws Exception {
- assertFalse("Should not be RpcType", BindingReflections.isRpcType(DataObject.class));
- assertTrue("Should be BindingClass", BindingReflections.isBindingClass(DataObject.class));
+ assertFalse(BindingReflections.isRpcType(DataObject.class));
+ assertTrue(BindingReflections.isBindingClass(DataObject.class));
}
- static final class TestImplementation implements Augmentation<TestImplementation>, RpcService {
- public static final QName QNAME = QName.create("test", "test");
-
- @SuppressWarnings("static-method")
- ListenableFuture<List<Object>> rpcMethodTest() {
- return null;
- }
-
+ static final class TestImplementation implements Augmentation<TestImplementation> {
@Override
public Class<TestImplementation> implementedInterface() {
return TestImplementation.class;
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.binding;
-
-/**
- * Marker interface for tagging generated YANG Modules.
- */
-@Deprecated(since = "11.0.0", forRemoval = true)
-public interface RpcService {
-
-}
return str.substring(0, 1).toLowerCase(Locale.ENGLISH) + str.substring(1);
}
- /**
- * Returns the {@link String} {@code s} with a '$' character as suffix.
- *
- * @param qname RPC QName
- * @return The RPC method name as determined by considering the localname against the JLS.
- * @throws NullPointerException if {@code qname} is null
- */
- public static @NonNull String getRpcMethodName(final @NonNull QName qname) {
- final String methodName = getMethodName(qname);
- return JAVA_RESERVED_WORDS.contains(methodName) ? methodName + "$" : methodName;
- }
-
/**
* Returns root package name for supplied package name.
*