public void register(Class type, Serializer serializer) {
   if (type == null) {
     throw new IllegalArgumentException("Class type information is required!");
   }
   if (serializer.getTypeId() <= 0) {
     throw new IllegalArgumentException(
         "Type id must be positive! Current: "
             + serializer.getTypeId()
             + ", Serializer: "
             + serializer);
   }
   safeRegister(type, createSerializerAdapter(serializer));
 }
 public void registerGlobal(final Serializer serializer) {
   SerializerAdapter adapter = createSerializerAdapter(serializer);
   if (!global.compareAndSet(null, adapter)) {
     throw new IllegalStateException("Global serializer is already registered!");
   }
   SerializerAdapter current = idMap.putIfAbsent(serializer.getTypeId(), adapter);
   if (current != null && current.getImpl().getClass() != adapter.getImpl().getClass()) {
     global.compareAndSet(adapter, null);
     throw new IllegalStateException(
         "Serializer ["
             + current.getImpl()
             + "] has been already registered for type-id: "
             + serializer.getTypeId());
   }
 }