Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.codec.impl; |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 17 | |
Jian Li | 7231515 | 2015-12-10 17:20:43 -0800 | [diff] [blame] | 18 | import com.codahale.metrics.Metric; |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableSet; |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Service; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 24 | import org.onlab.packet.Ethernet; |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 25 | import org.onosproject.cluster.ControllerNode; |
Jian Li | b68a2b0 | 2016-05-02 11:23:32 -0700 | [diff] [blame] | 26 | import org.onosproject.cluster.RoleInfo; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 27 | import org.onosproject.codec.CodecService; |
| 28 | import org.onosproject.codec.JsonCodec; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 29 | import org.onosproject.core.Application; |
Jian Li | e1c1c8d | 2016-05-09 16:24:40 -0700 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
Sangsik Yoon | f0b3ad8 | 2016-08-19 18:47:59 +0900 | [diff] [blame] | 31 | import org.onosproject.incubator.net.dpi.DpiStatInfo; |
| 32 | import org.onosproject.incubator.net.dpi.DpiStatInfoCodec; |
| 33 | import org.onosproject.incubator.net.dpi.DpiStatistics; |
| 34 | import org.onosproject.incubator.net.dpi.DpiStatisticsCodec; |
| 35 | import org.onosproject.incubator.net.dpi.FlowStatInfo; |
| 36 | import org.onosproject.incubator.net.dpi.FlowStatInfoCodec; |
| 37 | import org.onosproject.incubator.net.dpi.ProtocolStatInfo; |
| 38 | import org.onosproject.incubator.net.dpi.ProtocolStatInfoCodec; |
| 39 | import org.onosproject.incubator.net.dpi.TrafficStatInfo; |
| 40 | import org.onosproject.incubator.net.dpi.TrafficStatInfoCodec; |
Claudine Chiu | fb8b816 | 2016-04-01 23:50:51 +0000 | [diff] [blame] | 41 | import org.onosproject.incubator.net.virtual.TenantId; |
| 42 | import org.onosproject.incubator.net.virtual.VirtualDevice; |
Claudine Chiu | 25f07be | 2016-06-27 16:21:21 +0000 | [diff] [blame] | 43 | import org.onosproject.incubator.net.virtual.VirtualHost; |
Claudine Chiu | f6bf8d5 | 2016-04-08 01:31:54 +0000 | [diff] [blame] | 44 | import org.onosproject.incubator.net.virtual.VirtualLink; |
Claudine Chiu | fb8b816 | 2016-04-01 23:50:51 +0000 | [diff] [blame] | 45 | import org.onosproject.incubator.net.virtual.VirtualNetwork; |
| 46 | import org.onosproject.incubator.net.virtual.VirtualPort; |
Jian Li | b68a2b0 | 2016-05-02 11:23:32 -0700 | [diff] [blame] | 47 | import org.onosproject.mastership.MastershipTerm; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 48 | import org.onosproject.net.Annotations; |
| 49 | import org.onosproject.net.ConnectPoint; |
| 50 | import org.onosproject.net.Device; |
Jonathan Hart | 8338b8d | 2017-08-15 15:46:14 -0700 | [diff] [blame] | 51 | import org.onosproject.net.DisjointPath; |
| 52 | import org.onosproject.net.FilteredConnectPoint; |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 53 | import org.onosproject.net.Host; |
| 54 | import org.onosproject.net.HostLocation; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 55 | import org.onosproject.net.Link; |
Jian Li | b68a2b0 | 2016-05-02 11:23:32 -0700 | [diff] [blame] | 56 | import org.onosproject.net.MastershipRole; |
Ray Milkey | 19ffea3 | 2015-01-28 10:03:06 -0800 | [diff] [blame] | 57 | import org.onosproject.net.Path; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 58 | import org.onosproject.net.Port; |
Yuta HIGUCHI | a255bb4 | 2016-11-03 16:04:08 -0700 | [diff] [blame] | 59 | import org.onosproject.net.behaviour.protection.TransportEndpointDescription; |
Jian Li | ecb3c0f | 2015-12-15 10:07:49 -0800 | [diff] [blame] | 60 | import org.onosproject.net.device.PortStatistics; |
Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 61 | import org.onosproject.net.driver.Driver; |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 62 | import org.onosproject.net.flow.FlowEntry; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 63 | import org.onosproject.net.flow.FlowRule; |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 64 | import org.onosproject.net.flow.TableStatisticsEntry; |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 65 | import org.onosproject.net.flow.TrafficSelector; |
| 66 | import org.onosproject.net.flow.TrafficTreatment; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 67 | import org.onosproject.net.flow.criteria.Criterion; |
| 68 | import org.onosproject.net.flow.instructions.Instruction; |
Jian Li | 8bcef8b | 2016-01-06 11:35:53 -0800 | [diff] [blame] | 69 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 70 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 71 | import org.onosproject.net.flowobjective.NextObjective; |
Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 72 | import org.onosproject.net.group.Group; |
| 73 | import org.onosproject.net.group.GroupBucket; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 74 | import org.onosproject.net.intent.ConnectivityIntent; |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 75 | import org.onosproject.net.intent.Constraint; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 76 | import org.onosproject.net.intent.HostToHostIntent; |
Ray Milkey | 2b21714 | 2014-12-15 09:24:24 -0800 | [diff] [blame] | 77 | import org.onosproject.net.intent.Intent; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 78 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 79 | import org.onosproject.net.intent.PointToPointIntent; |
Chiara Contoli | a8f69ff | 2016-07-28 01:06:07 +0900 | [diff] [blame] | 80 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; |
dvaddire | 95c84ed | 2017-06-14 15:42:24 +0530 | [diff] [blame] | 81 | import org.onosproject.net.intent.util.IntentMiniSummary; |
Brian Stanke | b9170d9 | 2016-02-19 14:18:42 -0500 | [diff] [blame] | 82 | import org.onosproject.net.key.DeviceKey; |
Jonathan Hart | 07eb041 | 2016-02-08 16:42:29 -0800 | [diff] [blame] | 83 | import org.onosproject.net.mcast.McastRoute; |
Jian Li | 5c41123 | 2015-12-16 15:29:16 -0800 | [diff] [blame] | 84 | import org.onosproject.net.meter.Band; |
| 85 | import org.onosproject.net.meter.Meter; |
Jian Li | 9567896 | 2016-01-26 17:17:52 -0800 | [diff] [blame] | 86 | import org.onosproject.net.meter.MeterRequest; |
Claudine Chiu | 1f036b8 | 2017-03-09 16:45:56 -0500 | [diff] [blame] | 87 | import org.onosproject.net.packet.PacketRequest; |
Yi Tseng | a87b40c | 2017-09-10 00:59:03 -0700 | [diff] [blame] | 88 | import org.onosproject.net.pi.model.PiActionModel; |
| 89 | import org.onosproject.net.pi.model.PiActionParamModel; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 90 | import org.onosproject.net.pi.model.PiMatchFieldModel; |
Yi Tseng | a87b40c | 2017-09-10 00:59:03 -0700 | [diff] [blame] | 91 | import org.onosproject.net.pi.model.PiPipeconf; |
| 92 | import org.onosproject.net.pi.model.PiPipelineModel; |
Yi Tseng | a87b40c | 2017-09-10 00:59:03 -0700 | [diff] [blame] | 93 | import org.onosproject.net.pi.model.PiTableModel; |
Jian Li | b68b9a8 | 2016-02-23 10:25:54 +0900 | [diff] [blame] | 94 | import org.onosproject.net.region.Region; |
Ray Milkey | b9af946 | 2015-07-17 11:12:09 -0700 | [diff] [blame] | 95 | import org.onosproject.net.statistic.Load; |
Ray Milkey | 82e5031 | 2015-01-22 17:01:42 -0800 | [diff] [blame] | 96 | import org.onosproject.net.topology.Topology; |
| 97 | import org.onosproject.net.topology.TopologyCluster; |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 98 | import org.slf4j.Logger; |
| 99 | import org.slf4j.LoggerFactory; |
| 100 | |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 101 | import java.util.Map; |
| 102 | import java.util.Set; |
| 103 | import java.util.concurrent.ConcurrentHashMap; |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 104 | |
Heedo Kang | 4a47a30 | 2016-02-29 17:40:23 +0900 | [diff] [blame] | 105 | import static org.onosproject.security.AppGuard.checkPermission; |
Jonathan Hart | 8338b8d | 2017-08-15 15:46:14 -0700 | [diff] [blame] | 106 | import static org.onosproject.security.AppPermission.Type.CODEC_READ; |
| 107 | import static org.onosproject.security.AppPermission.Type.CODEC_WRITE; |
Heedo Kang | 4a47a30 | 2016-02-29 17:40:23 +0900 | [diff] [blame] | 108 | |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 109 | /** |
| 110 | * Implementation of the JSON codec brokering service. |
| 111 | */ |
| 112 | @Component(immediate = true) |
| 113 | @Service |
| 114 | public class CodecManager implements CodecService { |
| 115 | |
| 116 | private static Logger log = LoggerFactory.getLogger(CodecManager.class); |
| 117 | |
| 118 | private final Map<Class<?>, JsonCodec> codecs = new ConcurrentHashMap<>(); |
| 119 | |
| 120 | @Activate |
| 121 | public void activate() { |
| 122 | codecs.clear(); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 123 | registerCodec(Application.class, new ApplicationCodec()); |
Jian Li | e1c1c8d | 2016-05-09 16:24:40 -0700 | [diff] [blame] | 124 | registerCodec(ApplicationId.class, new ApplicationIdCodec()); |
Thomas Vachuska | de563cf | 2015-04-01 00:28:50 -0700 | [diff] [blame] | 125 | registerCodec(ControllerNode.class, new ControllerNodeCodec()); |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 126 | registerCodec(Annotations.class, new AnnotationsCodec()); |
| 127 | registerCodec(Device.class, new DeviceCodec()); |
| 128 | registerCodec(Port.class, new PortCodec()); |
| 129 | registerCodec(ConnectPoint.class, new ConnectPointCodec()); |
| 130 | registerCodec(Link.class, new LinkCodec()); |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 131 | registerCodec(Host.class, new HostCodec()); |
| 132 | registerCodec(HostLocation.class, new HostLocationCodec()); |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 133 | registerCodec(HostToHostIntent.class, new HostToHostIntentCodec()); |
dvaddire | 95c84ed | 2017-06-14 15:42:24 +0530 | [diff] [blame] | 134 | registerCodec(IntentMiniSummary.class, new IntentMiniSummaryCodec()); |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 135 | registerCodec(PointToPointIntent.class, new PointToPointIntentCodec()); |
Chiara Contoli | a8f69ff | 2016-07-28 01:06:07 +0900 | [diff] [blame] | 136 | registerCodec(SinglePointToMultiPointIntent.class, new SinglePointToMultiPointIntentCodec()); |
nassima toumi | 9576131 | 2017-05-23 14:00:33 +0300 | [diff] [blame] | 137 | registerCodec(MultiPointToSinglePointIntent.class, new MultiPointToSinglePointIntentCodec()); |
Ray Milkey | 2b21714 | 2014-12-15 09:24:24 -0800 | [diff] [blame] | 138 | registerCodec(Intent.class, new IntentCodec()); |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 139 | registerCodec(ConnectivityIntent.class, new ConnectivityIntentCodec()); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 140 | registerCodec(FlowEntry.class, new FlowEntryCodec()); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 141 | registerCodec(FlowRule.class, new FlowRuleCodec()); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 142 | registerCodec(TrafficTreatment.class, new TrafficTreatmentCodec()); |
| 143 | registerCodec(TrafficSelector.class, new TrafficSelectorCodec()); |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 144 | registerCodec(Instruction.class, new InstructionCodec()); |
| 145 | registerCodec(Criterion.class, new CriterionCodec()); |
| 146 | registerCodec(Ethernet.class, new EthernetCodec()); |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 147 | registerCodec(Constraint.class, new ConstraintCodec()); |
Ray Milkey | 82e5031 | 2015-01-22 17:01:42 -0800 | [diff] [blame] | 148 | registerCodec(Topology.class, new TopologyCodec()); |
| 149 | registerCodec(TopologyCluster.class, new TopologyClusterCodec()); |
Ray Milkey | 19ffea3 | 2015-01-28 10:03:06 -0800 | [diff] [blame] | 150 | registerCodec(Path.class, new PathCodec()); |
Jayasree Ghosh | d3ff540 | 2016-08-17 18:41:19 +0530 | [diff] [blame] | 151 | registerCodec(DisjointPath.class, new DisjointPathCodec()); |
Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 152 | registerCodec(Group.class, new GroupCodec()); |
| 153 | registerCodec(Driver.class, new DriverCodec()); |
| 154 | registerCodec(GroupBucket.class, new GroupBucketCodec()); |
Ray Milkey | b9af946 | 2015-07-17 11:12:09 -0700 | [diff] [blame] | 155 | registerCodec(Load.class, new LoadCodec()); |
Jian Li | 9567896 | 2016-01-26 17:17:52 -0800 | [diff] [blame] | 156 | registerCodec(MeterRequest.class, new MeterRequestCodec()); |
Jian Li | 5c41123 | 2015-12-16 15:29:16 -0800 | [diff] [blame] | 157 | registerCodec(Meter.class, new MeterCodec()); |
| 158 | registerCodec(Band.class, new MeterBandCodec()); |
Srikanth Vavilapalli | 95810f5 | 2015-09-14 15:49:56 -0700 | [diff] [blame] | 159 | registerCodec(TableStatisticsEntry.class, new TableStatisticsEntryCodec()); |
Srikanth Vavilapalli | d120f5c | 2015-11-24 14:15:01 -0800 | [diff] [blame] | 160 | registerCodec(PortStatistics.class, new PortStatisticsCodec()); |
Jian Li | 7231515 | 2015-12-10 17:20:43 -0800 | [diff] [blame] | 161 | registerCodec(Metric.class, new MetricCodec()); |
Jian Li | 8bcef8b | 2016-01-06 11:35:53 -0800 | [diff] [blame] | 162 | registerCodec(FilteringObjective.class, new FilteringObjectiveCodec()); |
| 163 | registerCodec(ForwardingObjective.class, new ForwardingObjectiveCodec()); |
| 164 | registerCodec(NextObjective.class, new NextObjectiveCodec()); |
Jonathan Hart | 07eb041 | 2016-02-08 16:42:29 -0800 | [diff] [blame] | 165 | registerCodec(McastRoute.class, new McastRouteCodec()); |
Brian Stanke | b9170d9 | 2016-02-19 14:18:42 -0500 | [diff] [blame] | 166 | registerCodec(DeviceKey.class, new DeviceKeyCodec()); |
Jian Li | b68b9a8 | 2016-02-23 10:25:54 +0900 | [diff] [blame] | 167 | registerCodec(Region.class, new RegionCodec()); |
Claudine Chiu | fb8b816 | 2016-04-01 23:50:51 +0000 | [diff] [blame] | 168 | registerCodec(TenantId.class, new TenantIdCodec()); |
| 169 | registerCodec(VirtualNetwork.class, new VirtualNetworkCodec()); |
| 170 | registerCodec(VirtualDevice.class, new VirtualDeviceCodec()); |
| 171 | registerCodec(VirtualPort.class, new VirtualPortCodec()); |
Claudine Chiu | f6bf8d5 | 2016-04-08 01:31:54 +0000 | [diff] [blame] | 172 | registerCodec(VirtualLink.class, new VirtualLinkCodec()); |
Claudine Chiu | 25f07be | 2016-06-27 16:21:21 +0000 | [diff] [blame] | 173 | registerCodec(VirtualHost.class, new VirtualHostCodec()); |
Jian Li | b68a2b0 | 2016-05-02 11:23:32 -0700 | [diff] [blame] | 174 | registerCodec(MastershipTerm.class, new MastershipTermCodec()); |
| 175 | registerCodec(MastershipRole.class, new MastershipRoleCodec()); |
| 176 | registerCodec(RoleInfo.class, new RoleInfoCodec()); |
Sangsik Yoon | f0b3ad8 | 2016-08-19 18:47:59 +0900 | [diff] [blame] | 177 | registerCodec(DpiStatistics.class, new DpiStatisticsCodec()); |
| 178 | registerCodec(DpiStatInfo.class, new DpiStatInfoCodec()); |
| 179 | registerCodec(TrafficStatInfo.class, new TrafficStatInfoCodec()); |
| 180 | registerCodec(ProtocolStatInfo.class, new ProtocolStatInfoCodec()); |
| 181 | registerCodec(FlowStatInfo.class, new FlowStatInfoCodec()); |
Yuta HIGUCHI | 776f074 | 2016-11-03 15:51:14 -0700 | [diff] [blame] | 182 | registerCodec(FilteredConnectPoint.class, new FilteredConnectPointCodec()); |
Yuta HIGUCHI | a255bb4 | 2016-11-03 16:04:08 -0700 | [diff] [blame] | 183 | registerCodec(TransportEndpointDescription.class, new TransportEndpointDescriptionCodec()); |
Claudine Chiu | 1f036b8 | 2017-03-09 16:45:56 -0500 | [diff] [blame] | 184 | registerCodec(PacketRequest.class, new PacketRequestCodec()); |
Yi Tseng | a87b40c | 2017-09-10 00:59:03 -0700 | [diff] [blame] | 185 | registerCodec(PiActionModel.class, new PiActionModelCodec()); |
Yi Tseng | a87b40c | 2017-09-10 00:59:03 -0700 | [diff] [blame] | 186 | registerCodec(PiPipelineModel.class, new PiPipelineModelCodec()); |
| 187 | registerCodec(PiPipeconf.class, new PiPipeconfCodec()); |
| 188 | registerCodec(PiTableModel.class, new PiTableModelCodec()); |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 189 | registerCodec(PiMatchFieldModel.class, new PiMatchFieldModelCodec()); |
Yi Tseng | a87b40c | 2017-09-10 00:59:03 -0700 | [diff] [blame] | 190 | registerCodec(PiActionParamModel.class, new PiActionParamModelCodec()); |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 191 | log.info("Started"); |
| 192 | } |
| 193 | |
| 194 | @Deactivate |
Ray Milkey | 1f95bd3 | 2014-12-10 11:11:00 -0800 | [diff] [blame] | 195 | public void deactivate() { |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 196 | codecs.clear(); |
| 197 | log.info("Stopped"); |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public Set<Class<?>> getCodecs() { |
Heedo Kang | 4a47a30 | 2016-02-29 17:40:23 +0900 | [diff] [blame] | 202 | checkPermission(CODEC_READ); |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 203 | return ImmutableSet.copyOf(codecs.keySet()); |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | @SuppressWarnings("unchecked") |
| 208 | public <T> JsonCodec<T> getCodec(Class<T> entityClass) { |
Heedo Kang | 4a47a30 | 2016-02-29 17:40:23 +0900 | [diff] [blame] | 209 | checkPermission(CODEC_READ); |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 210 | return codecs.get(entityClass); |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) { |
Heedo Kang | 4a47a30 | 2016-02-29 17:40:23 +0900 | [diff] [blame] | 215 | checkPermission(CODEC_WRITE); |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 216 | codecs.putIfAbsent(entityClass, codec); |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public void unregisterCodec(Class<?> entityClass) { |
Heedo Kang | 4a47a30 | 2016-02-29 17:40:23 +0900 | [diff] [blame] | 221 | checkPermission(CODEC_WRITE); |
Thomas Vachuska | ca60f2b | 2014-11-06 01:34:28 -0800 | [diff] [blame] | 222 | codecs.remove(entityClass); |
| 223 | } |
| 224 | |
| 225 | } |