All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.client.hotrod.impl.MarshallerRegistry Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.client.hotrod.impl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.infinispan.client.hotrod.logging.Log;
import org.infinispan.client.hotrod.logging.LogFactory;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.commons.marshall.Marshaller;

/**
 * A registry of {@link Marshaller} along with its {@link MediaType}.
 *
 * @since 9.3
 */
public final class MarshallerRegistry {

   public static final Log log = LogFactory.getLog(MarshallerRegistry.class, Log.class);

   private final Map marshallerByMediaType = new ConcurrentHashMap<>();

   public void registerMarshaller(Marshaller marshaller) {
      marshallerByMediaType.put(marshaller.mediaType().withoutParameters(), marshaller);
   }

   public Marshaller getMarshaller(MediaType mediaType) {
      return marshallerByMediaType.get(mediaType);
   }

   public Marshaller getMarshaller(Class marshallerClass) {
      return marshallerByMediaType.values().stream()
            .filter(m -> m.getClass() == marshallerClass).findFirst().orElse(null);
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy