import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
import org.opendaylight.mdsal.binding.dom.codec.spi.ForwardingBindingDOMCodecServices;
import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
-import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
import org.slf4j.Logger;
return Map.entry(stack, lastNamespace);
}
- // FIXME: This should be probably part of Binding Runtime context and RpcServices perhaps should have their own
- // RuntimeType
- ImmutableBiMap<Method, RpcRuntimeType> getRpcMethodToSchema(final Class<? extends RpcService> key) {
- final var runtimeContext = getRuntimeContext();
- final var types = runtimeContext.getTypes();
- final var qnameModule = BindingReflections.getQNameModule(key);
-
- // 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 " + key));
- return module.streamEffectiveSubstatements(RpcEffectiveStatement.class)
- .map(rpc -> {
- final var rpcName = rpc.argument();
- final var inputClz = runtimeContext.getRpcInput(rpcName);
- final var methodName = BindingMapping.getRpcMethodName(rpcName);
-
- final Method method;
- try {
- method = key.getMethod(methodName, inputClz);
- } catch (NoSuchMethodException e) {
- throw new IllegalStateException("Cannot find RPC method for " + rpc, e);
- }
-
- final var type = types.schemaTreeChild(rpcName);
- if (!(type instanceof RpcRuntimeType rpcType)) {
- throw new IllegalStateException("Unexpected run-time type " + type + " for " + rpcName);
- }
- return Map.entry(method, rpcType);
- })
- .collect(ImmutableBiMap.toImmutableBiMap(Entry::getKey, Entry::getValue));
- }
-
// FIXME: This should be probably part of Binding Runtime context
ImmutableBiMap<Method, QName> getRpcMethodToQName(final Class<? extends RpcService> key) {
final Module module = getModule(key);
import static java.util.Objects.requireNonNull;
+import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.binding.runtime.api.RpcRuntimeType;
+import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
+import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
class RpcServiceAdapter implements InvocationHandler {
private final ImmutableMap<Method, RpcInvocationStrategy> rpcNames;
this.type = requireNonNull(type);
this.adapterContext = requireNonNull(adapterContext);
delegate = requireNonNull(domService);
+ facade = (RpcService) Proxy.newProxyInstance(type.getClassLoader(), new Class[] {type}, this);
- final var methods = adapterContext.currentSerializer().getRpcMethodToSchema(type);
+ final var methods = getRpcMethodToSchema(adapterContext.currentSerializer(), type);
final var rpcBuilder = ImmutableMap.<Method, RpcInvocationStrategy>builderWithExpectedSize(methods.size());
for (var entry : methods.entrySet()) {
final var method = entry.getKey();
rpcBuilder.put(method, RpcInvocationStrategy.of(this, method, entry.getValue()));
}
rpcNames = rpcBuilder.build();
- facade = (RpcService) Proxy.newProxyInstance(type.getClassLoader(), new Class[] {type}, this);
}
final @NonNull CurrentAdapterSerializer currentSerializer() {
throw new UnsupportedOperationException("Method " + method.toString() + "is unsupported.");
}
+
+ // FIXME: This should be probably part of BindingRuntimeContext and RpcServices perhaps should have their own
+ // RuntimeType
+ private static ImmutableBiMap<Method, RpcRuntimeType> getRpcMethodToSchema(
+ final CurrentAdapterSerializer serializer, final Class<? extends RpcService> key) {
+ final var runtimeContext = serializer.getRuntimeContext();
+ final var types = runtimeContext.getTypes();
+ final var qnameModule = BindingReflections.getQNameModule(key);
+
+ // 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 " + key));
+ return module.streamEffectiveSubstatements(RpcEffectiveStatement.class)
+ .map(rpc -> {
+ final var rpcName = rpc.argument();
+ final var inputClz = runtimeContext.getRpcInput(rpcName);
+ final var methodName = BindingMapping.getRpcMethodName(rpcName);
+
+ final Method method;
+ try {
+ method = key.getMethod(methodName, inputClz);
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Cannot find RPC method for " + rpc, e);
+ }
+
+ final var type = types.schemaTreeChild(rpcName);
+ if (!(type instanceof RpcRuntimeType rpcType)) {
+ throw new IllegalStateException("Unexpected run-time type " + type + " for " + rpcName);
+ }
+ return Map.entry(method, rpcType);
+ })
+ .collect(ImmutableBiMap.toImmutableBiMap(Entry::getKey, Entry::getValue));
+ }
}