Register PCEP session to stats handler only after it is fully initialized
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / pojo / SimpleVendorInformationObjectRegistry.java
index 4823ddfb57b38781f11b3938b5dab3c138a83459..081f53915f070d76d8c1eb055ee4274189c633ba 100644 (file)
@@ -5,13 +5,9 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.pcep.spi.pojo;
 
-import com.google.common.primitives.Ints;
-
 import io.netty.buffer.ByteBuf;
-
 import java.util.Optional;
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
@@ -25,24 +21,28 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.EnterpriseSpecificInformation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
 public class SimpleVendorInformationObjectRegistry implements VendorInformationObjectRegistry {
-
     private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
 
-    public AutoCloseable registerVendorInformationObjectParser(final EnterpriseNumber enterpriseNumber, final ObjectParser parser) {
-        return this.handlers.registerParser(Ints.checkedCast(enterpriseNumber.getValue()), parser);
+    public Registration registerVendorInformationObjectParser(final EnterpriseNumber enterpriseNumber,
+            final ObjectParser parser) {
+        return this.handlers.registerParser(enterpriseNumber.getValue().intValue(), parser);
     }
 
-    public AutoCloseable registerVendorInformationObjectSerializer(final Class<? extends EnterpriseSpecificInformation> esInformationClass, final ObjectSerializer serializer) {
+    public Registration registerVendorInformationObjectSerializer(
+            final Class<? extends EnterpriseSpecificInformation> esInformationClass,
+            final ObjectSerializer serializer) {
         return this.handlers.registerSerializer(esInformationClass, serializer);
     }
 
     @Override
-    public Optional<? extends Object> parseVendorInformationObject(final EnterpriseNumber enterpriseNumber, final ObjectHeader header, final ByteBuf buffer)
+    public Optional<? extends Object> parseVendorInformationObject(final EnterpriseNumber enterpriseNumber,
+            final ObjectHeader header, final ByteBuf buffer)
             throws PCEPDeserializerException {
-        final ObjectParser parser = this.handlers.getParser(Ints.checkedCast(enterpriseNumber.getValue()));
+        final ObjectParser parser = this.handlers.getParser(enterpriseNumber.getValue().intValue());
         if (parser == null) {
             if (!header.isProcessingRule()) {
                 return Optional.empty();
@@ -54,11 +54,11 @@ public class SimpleVendorInformationObjectRegistry implements VendorInformationO
 
     @Override
     public void serializeVendorInformationObject(final VendorInformationObject viObject, final ByteBuf buffer) {
-        final ObjectSerializer serializer = this.handlers.getSerializer(viObject.getEnterpriseSpecificInformation().getImplementedInterface());
+        final ObjectSerializer serializer = this.handlers.getSerializer(
+            viObject.getEnterpriseSpecificInformation().implementedInterface());
         if (serializer == null) {
             return;
         }
         serializer.serializeObject(viObject, buffer);
     }
-
 }