304595e3084cf8f43813096baf618754b9dab5ad
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMRpcService.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.dom.api;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.yangtools.concepts.ListenerRegistration;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16
17 /**
18  * A {@link DOMService} which allows clients to invoke RPCs. The conceptual model of this service is that of a dynamic
19  * router, where the set of available RPC services can change dynamically. The service allows users to add a listener
20  * to track the process of RPCs becoming available.
21  */
22 // FIXME: once we have a DOMOperationService implementation, deprecate this interface
23 public interface DOMRpcService extends DOMService {
24     /**
25      * Initiate invocation of an RPC. This method is guaranteed to not block on any external
26      * resources.
27      *
28      * @param type SchemaPath of the RPC to be invoked
29      * @param input Input arguments, null if the RPC does not take any.
30      * @return A {@link ListenableFuture} which will return either a result structure, or report a subclass
31      *         of {@link DOMRpcException} reporting a transport error.
32      */
33     // FIXME: 5.0.0: do not allow null input
34     @NonNull ListenableFuture<DOMRpcResult> invokeRpc(@NonNull SchemaPath type, @Nullable NormalizedNode<?, ?> input);
35
36     /**
37      * Register a {@link DOMRpcAvailabilityListener} with this service to receive notifications
38      * about RPC implementations becoming (un)available. The listener will be invoked with the
39      * current implementations reported and will be kept uptodate as implementations come and go.
40      * Users should note that using a listener does not necessarily mean that
41      * {@link #invokeRpc(SchemaPath, NormalizedNode)} will not report a failure due to
42      * {@link DOMRpcImplementationNotAvailableException} and need to be ready to handle it.
43      * Implementations are encouraged to take reasonable precautions to prevent this scenario from
44      * occurring.
45      *
46      * @param listener {@link DOMRpcAvailabilityListener} instance to register
47      * @return A {@link ListenerRegistration} representing this registration. Performing a
48      *         {@link ListenerRegistration#close()} will cancel it. Returned object is guaranteed to be non-null.
49      */
50     @NonNull <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(@NonNull T listener);
51 }