X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fimpl%2Fconnect%2Fdom%2FBindingIndependentConnector.java;h=5bbebe6f1b00544021bb64d5cdf0ea4bf77c82a5;hp=2b40437d6446a9cce652b8245c82c3dc2342e8f9;hb=a31a4448ea6665317f4af41ae26d804829418c04;hpb=8eec36aeacef01fbe24d17824120bd2f5d201db2 diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentConnector.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentConnector.java index 2b40437d64..5bbebe6f1b 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentConnector.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentConnector.java @@ -77,8 +77,6 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode; import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService; import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException; import org.slf4j.Logger; @@ -87,7 +85,6 @@ import org.slf4j.LoggerFactory; import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.common.util.concurrent.Futures; @@ -736,224 +733,13 @@ public class BindingIndependentConnector implements // } } checkState(targetMethod != null, "Rpc method not found"); - Optional> outputClass = BindingReflections.resolveRpcOutputClass(targetMethod); - Optional> inputClass = BindingReflections - .resolveRpcInputClass(targetMethod); - - RpcInvocationStrategy strategy = null; - if (outputClass.isPresent()) { - if (inputClass.isPresent()) { - strategy = new DefaultInvocationStrategy(rpc, targetMethod, outputClass.get(), inputClass - .get()); - } else { - strategy = new NoInputInvocationStrategy(rpc, targetMethod, outputClass.get()); - } - } else if (inputClass.isPresent()) { - strategy = new NoOutputInvocationStrategy(rpc, targetMethod, inputClass.get()); - } else { - strategy = new NoInputNoOutputInvocationStrategy(rpc, targetMethod); - } - return strategy; + return new RpcInvocationStrategy(rpc,targetMethod, mappingService, biRpcRegistry); } }); } } - private abstract class RpcInvocationStrategy { - - protected final Method targetMethod; - protected final QName rpc; - - public RpcInvocationStrategy(final QName rpc, final Method targetMethod) { - this.targetMethod = targetMethod; - this.rpc = rpc; - } - - public abstract Future> forwardToDomBroker(DataObject input); - - public abstract RpcResult uncheckedInvoke(RpcService rpcService, CompositeNode domInput) - throws Exception; - - public RpcResult invokeOn(final RpcService rpcService, final CompositeNode domInput) - throws Exception { - return uncheckedInvoke(rpcService, domInput); - } - } - - private class DefaultInvocationStrategy extends RpcInvocationStrategy { - - @SuppressWarnings("rawtypes") - private final WeakReference inputClass; - - @SuppressWarnings("rawtypes") - private final WeakReference outputClass; - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public DefaultInvocationStrategy(final QName rpc, final Method targetMethod, final Class outputClass, - final Class inputClass) { - super(rpc, targetMethod); - this.outputClass = new WeakReference(outputClass); - this.inputClass = new WeakReference(inputClass); - } - - @SuppressWarnings("unchecked") - @Override - public RpcResult uncheckedInvoke(final RpcService rpcService, final CompositeNode domInput) - throws Exception { - DataContainer bindingInput = mappingService.dataObjectFromDataDom(inputClass.get(), domInput); - Future> futureResult = (Future>) targetMethod.invoke(rpcService, bindingInput); - if (futureResult == null) { - return Rpcs.getRpcResult(false); - } - RpcResult bindingResult = futureResult.get(); - final Object resultObj = bindingResult.getResult(); - if (resultObj instanceof DataObject) { - final CompositeNode output = mappingService.toDataDom((DataObject) resultObj); - return Rpcs.getRpcResult(true, output, Collections. emptySet()); - } - return Rpcs.getRpcResult(true); - } - - @Override - public ListenableFuture> forwardToDomBroker(final DataObject input) { - if (biRpcRegistry == null) { - return Futures.> immediateFuture(Rpcs.getRpcResult(false)); - } - - CompositeNode xml = mappingService.toDataDom(input); - CompositeNode wrappedXml = ImmutableCompositeNode.create(rpc, ImmutableList.> of(xml)); - - return Futures.transform(biRpcRegistry.invokeRpc(rpc, wrappedXml), - new Function, RpcResult>() { - @Override - public RpcResult apply(final RpcResult input) { - Object baResultValue = null; - if (input.getResult() != null) { - baResultValue = mappingService.dataObjectFromDataDom(outputClass.get(), - input.getResult()); - } - return Rpcs.getRpcResult(input.isSuccessful(), baResultValue, input.getErrors()); - } - }); - } - } - - private class NoInputInvocationStrategy extends RpcInvocationStrategy { - - @SuppressWarnings("rawtypes") - private final WeakReference outputClass; - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public NoInputInvocationStrategy(final QName rpc, final Method targetMethod, final Class outputClass) { - super(rpc, targetMethod); - this.outputClass = new WeakReference(outputClass); - } - - @SuppressWarnings("unchecked") - @Override - public RpcResult uncheckedInvoke(final RpcService rpcService, final CompositeNode domInput) - throws Exception { - Future> futureResult = (Future>) targetMethod.invoke(rpcService); - if (futureResult == null) { - return Rpcs.getRpcResult(false); - } - RpcResult bindingResult = futureResult.get(); - final Object resultObj = bindingResult.getResult(); - if (resultObj instanceof DataObject) { - final CompositeNode output = mappingService.toDataDom((DataObject) resultObj); - return Rpcs.getRpcResult(true, output, Collections. emptySet()); - } - return Rpcs.getRpcResult(true); - } - - @Override - public Future> forwardToDomBroker(final DataObject input) { - if (biRpcRegistry != null) { - CompositeNode xml = mappingService.toDataDom(input); - CompositeNode wrappedXml = ImmutableCompositeNode.create(rpc, ImmutableList.> of(xml)); - return Futures.transform(biRpcRegistry.invokeRpc(rpc, wrappedXml), - new Function, RpcResult>() { - @Override - public RpcResult apply(final RpcResult input) { - Object baResultValue = null; - if (input.getResult() != null) { - baResultValue = mappingService.dataObjectFromDataDom(outputClass.get(), - input.getResult()); - } - return Rpcs.getRpcResult(input.isSuccessful(), baResultValue, input.getErrors()); - } - }); - } else { - return Futures.> immediateFuture(Rpcs.getRpcResult(false)); - } - } - } - - private class NoInputNoOutputInvocationStrategy extends RpcInvocationStrategy { - - public NoInputNoOutputInvocationStrategy(final QName rpc, final Method targetMethod) { - super(rpc, targetMethod); - } - - @Override - public RpcResult uncheckedInvoke(final RpcService rpcService, final CompositeNode domInput) - throws Exception { - @SuppressWarnings("unchecked") - Future> result = (Future>) targetMethod.invoke(rpcService); - RpcResult bindingResult = result.get(); - return Rpcs.getRpcResult(bindingResult.isSuccessful(), bindingResult.getErrors()); - } - - @Override - public Future> forwardToDomBroker(final DataObject input) { - return Futures.immediateFuture(null); - } - } - - private class NoOutputInvocationStrategy extends RpcInvocationStrategy { - - @SuppressWarnings("rawtypes") - private final WeakReference inputClass; - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public NoOutputInvocationStrategy(final QName rpc, final Method targetMethod, - final Class inputClass) { - super(rpc, targetMethod); - this.inputClass = new WeakReference(inputClass); - } - - @Override - public RpcResult uncheckedInvoke(final RpcService rpcService, final CompositeNode domInput) - throws Exception { - DataContainer bindingInput = mappingService.dataObjectFromDataDom(inputClass.get(), domInput); - Future> result = (Future>) targetMethod.invoke(rpcService, bindingInput); - if (result == null) { - return Rpcs.getRpcResult(false); - } - RpcResult bindingResult = result.get(); - return Rpcs.getRpcResult(true); - } - - @Override - public ListenableFuture> forwardToDomBroker(final DataObject input) { - if (biRpcRegistry == null) { - return Futures.> immediateFuture(Rpcs.getRpcResult(false)); - } - - CompositeNode xml = mappingService.toDataDom(input); - CompositeNode wrappedXml = ImmutableCompositeNode.create(rpc, ImmutableList.> of(xml)); - - return Futures.transform(biRpcRegistry.invokeRpc(rpc, wrappedXml), - new Function, RpcResult>() { - @Override - public RpcResult apply(final RpcResult input) { - return Rpcs. getRpcResult(input.isSuccessful(), null, input.getErrors()); - } - }); - } - } - public boolean isRpcForwarding() { return rpcForwarding; }