Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 1 | /* |
| 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 Cascone | 3370c96 | 2019-02-07 18:24:19 -0800 | [diff] [blame] | 16 | |
| 17 | package org.onosproject.gnmi.ctl; |
Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 18 | |
| 19 | import io.grpc.ManagedChannel; |
Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 20 | import org.onosproject.gnmi.api.GnmiClient; |
| 21 | import org.onosproject.gnmi.api.GnmiClientKey; |
| 22 | import org.onosproject.gnmi.api.GnmiController; |
Ray Milkey | 5739b2c | 2018-11-06 14:04:51 -0800 | [diff] [blame] | 23 | import org.onosproject.gnmi.api.GnmiEvent; |
| 24 | import org.onosproject.gnmi.api.GnmiEventListener; |
| 25 | import org.onosproject.grpc.ctl.AbstractGrpcClientController; |
| 26 | import org.osgi.service.component.annotations.Activate; |
| 27 | import org.osgi.service.component.annotations.Component; |
| 28 | import org.osgi.service.component.annotations.Deactivate; |
Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 29 | import org.slf4j.Logger; |
| 30 | |
| 31 | import static org.slf4j.LoggerFactory.getLogger; |
| 32 | |
| 33 | /** |
| 34 | * Implementation of gNMI controller. |
| 35 | */ |
Ray Milkey | 5739b2c | 2018-11-06 14:04:51 -0800 | [diff] [blame] | 36 | @Component(immediate = true, service = GnmiController.class) |
Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 37 | public class GnmiControllerImpl |
| 38 | extends AbstractGrpcClientController<GnmiClientKey, GnmiClient, GnmiEvent, GnmiEventListener> |
| 39 | implements GnmiController { |
Carmelo Cascone | a46f554 | 2018-12-12 23:41:01 -0800 | [diff] [blame] | 40 | |
Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 41 | private final Logger log = getLogger(getClass()); |
| 42 | |
| 43 | @Activate |
| 44 | public void activate() { |
| 45 | super.activate(); |
Yi Tseng | e616d75 | 2018-11-27 10:53:27 -0800 | [diff] [blame] | 46 | eventDispatcher.addSink(GnmiEvent.class, listenerRegistry); |
Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 47 | 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 Tseng | e616d75 | 2018-11-27 10:53:27 -0800 | [diff] [blame] | 58 | 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 Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 68 | } |
| 69 | } |