blob: 13ab168ff43e3eadc4a82d2a6bc8bad48bec5bec [file] [log] [blame]
Yi Tseng890dc3f2018-11-01 13:23:11 -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 */
16package protocols.gnmi.ctl.java.org.onosproject.gnmi.ctl;
17
18import io.grpc.ManagedChannel;
Yi Tseng890dc3f2018-11-01 13:23:11 -070019import org.onosproject.gnmi.api.GnmiClient;
20import org.onosproject.gnmi.api.GnmiClientKey;
21import org.onosproject.gnmi.api.GnmiController;
Ray Milkey5739b2c2018-11-06 14:04:51 -080022import org.onosproject.gnmi.api.GnmiEvent;
23import org.onosproject.gnmi.api.GnmiEventListener;
24import org.onosproject.grpc.ctl.AbstractGrpcClientController;
25import org.osgi.service.component.annotations.Activate;
26import org.osgi.service.component.annotations.Component;
27import org.osgi.service.component.annotations.Deactivate;
Yi Tseng890dc3f2018-11-01 13:23:11 -070028import org.slf4j.Logger;
29
30import static org.slf4j.LoggerFactory.getLogger;
31
32/**
33 * Implementation of gNMI controller.
34 */
Ray Milkey5739b2c2018-11-06 14:04:51 -080035@Component(immediate = true, service = GnmiController.class)
Yi Tseng890dc3f2018-11-01 13:23:11 -070036public class GnmiControllerImpl
37 extends AbstractGrpcClientController<GnmiClientKey, GnmiClient, GnmiEvent, GnmiEventListener>
38 implements GnmiController {
Carmelo Casconea46f5542018-12-12 23:41:01 -080039
Yi Tseng890dc3f2018-11-01 13:23:11 -070040 private final Logger log = getLogger(getClass());
41
42 @Activate
43 public void activate() {
44 super.activate();
Yi Tsenge616d752018-11-27 10:53:27 -080045 eventDispatcher.addSink(GnmiEvent.class, listenerRegistry);
Yi Tseng890dc3f2018-11-01 13:23:11 -070046 log.info("Started");
47 }
48
49 @Deactivate
50 public void deactivate() {
51 super.deactivate();
52 log.info("Stopped");
53 }
54
55 @Override
56 protected GnmiClient createClientInstance(GnmiClientKey clientKey, ManagedChannel channel) {
Yi Tsenge616d752018-11-27 10:53:27 -080057 return new GnmiClientImpl(clientKey, channel, this);
58 }
59
60 /**
61 * Handles event from gNMI client.
62 *
63 * @param event the gNMI event
64 */
65 void postEvent(GnmiEvent event) {
66 post(event);
Yi Tseng890dc3f2018-11-01 13:23:11 -070067 }
68}