X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fspi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fspi%2Fpojo%2FSimpleRROSubobjectRegistry.java;h=6861980a8da82a31206b96ffd889e6e4281e721d;hb=de85a9278e9bf40831803e537d724a6d2bdfac34;hp=c583ce1b07bca2ad2fa8cd6e73d308cdd3255942;hpb=b6a10e3ec81bee2a49ac44486eb83b06d52a52db;p=bgpcep.git diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectRegistry.java index c583ce1b07..6861980a8d 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectRegistry.java @@ -7,49 +7,47 @@ */ package org.opendaylight.protocol.pcep.spi.pojo; -import io.netty.buffer.ByteBuf; +import static com.google.common.base.Preconditions.checkArgument; +import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.concepts.HandlerRegistry; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.RROSubobjectParser; import org.opendaylight.protocol.pcep.spi.RROSubobjectRegistry; import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer; import org.opendaylight.protocol.util.Values; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.SubobjectType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.SubobjectType; +import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.DataContainer; -import com.google.common.base.Preconditions; - public final class SimpleRROSubobjectRegistry implements RROSubobjectRegistry { - private final HandlerRegistry handlers = new HandlerRegistry<>(); - - public AutoCloseable registerSubobjectParser(final int subobjectType, final RROSubobjectParser parser) { - Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE); - return this.handlers.registerParser(subobjectType, parser); - } - - public AutoCloseable registerSubobjectSerializer(final Class subobjectClass, - final RROSubobjectSerializer serializer) { - return this.handlers.registerSerializer(subobjectClass, serializer); - } - - @Override - public Subobject parseSubobject(final int type, final ByteBuf buffer) throws PCEPDeserializerException { - Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE); - final RROSubobjectParser parser = this.handlers.getParser(type); - if (parser == null) { - return null; - } - return parser.parseSubobject(buffer); - } - - @Override - public byte[] serializeSubobject(Subobject subobject) { - final RROSubobjectSerializer serializer = this.handlers.getSerializer(subobject.getSubobjectType().getImplementedInterface()); - if (serializer == null) { - return null; - } - return serializer.serializeSubobject(subobject); - } + private final HandlerRegistry handlers = + new HandlerRegistry<>(); + + public Registration registerSubobjectParser(final int subobjectType, final RROSubobjectParser parser) { + checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE); + return this.handlers.registerParser(subobjectType, parser); + } + + public Registration registerSubobjectSerializer(final Class subobjectClass, + final RROSubobjectSerializer serializer) { + return this.handlers.registerSerializer(subobjectClass, serializer); + } + + @Override + public Subobject parseSubobject(final int type, final ByteBuf buffer) throws PCEPDeserializerException { + checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE); + final RROSubobjectParser parser = this.handlers.getParser(type); + return parser == null ? null : parser.parseSubobject(buffer); + } + + @Override + public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { + final RROSubobjectSerializer serializer = this.handlers.getSerializer( + subobject.getSubobjectType().implementedInterface()); + if (serializer != null) { + serializer.serializeSubobject(subobject, buffer); + } + } }