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 | */ |
| 16 | package protocols.gnmi.ctl.java.org.onosproject.gnmi.ctl; |
| 17 | |
| 18 | import io.grpc.ManagedChannel; |
Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 19 | import org.onosproject.gnmi.api.GnmiClient; |
| 20 | import org.onosproject.gnmi.api.GnmiClientKey; |
| 21 | import org.onosproject.gnmi.api.GnmiController; |
Ray Milkey | 5739b2c | 2018-11-06 14:04:51 -0800 | [diff] [blame] | 22 | import org.onosproject.gnmi.api.GnmiEvent; |
| 23 | import org.onosproject.gnmi.api.GnmiEventListener; |
| 24 | import org.onosproject.grpc.ctl.AbstractGrpcClientController; |
| 25 | import org.osgi.service.component.annotations.Activate; |
| 26 | import org.osgi.service.component.annotations.Component; |
| 27 | import org.osgi.service.component.annotations.Deactivate; |
Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 28 | import org.slf4j.Logger; |
| 29 | |
| 30 | import static org.slf4j.LoggerFactory.getLogger; |
| 31 | |
| 32 | /** |
| 33 | * Implementation of gNMI controller. |
| 34 | */ |
Ray Milkey | 5739b2c | 2018-11-06 14:04:51 -0800 | [diff] [blame] | 35 | @Component(immediate = true, service = GnmiController.class) |
Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 36 | public 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 Tseng | e616d75 | 2018-11-27 10:53:27 -0800 | [diff] [blame^] | 44 | eventDispatcher.addSink(GnmiEvent.class, listenerRegistry); |
Yi Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 45 | 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 Tseng | e616d75 | 2018-11-27 10:53:27 -0800 | [diff] [blame^] | 56 | 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 Tseng | 890dc3f | 2018-11-01 13:23:11 -0700 | [diff] [blame] | 66 | } |
| 67 | } |