blob: cf147128eb2776c75106dd5c46a479851ccfe4ab [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 {
39 private final Logger log = getLogger(getClass());
40
41 @Activate
42 public void activate() {
43 super.activate();
Yi Tsenge616d752018-11-27 10:53:27 -080044 eventDispatcher.addSink(GnmiEvent.class, listenerRegistry);
Yi Tseng890dc3f2018-11-01 13:23:11 -070045 log.info("Started");
46 }
47
48 @Deactivate
49 public void deactivate() {
50 super.deactivate();
51 log.info("Stopped");
52 }
53
54 @Override
55 protected GnmiClient createClientInstance(GnmiClientKey clientKey, ManagedChannel channel) {
Yi Tsenge616d752018-11-27 10:53:27 -080056 return new GnmiClientImpl(clientKey, channel, this);
57 }
58
59 /**
60 * Handles event from gNMI client.
61 *
62 * @param event the gNMI event
63 */
64 void postEvent(GnmiEvent event) {
65 post(event);
Yi Tseng890dc3f2018-11-01 13:23:11 -070066 }
67}