blob: 3edb36df3fde1aa7efb0883704c25f995e796db4 [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 Casconec2be50a2019-04-10 00:15:39 -070020import io.grpc.ManagedChannel;
Yi Tseng2a340f72018-11-02 16:52:47 -070021import org.onosproject.net.DeviceId;
Carmelo Cascone3977ea42019-02-28 13:43:42 -080022import org.onosproject.net.device.DeviceAgentListener;
23import org.onosproject.net.provider.ProviderId;
Yi Tseng2a340f72018-11-02 16:52:47 -070024
25/**
Carmelo Cascone3977ea42019-02-28 13:43:42 -080026 * Abstraction of controller that manages gRPC clients.
Yi Tseng2a340f72018-11-02 16:52:47 -070027 *
Yi Tseng2a340f72018-11-02 16:52:47 -070028 * @param <C> the gRPC client type
29 */
30@Beta
Carmelo Casconec2be50a2019-04-10 00:15:39 -070031public interface GrpcClientController<C extends GrpcClient> {
Yi Tseng2a340f72018-11-02 16:52:47 -070032
33 /**
Carmelo Casconec2be50a2019-04-10 00:15:39 -070034 * Instantiates a new client to operate on the given gRPC channel. Returns
35 * true if the client was created successfully, false otherwise. Clients
36 * are identified by device IDs and once created they can be obtained by
37 * invoking {@link #get(DeviceId)}.
Yi Tsengd7716482018-10-31 15:34:30 -070038 * <p>
Carmelo Casconec2be50a2019-04-10 00:15:39 -070039 * Only one client can exist for the same device ID. If a client for the
40 * given device ID already exists, throws an exception.
Yi Tseng2a340f72018-11-02 16:52:47 -070041 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070042 * @param deviceId device ID
43 * @param channel gRPC managed channel
44 * @return true if the client was created, false otherwise
45 * @throws IllegalArgumentException if a client for the same device ID
46 * already exists.
Yi Tseng2a340f72018-11-02 16:52:47 -070047 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -070048 boolean create(DeviceId deviceId, ManagedChannel channel);
Yi Tseng2a340f72018-11-02 16:52:47 -070049
50 /**
Carmelo Casconec2be50a2019-04-10 00:15:39 -070051 * Returns the gRPC client previously created for the given device ID, or
Carmelo Cascone3977ea42019-02-28 13:43:42 -080052 * null if such client does not exist.
53 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070054 * @param deviceId the device ID
Carmelo Cascone3977ea42019-02-28 13:43:42 -080055 * @return the gRPC client of the device if exists; null otherwise
56 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -070057 C get(DeviceId deviceId);
Carmelo Cascone3977ea42019-02-28 13:43:42 -080058
59 /**
60 * Removes the gRPC client for the given device and any gRPC channel state
61 * associated to it. If no client exists for the given device, the result is
62 * a no-op.
Yi Tseng2a340f72018-11-02 16:52:47 -070063 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070064 * @param deviceId the device ID
Yi Tseng2a340f72018-11-02 16:52:47 -070065 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -070066 void remove(DeviceId deviceId);
Yi Tseng2a340f72018-11-02 16:52:47 -070067
68 /**
Carmelo Casconec2be50a2019-04-10 00:15:39 -070069 * Adds a listener for device agent events for the given provider. If a
70 * listener already exists for the given device ID and provider ID, then it
71 * will be replaced by the new one.
Yi Tseng2a340f72018-11-02 16:52:47 -070072 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070073 * @param deviceId device ID
Carmelo Cascone3977ea42019-02-28 13:43:42 -080074 * @param providerId provider ID
Carmelo Casconec2be50a2019-04-10 00:15:39 -070075 * @param listener the device agent listener
Carmelo Cascone3977ea42019-02-28 13:43:42 -080076 */
77 void addDeviceAgentListener(DeviceId deviceId, ProviderId providerId,
78 DeviceAgentListener listener);
79
80 /**
81 * Removes the listener for device agent events that was previously
82 * registered for the given provider.
83 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070084 * @param deviceId device ID
Carmelo Cascone3977ea42019-02-28 13:43:42 -080085 * @param providerId the provider ID
86 */
87 void removeDeviceAgentListener(DeviceId deviceId, ProviderId providerId);
Yi Tseng2a340f72018-11-02 16:52:47 -070088}