import com.google.common.annotations.Beta;
import java.util.EventListener;
import java.util.Set;
-import java.util.concurrent.Executor;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.common.QName;
*
* <p>
* Users should note that using a listener does not necessarily mean that
- * {@link DOMOperationService#invokeRpc(QName, ContainerNode, DOMOperationCallback, Executor)} and
+ * {@link DOMOperationService#invokeRpc(QName, ContainerNode)} and
* {@link DOMOperationService#invokeAction(SchemaPath, DOMDataTreeIdentifier, ContainerNode)} will not report
* a failure due to {@link DOMOperationNotAvailableException} and need to be ready to handle it.
*
+++ /dev/null
-/*
- * Copyright (c) 2018 Pantheon Technologies, 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.dom.api;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.util.concurrent.SettableFuture;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.Consumer;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.concepts.CheckedValue;
-
-/**
- * A callback to be executed when an operation invocation completes. This interface is modeled as a {@link Consumer}
- * of {@link CheckedValue}, which needs to be unwrapped.
- *
- * <p>
- * Alternatively, you can use {@link #of(Consumer, Consumer)} utility method, which provides the equivalent
- * dispatch with a nicer interface:
- * <code>
- * DOMOperationCallback callback = DOMOperationCallback.of((success) -> {
- * // ... code to handle success ...
- * }, (failure) -> {
- * // ... code to handle failure ...
- * });
- * </code>
- *
- * <p>
- * Finally, you can create a bridging {@link DOMOperationCallback} through either
- * {@link #completingFuture(SettableFuture)} or {@link #completingFuture(CompletableFuture)}.
- *
- * @author Robert Varga
- */
-@Beta
-@NonNullByDefault
-@FunctionalInterface
-public interface DOMOperationCallback extends Consumer<CheckedValue<DOMOperationResult, DOMOperationException>> {
- /**
- * Create a DOMOperationCallback composed of two separate consumers, one for success and one for failure.
- *
- * @param onSuccess Callback to invoke on success
- * @param onFailure Callback to invoke on failure
- * @return A {@link DOMOperationCallback} which delegates to provided methods
- * @throws NullPointerException if any of the arguments is null
- */
- static DOMOperationCallback of(final Consumer<DOMOperationResult> onSuccess,
- final Consumer<DOMOperationException> onFailure) {
- requireNonNull(onSuccess);
- requireNonNull(onFailure);
- return result -> {
- if (result.isPresent()) {
- onSuccess.accept(result.get());
- } else {
- onFailure.accept(result.getException());
- }
- };
- }
-
- /**
- * Create a {@link DOMOperationCallback} which completes the specified future.
- *
- * @param future {@link CompletableFuture} to complete
- * @return A {@link DOMOperationCallback}
- * @throws NullPointerException if any of the arguments is null
- */
- static DOMOperationCallback completingFuture(final CompletableFuture<DOMOperationResult> future) {
- requireNonNull(future);
- return of(future::complete, future::completeExceptionally);
- }
-
- /**
- * Create a {@link DOMOperationCallback} which completes the specified future.
- *
- * @param future {@link SettableFuture} to complete
- * @return A {@link DOMOperationCallback}
- * @throws NullPointerException if any of the arguments is null
- */
- static DOMOperationCallback completingFuture(final SettableFuture<DOMOperationResult> future) {
- requireNonNull(future);
- return of(future::set, future::setException);
- }
-}
package org.opendaylight.mdsal.dom.api;
import com.google.common.annotations.Beta;
-import java.util.concurrent.Executor;
+import com.google.common.util.concurrent.FluentFuture;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
* top of the conceptual {@link StoreTreeNode}.
* @param path {@link DOMDataTreeIdentifier} of parent data node which action attached to.
* @param input Input arguments
- * @param callback Callback to invoke with the invocation result
- * @param callbackExecutor Executor to use for executing the callback
+ * @return A FluentFuture which completes with the result of invocation
* @throws NullPointerException if any of the arguments is null
*/
- void invokeAction(SchemaPath type, DOMDataTreeIdentifier path, ContainerNode input,
- DOMOperationCallback callback, Executor callbackExecutor);
+ FluentFuture<DOMOperationResult> invokeAction(SchemaPath type, DOMDataTreeIdentifier path, ContainerNode input);
}
/**
*
* @param type QName of the RPC to be invoked
* @param input Input arguments
- * @param callback Callback to invoke with the invocation result
- * @param callbackExecutor Executor to use for executing the callback
+ * @return A FluentFuture which completes with the result of invocation
* @throws NullPointerException if any of the arguments is null
*/
- void invokeRpc(QName type, ContainerNode input, DOMOperationCallback callback, Executor callbackExecutor);
+ FluentFuture<DOMOperationResult> invokeRpc(QName type, ContainerNode input);
}
/**
*/
package org.opendaylight.mdsal.dom.api;
-import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
-
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.FluentFuture;
-import com.google.common.util.concurrent.SettableFuture;
-import java.util.concurrent.Executor;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@Beta
@NonNullByDefault
public interface DOMOperationService extends DOMExtensibleService<DOMOperationService, DOMOperationServiceExtension> {
- /**
- * Initiate invocation of an RPC. This method is guaranteed to not block on any external resources.
- *
- * @param type QName of the RPC to be invoked
- * @param input Input arguments
- * @param callback Callback to invoke with the invocation result
- * @param callbackExecutor Executor to use for executing the callback
- * @throws NullPointerException if any of the arguments is null
- */
- void invokeRpc(QName type, ContainerNode input, DOMOperationCallback callback,
- Executor callbackExecutor);
-
/**
* Initiate invocation of an RPC. This method is guaranteed to not block on any external resources.
*
* @return A FluentFuture which completes with the result of invocation
* @throws NullPointerException if any of the arguments is null
*/
- default FluentFuture<DOMOperationResult> invokeRpc(final QName type, final ContainerNode input) {
- final SettableFuture<DOMOperationResult> future = SettableFuture.create();
- invokeRpc(type, input, DOMOperationCallback.completingFuture(future), directExecutor());
- return future;
- }
-
- /**
- * Initiate invocation of an Action. This method is guaranteed to not block on any external resources.
- *
- * @param type SchemaPath of the action to be invoked. This path refers to an effective action instantiated on top
- * of the conceptual {@link StoreTreeNode}.
- * @param path {@link DOMDataTreeIdentifier} of parent data node which action attached to.
- * @param input Input argument
- * @param callback Callback to invoke with the invocation result
- * @param callbackExecutor Executor to use for executing the callback
- * @throws NullPointerException if any of the arguments is null
- */
- void invokeAction(SchemaPath type, DOMDataTreeIdentifier path, ContainerNode input, DOMOperationCallback callback,
- Executor callbackExecutor);
+ FluentFuture<DOMOperationResult> invokeRpc(QName type, ContainerNode input);
/**
* Initiate invocation of an Action. This method is guaranteed to not block on any external resources.
* @return A FluentFuture which completes with the result of invocation
* @throws NullPointerException if any of the arguments is null
*/
- default FluentFuture<DOMOperationResult> invokeAction(final SchemaPath type, final DOMDataTreeIdentifier path,
- final ContainerNode input) {
- final SettableFuture<DOMOperationResult> future = SettableFuture.create();
- invokeAction(type, path, input, DOMOperationCallback.completingFuture(future), directExecutor());
- return future;
- }
+ FluentFuture<DOMOperationResult> invokeAction(SchemaPath type, DOMDataTreeIdentifier path, ContainerNode input);
}
--- /dev/null
+/*
+ * Copyright (c) 2018 Pantheon Technologies, 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.dom.spi;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.Optional;
+import javax.annotation.concurrent.ThreadSafe;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.dom.api.DOMOperationResult;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+@Beta
+@NonNullByDefault
+@ThreadSafe
+public final class SimpleDOMOperationResult implements DOMOperationResult, Immutable {
+ private final Collection<RpcError> errors;
+ private final @Nullable ContainerNode output;
+
+ private SimpleDOMOperationResult(final Collection<RpcError> errors, final @Nullable ContainerNode output) {
+ this.errors = ImmutableList.copyOf(errors);
+ this.output = null;
+ }
+
+ public SimpleDOMOperationResult(final Collection<RpcError> errors) {
+ this(errors, null);
+ }
+
+ public SimpleDOMOperationResult(final ContainerNode output, final Collection<RpcError> errors) {
+ this(errors, requireNonNull(output));
+ }
+
+ @Override
+ public Collection<RpcError> getErrors() {
+ return errors;
+ }
+
+ @Override
+ public Optional<ContainerNode> getOutput() {
+ return (Optional) Optional.<@Nullable ContainerNode>ofNullable(output);
+ }
+
+ @Override
+ public String toString() {
+ final ToStringHelper helper = MoreObjects.toStringHelper(this).omitNullValues().add("output", output);
+ if (!errors.isEmpty()) {
+ helper.add("errors", errors);
+ }
+ return helper.toString();
+ }
+}
\ No newline at end of file