blob: 3cdbcd13950afa25a2d60ccb4f75bf907b120376 [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;
20import org.onosproject.net.DeviceId;
21
22/**
Yi Tsengd7716482018-10-31 15:34:30 -070023 * Abstraction of a gRPC controller which controls specific gRPC client {@link
24 * C} with specific client key {@link K}.
Yi Tseng2a340f72018-11-02 16:52:47 -070025 *
26 * @param <K> the gRPC client key
27 * @param <C> the gRPC client type
28 */
29@Beta
30public interface GrpcClientController<K extends GrpcClientKey, C extends GrpcClient> {
31
32 /**
Yi Tsengd7716482018-10-31 15:34:30 -070033 * Instantiates a new client to operate on a gRPC server identified by the
34 * given information. As a result of this method, a client can be later
Yi Tseng2a340f72018-11-02 16:52:47 -070035 * obtained by invoking {@link #getClient(DeviceId)}.
Yi Tsengd7716482018-10-31 15:34:30 -070036 * <p>
37 * Only one client can exist for the same device ID. Calls to this method
38 * are idempotent fot the same client key, i.e. returns true if such client
39 * already exists but a new one is not created. If there exists a client
40 * with same device ID but different address and port, removes old one and
41 * recreate new one.
Yi Tseng2a340f72018-11-02 16:52:47 -070042 *
43 * @param clientKey the client key
Yi Tsengd7716482018-10-31 15:34:30 -070044 * @return true if the client was created and the channel to the server is
45 * open; false otherwise
Yi Tseng2a340f72018-11-02 16:52:47 -070046 */
47 boolean createClient(K clientKey);
48
49 /**
50 * Retrieves the gRPC client to operate on the given device.
51 *
52 * @param deviceId the device identifier
53 * @return the gRPC client of the device if exists; null otherwise
54 */
55 C getClient(DeviceId deviceId);
56
57 /**
Yi Tsengd7716482018-10-31 15:34:30 -070058 * Removes the gRPC client for the given device. If no client exists for the
59 * given device, the result is a no-op.
Yi Tseng2a340f72018-11-02 16:52:47 -070060 *
61 * @param deviceId the device identifier
62 */
63 void removeClient(DeviceId deviceId);
64
65 /**
66 * Check reachability of the gRPC server running on the given device.
Yi Tsengd7716482018-10-31 15:34:30 -070067 * Reachability can be tested only if a client is previously created using
68 * {@link #createClient(GrpcClientKey)}. Note that this only checks the
69 * reachability instead of checking service availability, different
70 * service-specific gRPC clients might check service availability in a
Yi Tseng5f7fef52018-11-05 11:30:47 -080071 * different way.
Yi Tseng2a340f72018-11-02 16:52:47 -070072 *
73 * @param deviceId the device identifier
Yi Tsengd7716482018-10-31 15:34:30 -070074 * @return true if client was created and is able to contact the gNMI
75 * server; false otherwise
Yi Tseng2a340f72018-11-02 16:52:47 -070076 */
77 boolean isReachable(DeviceId deviceId);
78}