blob: d529529197b5e58d8ea88ca632a882f9a2c03149 [file] [log] [blame]
Yi Tseng2a340f72018-11-02 16:52:47 -07001/*
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
17package org.onosproject.grpc.api;
18
19import com.google.common.annotations.Beta;
Carmelo Cascone3977ea42019-02-28 13:43:42 -080020
Yi Tseng2a340f72018-11-02 16:52:47 -070021import java.util.concurrent.CompletableFuture;
22
23/**
24 * Abstraction of a gRPC client.
Yi Tseng2a340f72018-11-02 16:52:47 -070025 */
26@Beta
27public interface GrpcClient {
28
29 /**
30 * Shutdowns the client by terminating any active RPC.
31 *
32 * @return a completable future to signal the completion of the shutdown
33 * procedure
34 */
35 CompletableFuture<Void> shutdown();
Carmelo Cascone3977ea42019-02-28 13:43:42 -080036
37 /**
38 * This method provides a coarse modelling of gRPC channel {@link
39 * io.grpc.ConnectivityState}. The implementation does not make any attempt
40 * at probing the server by sending messages over the network, as such it
41 * does not block execution. It returns true if this client is expected to
42 * communicate with the server successfully. In other words, if any RPC
43 * would be executed immediately after this method is called and returns
44 * true, then it is expected, but NOT guaranteed, for that RPC message to
45 * reach the server and be processed. If false, it means the channel is in a
46 * failure state and communication with the server is unlikely to happen
47 * soon.
48 *
49 * @return true if server is deemed reachable, false otherwise
50 */
51 boolean isServerReachable();
52
53 /**
54 * Similar to {@link #isServerReachable()}, but might involve sending
55 * packets over the network. This checks whether the specific gRPC
56 * service(s) required by this client is available or not on the server.
57 *
58 * @return completable future eventually true if the gRPC service(s) on the
59 * server was available during the probe; false otherwise
60 */
61 CompletableFuture<Boolean> probeService();
Yi Tseng2a340f72018-11-02 16:52:47 -070062}