blob: 7957006698dd83ad3e5807af73f486d35a8bb23f [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.
Yi Tseng2a340f72018-11-02 16:52:47 -070031 */
Carmelo Casconeab5d41e2019-03-06 18:02:34 -080032 void shutdown();
Carmelo Cascone3977ea42019-02-28 13:43:42 -080033
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 Tseng2a340f72018-11-02 16:52:47 -070059}