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());
   }
 }
 private void safeRegister(final Class type, final SerializerAdapter serializer) {
   if (constantTypesMap.containsKey(type)) {
     throw new IllegalArgumentException("[" + type + "] serializer cannot be overridden!");
   }
   SerializerAdapter current = typeMap.putIfAbsent(type, serializer);
   if (current != null && current.getImpl().getClass() != serializer.getImpl().getClass()) {
     throw new IllegalStateException(
         "Serializer[" + current.getImpl() + "] has been already registered for type: " + type);
   }
   current = idMap.putIfAbsent(serializer.getTypeId(), serializer);
   if (current != null && current.getImpl().getClass() != serializer.getImpl().getClass()) {
     throw new IllegalStateException(
         "Serializer ["
             + current.getImpl()
             + "] has been already registered for type-id: "
             + serializer.getTypeId());
   }
 }