Do not fall back to default Kryo serializers
[controller.git] / third-party / atomix / storage / src / main / java / io / atomix / utils / serializer / Namespace.java
index 6ebd044c9d98ed808e2987ec01d73349ce961652..f62ba084ca901fa339e6d35aeb1cb67dc6d2c8bb 100644 (file)
@@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableList;
 import org.apache.commons.lang3.tuple.Pair;
 import org.objenesis.strategy.StdInstantiatorStrategy;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -39,8 +40,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.slf4j.LoggerFactory.getLogger;
+import static java.util.Objects.requireNonNull;
 
 /**
  * Pool of Kryo instances, with classes pre-registered.
@@ -72,7 +72,7 @@ public final class Namespace implements KryoFactory, KryoPool {
 
   static final String NO_NAME = "(no name)";
 
-  private static final Logger LOGGER = getLogger(Namespace.class);
+  private static final Logger LOGGER = LoggerFactory.getLogger(Namespace.class);
 
   /**
    * Default Kryo namespace.
@@ -151,19 +151,6 @@ public final class Namespace implements KryoFactory, KryoPool {
       return this;
     }
 
-    /**
-     * Registers classes to be serialized using Kryo default serializer.
-     *
-     * @param expectedTypes list of classes
-     * @return this
-     */
-    public Builder register(final Class<?>... expectedTypes) {
-      for (Class<?> clazz : expectedTypes) {
-        types.add(Pair.of(new Class<?>[]{clazz}, null));
-      }
-      return this;
-    }
-
     /**
      * Registers serializer for the given set of classes.
      * <p>
@@ -175,42 +162,7 @@ public final class Namespace implements KryoFactory, KryoPool {
      * @return this
      */
     public Builder register(Serializer<?> serializer, final Class<?>... classes) {
-      types.add(Pair.of(classes, checkNotNull(serializer)));
-      return this;
-    }
-
-    private Builder register(RegistrationBlock block) {
-      if (block.begin() != FLOATING_ID) {
-        // flush pending types
-        nextId(block.begin());
-        blocks.add(block);
-        nextId(block.begin() + block.types().size());
-      } else {
-        // flush pending types
-        final int addedBlockBegin = blockHeadId + types.size();
-        nextId(addedBlockBegin);
-        blocks.add(new RegistrationBlock(addedBlockBegin, block.types()));
-        nextId(addedBlockBegin + block.types().size());
-      }
-      return this;
-    }
-
-    /**
-     * Registers all the class registered to given KryoNamespace.
-     *
-     * @param ns KryoNamespace
-     * @return this
-     */
-    public Builder register(final Namespace ns) {
-
-      if (blocks.containsAll(ns.registeredBlocks)) {
-        // Everything was already registered.
-        LOGGER.debug("Ignoring {}, already registered.", ns);
-        return this;
-      }
-      for (RegistrationBlock block : ns.registeredBlocks) {
-        this.register(block);
-      }
+      types.add(Pair.of(classes, requireNonNull(serializer)));
       return this;
     }
 
@@ -279,7 +231,7 @@ public final class Namespace implements KryoFactory, KryoPool {
     this.registrationRequired = registrationRequired;
     this.classLoader = classLoader;
     this.compatible = compatible;
-    this.friendlyName = checkNotNull(friendlyName);
+    this.friendlyName = requireNonNull(friendlyName);
   }
 
   /**