Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.grpc.api; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 20 | |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 21 | import java.util.concurrent.CompletableFuture; |
| 22 | |
| 23 | /** |
| 24 | * Abstraction of a gRPC client. |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 25 | */ |
| 26 | @Beta |
| 27 | public interface GrpcClient { |
| 28 | |
| 29 | /** |
| 30 | * Shutdowns the client by terminating any active RPC. |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 31 | */ |
Carmelo Cascone | ab5d41e | 2019-03-06 18:02:34 -0800 | [diff] [blame^] | 32 | void shutdown(); |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * This method provides a coarse modelling of gRPC channel {@link |
| 36 | * io.grpc.ConnectivityState}. The implementation does not make any attempt |
| 37 | * at probing the server by sending messages over the network, as such it |
| 38 | * does not block execution. It returns true if this client is expected to |
| 39 | * communicate with the server successfully. In other words, if any RPC |
| 40 | * would be executed immediately after this method is called and returns |
| 41 | * true, then it is expected, but NOT guaranteed, for that RPC message to |
| 42 | * reach the server and be processed. If false, it means the channel is in a |
| 43 | * failure state and communication with the server is unlikely to happen |
| 44 | * soon. |
| 45 | * |
| 46 | * @return true if server is deemed reachable, false otherwise |
| 47 | */ |
| 48 | boolean isServerReachable(); |
| 49 | |
| 50 | /** |
| 51 | * Similar to {@link #isServerReachable()}, but might involve sending |
| 52 | * packets over the network. This checks whether the specific gRPC |
| 53 | * service(s) required by this client is available or not on the server. |
| 54 | * |
| 55 | * @return completable future eventually true if the gRPC service(s) on the |
| 56 | * server was available during the probe; false otherwise |
| 57 | */ |
| 58 | CompletableFuture<Boolean> probeService(); |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 59 | } |