Java Code Examples for org.ehcache.spi.serialization.SerializationProvider

Following code examples demonstrate how to use org.ehcache.spi.serialization.SerializationProviderfrom ehcache. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.ehcache.spi.serialization.SerializationProviderand various code implementation of this class.

  public CacheConfigurationBuilder<K, V> withSerializationProvider(SerializationProvider serializationProvider) {
    this.serializationProvider = serializationProvider;
    return this;
  } 


  }

  public StoreConfigurationImpl(Class<K> keyType, Class<V> valueType, Comparable<Long> capacityConstraint,
          EvictionVeto<? super K, ? super V> evictionVeto, EvictionPrioritizer<? super K, ? super V> evictionPrioritizer,
          ClassLoader classLoader, Expiry<? super K, ? super V> expiry, SerializationProvider serializationProvider) {
    this.keyType = keyType;
    this.valueType = valueType;
    this.capacityConstraint = capacityConstraint;
    this.evictionVeto = evictionVeto;
    this.evictionPrioritizer = evictionPrioritizer;
    this.serializationProvider = serializationProvider;
    this.classLoader = classLoader;
    this.expiry = expiry;
  } 

  public void setup() throws UnsupportedTypeException {
    SerializationProvider provider = new DefaultSerializationProvider(null);
    provider.start(providerContaining());
    valueHolderPortability = new OffHeapValueHolderPortability<>(provider
      .createValueSerializer(String.class, getClass().getClassLoader()));

    originalValue = new BasicOffHeapValueHolder<>(-1, "aValue", 1L, 2L, 3L, 0);

  } 

  public DefaultSerializationProvider create(ServiceCreationConfiguration<SerializationProvider> configuration) {
    if (configuration != null && !(configuration instanceof DefaultSerializationProviderConfiguration)) {
      throw new IllegalArgumentException("Expected a configuration of type DefaultSerializationProviderConfiguration but got " + configuration
          .getClass()
          .getSimpleName());
    }
    return new DefaultSerializationProvider((DefaultSerializationProviderConfiguration) configuration);
  } 

Advertisement
Javadoc
A Service providing Serializer instances.

The CacheManager org.ehcache.spi.service.Servi

ceProvider obtains an instance of this Service prior to creating any Cache instances. Before creating each Cache instance, the CacheManager calls the #createKeySerializer(Class, ClassLoader, ServiceConfiguration[]) and #createValueSerializer(Class, ClassLoader, ServiceConfiguration[]) methods to obtain Serializer instances for the Cache, either through explicit configuration or from CacheManager level configuration.

Some Cache configurations make serialization mandatory. If serialization is mandatory, failure to return a Serializer from a SerializationProvider results in a Cache initialization failure. For a Cache in which serialization is not mandatory, failing to return a Serializer will not cause Cache initialization failure.

Read More
Advertisement