import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final class LazyDOMRpcResultFuture extends AbstractFuture<DOMRpcResult> implements BindingRpcFutureAware {
private static final ExceptionMapper<DOMRpcException> DOM_RPC_EX_MAPPER = new ExceptionMapper<>("rpc",
private LazyDOMRpcResultFuture(final ListenableFuture<RpcResult<?>> delegate,
final BindingNormalizedNodeSerializer codec) {
- this.bindingFuture = requireNonNull(delegate, "delegate");
+ bindingFuture = requireNonNull(delegate, "delegate");
this.codec = requireNonNull(codec, "codec");
}
private DOMRpcResult transform(final RpcResult<?> input) {
if (input.isSuccessful()) {
- final Object inputData = input.getResult();
- if (inputData instanceof DataContainer) {
- return new DefaultDOMRpcResult(codec.toNormalizedNodeRpcData((DataContainer) inputData));
- }
-
- return new DefaultDOMRpcResult((NormalizedNode) null);
+ final var value = input.getResult() instanceof DataContainer container
+ ? codec.toNormalizedNodeRpcData(container) : null;
+ return new DefaultDOMRpcResult(value);
}
return new DefaultDOMRpcResult(input.getErrors());
}
private ListenableFuture<RpcResult<?>> transformFuture(final ListenableFuture<? extends DOMRpcResult> domFuture,
final BindingNormalizedNodeSerializer resultCodec) {
return Futures.transform(domFuture, input -> {
- final NormalizedNode domData = input.getResult();
+ final NormalizedNode domData = input.value();
final DataObject bindingResult;
if (domData != null) {
bindingResult = resultCodec.fromNormalizedNodeRpcData(outputPath, (ContainerNode) domData);
bindingResult = null;
}
- return RpcResultUtil.rpcResultFromDOM(input.getErrors(), bindingResult);
+ return RpcResultUtil.rpcResultFromDOM(input.errors(), bindingResult);
}, MoreExecutors.directExecutor());
}
}
ContainerNode biKnockKnockInput = toDOMKnockKnockInput(baKnockKnockInput);
DOMRpcResult domResult = biRpcService.invokeRpc(KNOCK_KNOCK_QNAME, biKnockKnockInput).get(5, TimeUnit.SECONDS);
assertNotNull(domResult);
- assertNotNull(domResult.getResult());
+ assertNotNull(domResult.value());
assertTrue("Binding KnockKnock service was not invoked",
knockRpcImpl.getReceivedKnocks().containsKey(BA_NODE_ID));
assertEquals(baKnockKnockInput, knockRpcImpl.getReceivedKnocks().get(BA_NODE_ID).iterator().next());
OpendaylightKnockKnockRpcServiceImpl setKnockKnockResult(
final ListenableFuture<RpcResult<KnockKnockOutput>> kkOutput) {
- this.knockKnockResult = kkOutput;
+ knockKnockResult = kkOutput;
return this;
}
ContainerNode biSwitchInput = toDOMSwitchInput(baSwitchInput);
DOMRpcResult domResult = biRpcService.invokeRpc(SWITCH_QNAME, biSwitchInput).get(5, TimeUnit.SECONDS);
assertNotNull(domResult);
- assertNotNull(domResult.getResult());
+ assertNotNull(domResult.value());
assertTrue("Binding KnockKnock service was not invoked",
switchRpcImpl.getReceivedSwitch().containsKey(FOO));
assertEquals(baSwitchInput, switchRpcImpl.getReceivedSwitch().get(FOO).iterator().next());
private final Multimap<String, SwitchInput> receivedSwitch = HashMultimap.create();
Mdsal500ServiceImpl setSwitchResult(final ListenableFuture<RpcResult<SwitchOutput>> switchOutput) {
- this.switchResult = switchOutput;
+ switchResult = switchOutput;
return this;
}
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
/**
* Interface defining a result of an RPC call.
@NonNullByDefault
public interface DOMRpcResult {
/**
- * Returns a set of errors and warnings which occurred during processing
- * the call.
+ * Returns a set of errors and warnings which occurred during processing the call.
*
- * @return a Collection of {@link RpcError}, guaranteed to be non-null. In case
- * no errors are reported, an empty collection is returned.
+ * @return a Collection of {@link RpcError}, guaranteed to be non-null. In case no errors are reported, an empty
+ * collection is returned.
+ * @deprecated Use {@link #errors()} instead.
*/
- Collection<? extends RpcError> getErrors();
+ @Deprecated(since = "11.0.0", forRemoval = true)
+ default Collection<? extends RpcError> getErrors() {
+ return errors();
+ }
+
+ /**
+ * Returns a set of errors and warnings which occurred during processing the call.
+ *
+ * @return a Collection of {@link RpcError}, guaranteed to be non-null. In case no errors are reported, an empty
+ * collection is returned.
+ */
+ Collection<? extends RpcError> errors();
/**
* Returns the value result of the call or null if no result is available.
*
- * @return Invocation result, null if the operation has not produced a result. This might
- * be the case if the operation does not produce a result, or if it failed.
+ * @return Invocation result, {@code null} if the operation has not produced a result. This might be the case if the
+ * operation does not produce a result, or if it failed.
+ * @deprecated Use {@link #value()} instead.
+ */
+ @Deprecated(since = "11.0.0", forRemoval = true)
+ default @Nullable ContainerNode getResult() {
+ return value();
+ }
+
+ /**
+ * Returns the value result of the call or {code null} if no result is available.
+ *
+ * @return Invocation result, {@code null} if the operation has not produced a result. This might be the case if the
+ * operation does not produce a result, or if it failed.
*/
- @Nullable NormalizedNode getResult();
+ @Nullable ContainerNode value();
}
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
/**
* Utility class implementing {@link DefaultDOMRpcResult}.
private static final long serialVersionUID = 1L;
@SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Interfaces do not specify Serializable")
- private final @Nullable NormalizedNode result;
+ private final @Nullable ContainerNode result;
// FIXME: a plain Collection is bad for equality
private final Collection<? extends RpcError> errors;
- public DefaultDOMRpcResult(final NormalizedNode result, final RpcError... errors) {
- this(result, List.of(errors));
+ public DefaultDOMRpcResult(final ContainerNode value, final RpcError... errors) {
+ this(value, List.of(errors));
}
public DefaultDOMRpcResult(final RpcError... errors) {
this(null, List.of(errors));
}
- public DefaultDOMRpcResult(final @Nullable NormalizedNode result) {
+ public DefaultDOMRpcResult(final @Nullable ContainerNode result) {
this(result, List.of());
}
- public DefaultDOMRpcResult(final @Nullable NormalizedNode result,
- final Collection<? extends RpcError> errors) {
- this.result = result;
+ public DefaultDOMRpcResult(final @Nullable ContainerNode value, final Collection<? extends RpcError> errors) {
+ result = value;
this.errors = requireNonNull(errors);
}
}
@Override
- public Collection<? extends RpcError> getErrors() {
+ public Collection<? extends RpcError> errors() {
return errors;
}
@Override
- public @Nullable NormalizedNode getResult() {
+ public @Nullable ContainerNode value() {
return result;
}
import com.google.common.collect.ForwardingObject;
import java.util.Collection;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
/**
* Utility class which implements {@link DOMRpcResult} by forwarding all methods
* to a backing instance.
*/
-@NonNullByDefault
public abstract class ForwardingDOMRpcResult extends ForwardingObject implements DOMRpcResult {
@Override
- protected abstract DOMRpcResult delegate();
+ protected abstract @NonNull DOMRpcResult delegate();
@Override
- public Collection<? extends RpcError> getErrors() {
- return delegate().getErrors();
+ public Collection<? extends RpcError> errors() {
+ return delegate().errors();
}
@Override
- public @Nullable NormalizedNode getResult() {
- return delegate().getResult();
+ public ContainerNode value() {
+ return delegate().value();
}
}
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-import java.util.Collections;
+import java.util.List;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
public class DefaultDOMRpcResultTest {
-
@Test
- public void basicTest() throws Exception {
+ public void basicTest() {
RpcError rpcError = mock(RpcError.class);
- NormalizedNode normalizedNode = mock(NormalizedNode.class);
+ ContainerNode normalizedNode = mock(ContainerNode.class);
DefaultDOMRpcResult defaultDOMRpcResult = new DefaultDOMRpcResult(normalizedNode, rpcError);
- assertEquals(normalizedNode, defaultDOMRpcResult.getResult());
- assertTrue(defaultDOMRpcResult.getErrors().contains(rpcError));
- assertTrue(new DefaultDOMRpcResult(normalizedNode).getErrors().isEmpty());
- assertTrue(new DefaultDOMRpcResult().getErrors().isEmpty());
- assertTrue(new DefaultDOMRpcResult(Collections.emptyList()).getErrors().isEmpty());
+ assertEquals(normalizedNode, defaultDOMRpcResult.value());
+ assertTrue(defaultDOMRpcResult.errors().contains(rpcError));
+ assertTrue(new DefaultDOMRpcResult(normalizedNode).errors().isEmpty());
+ assertTrue(new DefaultDOMRpcResult().errors().isEmpty());
+ assertTrue(new DefaultDOMRpcResult(List.of()).errors().isEmpty());
assertEquals(defaultDOMRpcResult.hashCode(), new DefaultDOMRpcResult(normalizedNode, rpcError).hashCode());
assertTrue(new DefaultDOMRpcResult(normalizedNode, rpcError).equals(defaultDOMRpcResult));
assertTrue(defaultDOMRpcResult.equals(defaultDOMRpcResult));
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class ForwardingDOMRpcResultTest extends ForwardingDOMRpcResult {
@Mock(name = "domRpcResult")
- public DOMRpcResult domRpcResult;
+ public DOMRpcResult delegate;
@Test
public void basicTest() throws Exception {
- doReturn(null).when(domRpcResult).getErrors();
- this.getErrors();
- verify(domRpcResult).getErrors();
+ doReturn(null).when(delegate).errors();
+ errors();
+ verify(delegate).errors();
- doReturn(null).when(domRpcResult).getResult();
- this.getResult();
- verify(domRpcResult).getResult();
+ doReturn(null).when(delegate).value();
+ value();
+ verify(delegate).value();
}
@Override
protected DOMRpcResult delegate() {
- return domRpcResult;
+ return delegate;
}
}
\ No newline at end of file