Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature-25363 : Deprecating size based cache at heap tier #3038

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* This exception is thrown when {@link SizeOfEngine} reaches one of the limits defined in configuration while sizing
* the object on heap.
*/
@Deprecated
public class LimitExceededException extends Exception {

private static final long serialVersionUID = -4689090295854830331L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* <p>
* Implementations are expected to be linked to {@link Store} implementations.
*/
@Deprecated
public interface SizeOfEngine {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/**
* {@link Service} responsible for providing {@link SizeOfEngine}.
*/
@Deprecated
public interface SizeOfEngineProvider extends Service {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.ehcache.config.units.MemoryUnit;
import org.ehcache.impl.config.BaseCacheConfiguration;
import org.ehcache.core.config.store.StoreEventSourceConfiguration;
import org.ehcache.core.spi.store.heap.SizeOfEngine;
import org.ehcache.expiry.ExpiryPolicy;
import org.ehcache.impl.config.copy.DefaultCopierConfiguration;
import org.ehcache.impl.config.event.DefaultCacheEventDispatcherConfiguration;
Expand All @@ -35,7 +34,6 @@
import org.ehcache.impl.config.serializer.DefaultSerializerConfiguration;
import org.ehcache.impl.config.store.disk.OffHeapDiskStoreConfiguration;
import org.ehcache.impl.copy.SerializingCopier;
import org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration;
import org.ehcache.spi.copy.Copier;
import org.ehcache.spi.loaderwriter.CacheLoaderWriter;
import org.ehcache.spi.resilience.ResilienceStrategy;
Expand All @@ -54,9 +52,6 @@
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import static org.ehcache.core.config.ExpiryUtils.convertToExpiryPolicy;
import static org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_MAX_OBJECT_SIZE;
import static org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_OBJECT_GRAPH_SIZE;
import static org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_UNIT;


/**
Expand Down Expand Up @@ -528,29 +523,30 @@ public CacheConfigurationBuilder<K, V> withDefaultDiskStoreThreadPool() {
}

/**
* Adds or updates the {@link DefaultSizeOfEngineConfiguration} with the specified object graph maximum size to the configured
* Adds or updates the {@link org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration} with the specified object graph maximum size to the configured
* builder.
* <p>
* {@link SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}.
* {@link org.ehcache.core.spi.store.heap.SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}.
*
* @param size the maximum graph size
* @return a new builder with the added / updated configuration
*
* @see #withSizeOfMaxObjectSize(long, MemoryUnit)
* @see #withDefaultSizeOfSettings()
*/
@Deprecated
public CacheConfigurationBuilder<K, V> withSizeOfMaxObjectGraph(long size) {
return installOrUpdate(
() -> new DefaultSizeOfEngineConfiguration(DEFAULT_MAX_OBJECT_SIZE, DEFAULT_UNIT, size),
existing -> new DefaultSizeOfEngineConfiguration(existing.getMaxObjectSize(), existing.getUnit(), size)
() -> new org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration(org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_MAX_OBJECT_SIZE, org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_UNIT, size),
existing -> new org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration(existing.getMaxObjectSize(), existing.getUnit(), size)
);
}

/**
* Adds or updates the {@link DefaultSizeOfEngineConfiguration} with the specified maximum mapping size to the configured
* Adds or updates the {@link org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration} with the specified maximum mapping size to the configured
* builder.
* <p>
* {@link SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}.
* {@link org.ehcache.core.spi.store.heap.SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}.
*
* @param size the maximum mapping size
* @param unit the memory unit
Expand All @@ -559,10 +555,11 @@ public CacheConfigurationBuilder<K, V> withSizeOfMaxObjectGraph(long size) {
* @see #withSizeOfMaxObjectGraph(long)
* @see #withDefaultSizeOfSettings()
*/
@Deprecated
public CacheConfigurationBuilder<K, V> withSizeOfMaxObjectSize(long size, MemoryUnit unit) {
return installOrUpdate(
() -> new DefaultSizeOfEngineConfiguration(size, unit, DEFAULT_OBJECT_GRAPH_SIZE),
existing -> new DefaultSizeOfEngineConfiguration(size, unit, existing.getMaxObjectGraphSize())
() -> new org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration(size, unit, org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_OBJECT_GRAPH_SIZE),
existing -> new org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration(size, unit, existing.getMaxObjectGraphSize())
);
}

Expand All @@ -574,8 +571,9 @@ public CacheConfigurationBuilder<K, V> withSizeOfMaxObjectSize(long size, Memory
* @see #withSizeOfMaxObjectGraph(long)
* @see #withSizeOfMaxObjectSize(long, MemoryUnit)
*/
@Deprecated
public CacheConfigurationBuilder<K, V> withDefaultSizeOfSettings() {
return withoutServices(DefaultSizeOfEngineConfiguration.class);
return withoutServices(org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
import org.ehcache.config.FluentConfigurationBuilder;
import org.ehcache.config.units.MemoryUnit;
import org.ehcache.core.EhcacheManager;
import org.ehcache.core.spi.store.heap.SizeOfEngine;
import org.ehcache.impl.config.copy.DefaultCopyProviderConfiguration;
import org.ehcache.impl.config.event.CacheEventDispatcherFactoryConfiguration;
import org.ehcache.impl.config.loaderwriter.writebehind.WriteBehindProviderConfiguration;
import org.ehcache.impl.config.persistence.CacheManagerPersistenceConfiguration;
import org.ehcache.impl.config.serializer.DefaultSerializationProviderConfiguration;
import org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration;
import org.ehcache.impl.config.store.disk.OffHeapDiskStoreProviderConfiguration;
import org.ehcache.spi.copy.Copier;
import org.ehcache.spi.serialization.Serializer;
Expand All @@ -47,9 +45,6 @@
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableSet;
import static org.ehcache.config.builders.ConfigurationBuilder.newConfigurationBuilder;
import static org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_MAX_OBJECT_SIZE;
import static org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_OBJECT_GRAPH_SIZE;
import static org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_UNIT;

/**
* The {@code CacheManagerBuilder} enables building cache managers using a fluent style.
Expand Down Expand Up @@ -222,31 +217,33 @@ public <C> CacheManagerBuilder<T> withSerializer(Class<C> clazz, Class<? extends
}

/**
* Adds a default {@link SizeOfEngine} configuration, that limits the max object graph to
* Adds a default {@link org.ehcache.core.spi.store.heap.SizeOfEngine} configuration, that limits the max object graph to
* size, to the returned builder.
*
* @param size the max object graph size
* @return a new builder with the added configuration
*/
@Deprecated
public CacheManagerBuilder<T> withDefaultSizeOfMaxObjectGraph(long size) {
return ensureThenUpdate(
() -> new DefaultSizeOfEngineProviderConfiguration(DEFAULT_MAX_OBJECT_SIZE, DEFAULT_UNIT, DEFAULT_OBJECT_GRAPH_SIZE),
existing -> new DefaultSizeOfEngineProviderConfiguration(existing.getMaxObjectSize(), existing.getUnit(), size)
() -> new org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration(org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_MAX_OBJECT_SIZE, org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_UNIT, org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_OBJECT_GRAPH_SIZE),
existing -> new org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration(existing.getMaxObjectSize(), existing.getUnit(), size)
);
}

/**
* Adds a default {@link SizeOfEngine} configuration, that limits the max object size, to
* Adds a default {@link org.ehcache.core.spi.store.heap.SizeOfEngine} configuration, that limits the max object size, to
* the returned builder.
*
* @param size the max object size
* @param unit the max object size unit
* @return a new builder with the added configuration
*/
@Deprecated
public CacheManagerBuilder<T> withDefaultSizeOfMaxObjectSize(long size, MemoryUnit unit) {
return ensureThenUpdate(
() -> new DefaultSizeOfEngineProviderConfiguration(DEFAULT_MAX_OBJECT_SIZE, DEFAULT_UNIT, DEFAULT_OBJECT_GRAPH_SIZE),
existing -> new DefaultSizeOfEngineProviderConfiguration(size, unit, existing.getMaxObjectGraphSize())
() -> new org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration(org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_MAX_OBJECT_SIZE, org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_UNIT, org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_OBJECT_GRAPH_SIZE),
existing -> new org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration(size, unit, existing.getMaxObjectGraphSize())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.ehcache.config.ResourceType;
import org.ehcache.config.ResourceUnit;
import org.ehcache.config.units.MemoryUnit;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import org.ehcache.core.spi.ServiceLocator;
import org.ehcache.core.spi.service.DiskResourceService;
import org.ehcache.core.spi.store.Store;
import org.ehcache.core.spi.store.heap.SizeOfEngine;
import org.ehcache.core.spi.store.heap.SizeOfEngineProvider;
import org.ehcache.core.store.StoreConfigurationImpl;
import org.ehcache.core.store.StoreSupport;
import org.ehcache.core.util.ClassLoading;
Expand All @@ -51,7 +49,6 @@
import org.ehcache.impl.config.copy.DefaultCopierConfiguration;
import org.ehcache.impl.config.loaderwriter.DefaultCacheLoaderWriterConfiguration;
import org.ehcache.impl.config.serializer.DefaultSerializerConfiguration;
import org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration;
import org.ehcache.impl.copy.SerializingCopier;
import org.ehcache.impl.events.CacheEventDispatcherImpl;
import org.ehcache.impl.internal.events.DisabledCacheEventNotificationService;
Expand Down Expand Up @@ -87,9 +84,6 @@
import static org.ehcache.config.builders.ResourcePoolsBuilder.newResourcePoolsBuilder;
import static org.ehcache.core.spi.ServiceLocator.dependencySet;
import static org.ehcache.core.spi.service.ServiceUtils.findSingletonAmongst;
import static org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_MAX_OBJECT_SIZE;
import static org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_OBJECT_GRAPH_SIZE;
import static org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_UNIT;

/**
* The {@code UserManagedCacheBuilder} enables building {@link UserManagedCache}s using a fluent style.
Expand Down Expand Up @@ -131,9 +125,13 @@ public class UserManagedCacheBuilder<K, V, T extends UserManagedCache<K, V>> imp
private List<CacheEventListenerConfiguration<?>> eventListenerConfigurations = new ArrayList<>();
private ExecutorService unOrderedExecutor;
private ExecutorService orderedExecutor;
private long objectGraphSize = DEFAULT_OBJECT_GRAPH_SIZE;
private long maxObjectSize = DEFAULT_MAX_OBJECT_SIZE;
private MemoryUnit sizeOfUnit = DEFAULT_UNIT;

@SuppressWarnings("deprecation")
private long objectGraphSize = org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_OBJECT_GRAPH_SIZE;
@SuppressWarnings("deprecation")
private long maxObjectSize = org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_MAX_OBJECT_SIZE;
@SuppressWarnings("deprecation")
private MemoryUnit sizeOfUnit = org.ehcache.impl.config.store.heap.DefaultSizeOfEngineConfiguration.DEFAULT_UNIT;


UserManagedCacheBuilder(final Class<K> keyType, final Class<V> valueType) {
Expand Down Expand Up @@ -727,38 +725,40 @@ public UserManagedCacheBuilder<K, V, T> withValueSerializer(Serializer<V> valueS
}

/**
* Adds or updates the {@link DefaultSizeOfEngineProviderConfiguration} with the specified object graph maximum size to the configured
* Adds or updates the {@link org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration} with the specified object graph maximum size to the configured
* builder.
* <p>
* {@link SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}.
* {@link org.ehcache.core.spi.store.heap.SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}.
*
* @param size the maximum graph size
* @return a new builder with the added / updated configuration
*/
@Deprecated
public UserManagedCacheBuilder<K, V, T> withSizeOfMaxObjectGraph(long size) {
UserManagedCacheBuilder<K, V, T> otherBuilder = new UserManagedCacheBuilder<>(this);
removeAnySizeOfEngine(otherBuilder);
otherBuilder.objectGraphSize = size;
otherBuilder.serviceCreationConfigurations.add(new DefaultSizeOfEngineProviderConfiguration(otherBuilder.maxObjectSize, otherBuilder.sizeOfUnit, otherBuilder.objectGraphSize));
otherBuilder.serviceCreationConfigurations.add(new org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration(otherBuilder.maxObjectSize, otherBuilder.sizeOfUnit, otherBuilder.objectGraphSize));
return otherBuilder;
}

/**
* Adds or updates the {@link DefaultSizeOfEngineProviderConfiguration} with the specified maximum mapping size to the configured
* Adds or updates the {@link org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration} with the specified maximum mapping size to the configured
* builder.
* <p>
* {@link SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}.
* {@link org.ehcache.core.spi.store.heap.SizeOfEngine} is what enables the heap tier to be sized in {@link MemoryUnit}.
*
* @param size the maximum mapping size
* @param unit the memory unit
* @return a new builder with the added / updated configuration
*/
@Deprecated
public UserManagedCacheBuilder<K, V, T> withSizeOfMaxObjectSize(long size, MemoryUnit unit) {
UserManagedCacheBuilder<K, V, T> otherBuilder = new UserManagedCacheBuilder<>(this);
removeAnySizeOfEngine(otherBuilder);
otherBuilder.maxObjectSize = size;
otherBuilder.sizeOfUnit = unit;
otherBuilder.serviceCreationConfigurations.add(new DefaultSizeOfEngineProviderConfiguration(otherBuilder.maxObjectSize, otherBuilder.sizeOfUnit, otherBuilder.objectGraphSize));
otherBuilder.serviceCreationConfigurations.add(new org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration(otherBuilder.maxObjectSize, otherBuilder.sizeOfUnit, otherBuilder.objectGraphSize));
return otherBuilder;
}

Expand Down Expand Up @@ -787,9 +787,10 @@ public static <K, V> UserManagedCacheBuilder<K, V, UserManagedCache<K, V>> newUs
*
* @see #using(ServiceCreationConfiguration)
*/
@SuppressWarnings("deprecation")
public UserManagedCacheBuilder<K, V, T> using(Service service) {
UserManagedCacheBuilder<K, V, T> otherBuilder = new UserManagedCacheBuilder<>(this);
if (service instanceof SizeOfEngineProvider) {
if (service instanceof org.ehcache.core.spi.store.heap.SizeOfEngineProvider) {
removeAnySizeOfEngine(otherBuilder);
}
otherBuilder.services.add(service);
Expand All @@ -810,18 +811,20 @@ public UserManagedCacheBuilder<K, V, T> using(Service service) {
*
* @see #using(Service)
*/
@SuppressWarnings("deprecation")
public UserManagedCacheBuilder<K, V, T> using(ServiceCreationConfiguration<?, ?> serviceConfiguration) {
UserManagedCacheBuilder<K, V, T> otherBuilder = new UserManagedCacheBuilder<>(this);
if (serviceConfiguration instanceof DefaultSizeOfEngineProviderConfiguration) {
if (serviceConfiguration instanceof org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration) {
removeAnySizeOfEngine(otherBuilder);
}
otherBuilder.serviceCreationConfigurations.add(serviceConfiguration);
return otherBuilder;
}

@Deprecated
private static void removeAnySizeOfEngine(UserManagedCacheBuilder<?, ?, ?> builder) {
builder.services.remove(findSingletonAmongst(SizeOfEngineProvider.class, builder.services));
builder.serviceCreationConfigurations.remove(findSingletonAmongst(DefaultSizeOfEngineProviderConfiguration.class, builder.serviceCreationConfigurations));
builder.services.remove(findSingletonAmongst(org.ehcache.core.spi.store.heap.SizeOfEngineProvider.class, builder.services));
builder.serviceCreationConfigurations.remove(findSingletonAmongst(org.ehcache.impl.config.store.heap.DefaultSizeOfEngineProviderConfiguration.class, builder.serviceCreationConfigurations));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import org.ehcache.config.ResourceType;
import org.ehcache.config.ResourceUnit;
import org.ehcache.config.SizedResourcePool;
import org.ehcache.config.units.MemoryUnit;
import org.ehcache.core.HumanReadable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Implementation of the {@link SizedResourcePool} interface.
Expand All @@ -30,6 +33,7 @@
public class SizedResourcePoolImpl<P extends SizedResourcePool> extends AbstractResourcePool<P, ResourceType<P>>
implements SizedResourcePool, HumanReadable {

private static final Logger LOGGER = LoggerFactory.getLogger(SizedResourcePoolImpl.class);
private final long size;
private final ResourceUnit unit;

Expand All @@ -52,6 +56,9 @@ public SizedResourcePoolImpl(ResourceType<P> type, long size, ResourceUnit unit,
if (!type.isPersistable() && persistent) {
throw new IllegalStateException("Non-persistable resource cannot be configured persistent");
}
if (type == org.ehcache.config.ResourceType.Core.HEAP && unit instanceof MemoryUnit){
LOGGER.info("Byte based heap resources are deprecated and will be removed in a future version.");
}
this.size = size;
this.unit = unit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package org.ehcache.impl.config.store.heap;

import org.ehcache.config.units.MemoryUnit;
import org.ehcache.core.spi.store.heap.SizeOfEngineProvider;
import org.ehcache.spi.service.ServiceConfiguration;

/**
* {@link ServiceConfiguration} for the default {@link SizeOfEngineProvider}.
* {@link ServiceConfiguration} for the default {@link org.ehcache.core.spi.store.heap.SizeOfEngineProvider}.
*/
public class DefaultSizeOfEngineConfiguration implements ServiceConfiguration<SizeOfEngineProvider, DefaultSizeOfEngineConfiguration> {
@Deprecated
public class DefaultSizeOfEngineConfiguration implements ServiceConfiguration<org.ehcache.core.spi.store.heap.SizeOfEngineProvider, DefaultSizeOfEngineConfiguration> {

/**
* Default maximum object graph count after which sizing stops
Expand Down Expand Up @@ -64,8 +64,8 @@ public DefaultSizeOfEngineConfiguration(long size, MemoryUnit unit, long objectG
* {@inheritDoc}
*/
@Override
public Class<SizeOfEngineProvider> getServiceType() {
return SizeOfEngineProvider.class;
public Class<org.ehcache.core.spi.store.heap.SizeOfEngineProvider> getServiceType() {
return org.ehcache.core.spi.store.heap.SizeOfEngineProvider.class;
}

/**
Expand Down
Loading