blob: c0bdcddbfae1604dc975b6eaa72a241d8a67238c [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 */
Carmelo Cascone3370c962019-02-07 18:24:19 -080016
17package org.onosproject.gnmi.ctl;
Yi Tseng890dc3f2018-11-01 13:23:11 -070018
19import io.grpc.ManagedChannel;
Yi Tseng890dc3f2018-11-01 13:23:11 -070020import org.onosproject.gnmi.api.GnmiClient;
21import org.onosproject.gnmi.api.GnmiClientKey;
22import org.onosproject.gnmi.api.GnmiController;
Ray Milkey5739b2c2018-11-06 14:04:51 -080023import org.onosproject.gnmi.api.GnmiEvent;
24import org.onosproject.gnmi.api.GnmiEventListener;
25import org.onosproject.grpc.ctl.AbstractGrpcClientController;
26import org.osgi.service.component.annotations.Activate;
27import org.osgi.service.component.annotations.Component;
28import org.osgi.service.component.annotations.Deactivate;
Yi Tseng890dc3f2018-11-01 13:23:11 -070029import org.slf4j.Logger;
30
31import static org.slf4j.LoggerFactory.getLogger;
32
33/**
34 * Implementation of gNMI controller.
35 */
Ray Milkey5739b2c2018-11-06 14:04:51 -080036@Component(immediate = true, service = GnmiController.class)
Yi Tseng890dc3f2018-11-01 13:23:11 -070037public class GnmiControllerImpl
38 extends AbstractGrpcClientController<GnmiClientKey, GnmiClient, GnmiEvent, GnmiEventListener>
39 implements GnmiController {
Carmelo Casconea46f5542018-12-12 23:41:01 -080040
Yi Tseng890dc3f2018-11-01 13:23:11 -070041 private final Logger log = getLogger(getClass());
42
43 @Activate
44 public void activate() {
45 super.activate();
Yi Tsenge616d752018-11-27 10:53:27 -080046 eventDispatcher.addSink(GnmiEvent.class, listenerRegistry);
Yi Tseng890dc3f2018-11-01 13:23:11 -070047 log.info("Started");
48 }
49
50 @Deactivate
51 public void deactivate() {
52 super.deactivate();
53 log.info("Stopped");
54 }
55
56 @Override
57 protected GnmiClient createClientInstance(GnmiClientKey clientKey, ManagedChannel channel) {
Yi Tsenge616d752018-11-27 10:53:27 -080058 return new GnmiClientImpl(clientKey, channel, this);
59 }
60
61 /**
62 * Handles event from gNMI client.
63 *
64 * @param event the gNMI event
65 */
66 void postEvent(GnmiEvent event) {
67 post(event);
Yi Tseng890dc3f2018-11-01 13:23:11 -070068 }
69}