Committed by
Gerrit Code Review
[ONOS-3114] Vtn codec registrator added
Change-Id: I500e8a9c5f67603cb287d8deab33cddf2e93cbaa
Showing
2 changed files
with
72 additions
and
25 deletions
1 | +/* | ||
2 | + * Copyright 2014-2015 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.vtnweb.web; | ||
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.vtnrsc.FlowClassifier; | ||
25 | +import org.onosproject.vtnrsc.PortChain; | ||
26 | +import org.onosproject.vtnrsc.PortPair; | ||
27 | +import org.onosproject.vtnrsc.PortPairGroup; | ||
28 | +import org.slf4j.Logger; | ||
29 | +import org.slf4j.LoggerFactory; | ||
30 | + | ||
31 | +/** | ||
32 | + * Implementation of the JSON codec brokering service for VTN app. | ||
33 | + */ | ||
34 | +@Component(immediate = true) | ||
35 | +public class VtnCodecRegistrator { | ||
36 | + | ||
37 | + private static Logger log = LoggerFactory.getLogger(VtnCodecRegistrator.class); | ||
38 | + | ||
39 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
40 | + protected CodecService codecService; | ||
41 | + | ||
42 | + @Activate | ||
43 | + public void activate() { | ||
44 | + codecService.registerCodec(PortPair.class, new PortPairCodec()); | ||
45 | + codecService.registerCodec(PortPairGroup.class, new PortPairGroupCodec()); | ||
46 | + codecService.registerCodec(FlowClassifier.class, new FlowClassifierCodec()); | ||
47 | + codecService.registerCodec(PortChain.class, new PortChainCodec()); | ||
48 | + | ||
49 | + log.info("Started"); | ||
50 | + } | ||
51 | + | ||
52 | + @Deactivate | ||
53 | + public void deactivate() { | ||
54 | + log.info("Stopped"); | ||
55 | + } | ||
56 | +} |
... | @@ -15,15 +15,10 @@ | ... | @@ -15,15 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.vtnweb.web; | 16 | package org.onosproject.vtnweb.web; |
17 | 17 | ||
18 | -import java.util.Map; | ||
19 | -import java.util.concurrent.ConcurrentHashMap; | ||
20 | - | ||
21 | import org.onosproject.codec.CodecContext; | 18 | import org.onosproject.codec.CodecContext; |
19 | +import org.onosproject.codec.CodecService; | ||
22 | import org.onosproject.codec.JsonCodec; | 20 | import org.onosproject.codec.JsonCodec; |
23 | -import org.onosproject.vtnrsc.FlowClassifier; | 21 | +import org.onosproject.codec.impl.CodecManager; |
24 | -import org.onosproject.vtnrsc.PortChain; | ||
25 | -import org.onosproject.vtnrsc.PortPair; | ||
26 | -import org.onosproject.vtnrsc.PortPairGroup; | ||
27 | 22 | ||
28 | import com.fasterxml.jackson.databind.ObjectMapper; | 23 | import com.fasterxml.jackson.databind.ObjectMapper; |
29 | 24 | ||
... | @@ -33,17 +28,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ... | @@ -33,17 +28,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
33 | public class SfcCodecContext implements CodecContext { | 28 | public class SfcCodecContext implements CodecContext { |
34 | 29 | ||
35 | private final ObjectMapper mapper = new ObjectMapper(); | 30 | private final ObjectMapper mapper = new ObjectMapper(); |
36 | - private final Map<Class<?>, JsonCodec> codecs = new ConcurrentHashMap<>(); | 31 | + private final CodecManager codecManager = new CodecManager(); |
32 | + private final VtnCodecRegistrator manager = new VtnCodecRegistrator(); | ||
37 | 33 | ||
38 | /** | 34 | /** |
39 | * Constructs a new mock codec context. | 35 | * Constructs a new mock codec context. |
40 | */ | 36 | */ |
41 | public SfcCodecContext() { | 37 | public SfcCodecContext() { |
42 | - codecs.clear(); | 38 | + codecManager.activate(); |
43 | - registerCodec(PortPair.class, new PortPairCodec()); | 39 | + manager.codecService = codecManager; |
44 | - registerCodec(PortChain.class, new PortChainCodec()); | 40 | + manager.activate(); |
45 | - registerCodec(PortPairGroup.class, new PortPairGroupCodec()); | ||
46 | - registerCodec(FlowClassifier.class, new FlowClassifierCodec()); | ||
47 | } | 41 | } |
48 | 42 | ||
49 | @Override | 43 | @Override |
... | @@ -58,20 +52,17 @@ public class SfcCodecContext implements CodecContext { | ... | @@ -58,20 +52,17 @@ public class SfcCodecContext implements CodecContext { |
58 | return null; | 52 | return null; |
59 | } | 53 | } |
60 | 54 | ||
55 | + @Override | ||
56 | + public <T> JsonCodec<T> codec(Class<T> entityClass) { | ||
57 | + return codecManager.getCodec(entityClass); | ||
58 | + } | ||
59 | + | ||
61 | /** | 60 | /** |
62 | - * Registers the specified JSON codec for the given entity class. | 61 | + * Get the codec manager. |
63 | * | 62 | * |
64 | - * @param entityClass entity class | 63 | + * @return instance of codec manager |
65 | - * @param codec JSON codec | ||
66 | - * @param <T> entity type | ||
67 | */ | 64 | */ |
68 | - public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) { | 65 | + public CodecService codecManager() { |
69 | - codecs.putIfAbsent(entityClass, codec); | 66 | + return codecManager; |
70 | - } | ||
71 | - | ||
72 | - @SuppressWarnings("unchecked") | ||
73 | - @Override | ||
74 | - public <T> JsonCodec<T> codec(Class<T> entityClass) { | ||
75 | - return codecs.get(entityClass); | ||
76 | } | 67 | } |
77 | } | 68 | } | ... | ... |
-
Please register or login to post a comment