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=a398abc75a3254c3160ae685f9d829920f726f6c;hp=9edea0c2fd59fb9f50b94551fbf5574a174a2a07;hb=b23703bef6c3aaafe2dc83608a03b738ad42f945;hpb=a63e71e64b3aa624290790fc245e97e845f29798 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 9edea0c2fd..a398abc75a 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 @@ -91,6 +91,7 @@ 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; +import com.google.common.util.concurrent.ListenableFuture; public class BindingIndependentConnector implements // RuntimeDataProvider, // @@ -324,7 +325,7 @@ public class BindingIndependentConnector implements // } public void startRpcForwarding() { - if (baRpcRegistry != null && biRpcRegistry != null && baRpcRegistry instanceof RouteChangePublisher) { + if (biRpcRegistry != null && baRpcRegistry instanceof RouteChangePublisher) { checkState(!rpcForwarding, "Connector is already forwarding RPCs"); domToBindingRpcManager = baRpcRegistry.registerRouteChangeListener(new DomToBindingRpcForwardingManager()); if (baRpcRegistry instanceof RpcProviderRegistryImpl) { @@ -699,8 +700,9 @@ public class BindingIndependentConnector implements // } } + @Override - public RpcResult invokeRpc(final QName rpc, final CompositeNode domInput) { + public ListenableFuture> invokeRpc(final QName rpc, final CompositeNode domInput) { checkArgument(rpc != null); checkArgument(domInput != null); @@ -709,10 +711,11 @@ public class BindingIndependentConnector implements // RpcService rpcService = baRpcRegistry.getRpcService(rpcType); checkState(rpcService != null); CompositeNode domUnwrappedInput = domInput.getFirstCompositeByName(QName.create(rpc, "input")); + try { - return resolveInvocationStrategy(rpc).invokeOn(rpcService, domUnwrappedInput); + return Futures.immediateFuture(resolveInvocationStrategy(rpc).invokeOn(rpcService, domUnwrappedInput)); } catch (Exception e) { - throw new IllegalStateException(e); + return Futures.immediateFailedFuture(e); } } @@ -813,21 +816,25 @@ public class BindingIndependentConnector implements // } @Override - public Future> forwardToDomBroker(final DataObject input) { - if(biRpcRegistry != null) { - CompositeNode xml = mappingService.toDataDom(input); - CompositeNode wrappedXml = ImmutableCompositeNode.create(rpc, ImmutableList.> of(xml)); - RpcResult result = biRpcRegistry.invokeRpc(rpc, wrappedXml); - Object baResultValue = null; - if (result.getResult() != null) { - baResultValue = mappingService.dataObjectFromDataDom(outputClass.get(), result.getResult()); - } - RpcResult baResult = Rpcs.getRpcResult(result.isSuccessful(), baResultValue, result.getErrors()); - return Futures.> immediateFuture(baResult); + public ListenableFuture> forwardToDomBroker(final DataObject input) { + if(biRpcRegistry == null) { + return Futures.> immediateFuture(Rpcs.getRpcResult(false)); } - 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(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 NoInputNoOutputInvocationStrategy extends RpcInvocationStrategy { @@ -876,18 +883,21 @@ public class BindingIndependentConnector implements // } @Override - public Future> forwardToDomBroker(final DataObject input) { - if(biRpcRegistry != null) { - CompositeNode xml = mappingService.toDataDom(input); - CompositeNode wrappedXml = ImmutableCompositeNode.create(rpc,ImmutableList.>of(xml)); - RpcResult result = biRpcRegistry.invokeRpc(rpc, wrappedXml); - Object baResultValue = null; - RpcResult baResult = Rpcs.getRpcResult(result.isSuccessful(), null, result.getErrors()); - return Futures.>immediateFuture(baResult); + public ListenableFuture> forwardToDomBroker(final DataObject input) { + if(biRpcRegistry == null) { + return Futures.> immediateFuture(Rpcs.getRpcResult(false)); } - 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(RpcResult input) { + return Rpcs.getRpcResult(input.isSuccessful(), null, input.getErrors()); + } + }); + } } public boolean isRpcForwarding() {