Jian Li | f2acb66 | 2017-04-06 02:06:16 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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 org.onosproject.drivers.lisp.extensions; |
| 17 | |
| 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; |
| 21 | import org.apache.felix.scr.annotations.Reference; |
| 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 23 | import org.onosproject.codec.CodecService; |
| 24 | import org.onosproject.drivers.lisp.extensions.codec.LispAppDataAddressCodec; |
Jian Li | 944e3a9 | 2017-04-07 23:53:36 +0900 | [diff] [blame^] | 25 | import org.onosproject.drivers.lisp.extensions.codec.LispAsAddressCodec; |
Jian Li | f2acb66 | 2017-04-06 02:06:16 +0900 | [diff] [blame] | 26 | import org.onosproject.mapping.web.MappingCodecRegistrator; |
| 27 | import org.slf4j.Logger; |
| 28 | |
| 29 | import static org.slf4j.LoggerFactory.getLogger; |
| 30 | |
| 31 | /** |
| 32 | * Implementation of the JSON codec brokering service for |
| 33 | * mapping extension primitives. |
| 34 | */ |
| 35 | @Component(immediate = true) |
| 36 | public class LispMappingExtensionCodecRegistrator extends MappingCodecRegistrator { |
| 37 | |
| 38 | private final Logger log = getLogger(getClass()); |
| 39 | private MappingCodecRegistrator registrator; |
| 40 | |
| 41 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 42 | public CodecService codecService; |
| 43 | |
| 44 | @Activate |
| 45 | public void activate() { |
| 46 | |
| 47 | registrator = new MappingCodecRegistrator(); |
| 48 | registrator.codecService = codecService; |
| 49 | registrator.activate(); |
| 50 | |
| 51 | codecService.registerCodec(LispAppDataAddress.class, new LispAppDataAddressCodec()); |
Jian Li | 944e3a9 | 2017-04-07 23:53:36 +0900 | [diff] [blame^] | 52 | codecService.registerCodec(LispAsAddress.class, new LispAsAddressCodec()); |
Jian Li | f2acb66 | 2017-04-06 02:06:16 +0900 | [diff] [blame] | 53 | |
| 54 | log.info("Started"); |
| 55 | } |
| 56 | |
| 57 | @Deactivate |
| 58 | public void deactivate() { |
| 59 | codecService.unregisterCodec(LispAppDataAddress.class); |
Jian Li | 944e3a9 | 2017-04-07 23:53:36 +0900 | [diff] [blame^] | 60 | codecService.unregisterCodec(LispAsAddress.class); |
Jian Li | f2acb66 | 2017-04-06 02:06:16 +0900 | [diff] [blame] | 61 | |
| 62 | registrator.deactivate(); |
| 63 | registrator = null; |
| 64 | |
| 65 | log.info("Stopped"); |
| 66 | } |
| 67 | } |