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

org.ehcache.impl.config.BaseCacheConfiguration Maven / Gradle / Ivy

There is a newer version: 3.3.1
Show newest version
/*
 * Copyright Terracotta, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ehcache.impl.config;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.ehcache.config.CacheConfiguration;
import org.ehcache.config.EvictionAdvisor;
import org.ehcache.config.ResourcePools;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.core.config.ExpiryUtils;
import org.ehcache.expiry.ExpiryPolicy;
import org.ehcache.spi.service.ServiceConfiguration;

import static org.ehcache.config.builders.CacheConfigurationBuilder.newCacheConfigurationBuilder;

/**
 * Base implementation of {@link CacheConfiguration}.
 */
public class BaseCacheConfiguration implements CacheConfiguration {

  private final Class keyType;
  private final Class valueType;
  private final EvictionAdvisor evictionAdvisor;
  private final Collection> serviceConfigurations;
  private final ClassLoader classLoader;
  private final ExpiryPolicy expiry;
  private final ResourcePools resourcePools;

  /**
   * Creates a new {@code BaseCacheConfiguration} from the given parameters.
   *
   * @param keyType the key type
   * @param valueType the value type
   * @param evictionAdvisor the eviction advisor
   * @param classLoader the class loader
   * @param expiry the expiry policy
   * @param resourcePools the resource pools
   * @param serviceConfigurations the service configurations
   */
  public BaseCacheConfiguration(Class keyType, Class valueType,
          EvictionAdvisor evictionAdvisor,
          ClassLoader classLoader, ExpiryPolicy expiry,
          ResourcePools resourcePools, ServiceConfiguration... serviceConfigurations) {
    if (keyType == null) {
      throw new NullPointerException("keyType cannot be null");
    }
    if (valueType == null) {
      throw new NullPointerException("valueType cannot be null");
    }
    if (resourcePools == null) {
      throw new NullPointerException("resourcePools cannot be null");
    }
    this.keyType = keyType;
    this.valueType = valueType;
    this.evictionAdvisor = evictionAdvisor;
    this.classLoader = classLoader;
    if (expiry != null) {
      this.expiry = expiry;
    } else {
      this.expiry = ExpiryPolicy.NO_EXPIRY;
    }
    this.resourcePools = resourcePools;
    this.serviceConfigurations = Collections.unmodifiableCollection(Arrays.asList(serviceConfigurations));
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public Collection> getServiceConfigurations() {
    return serviceConfigurations;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public Class getKeyType() {
    return keyType;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public Class getValueType() {
    return valueType;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public EvictionAdvisor getEvictionAdvisor() {
    return evictionAdvisor;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public ClassLoader getClassLoader() {
    return classLoader;
  }

  /**
   * {@inheritDoc}
   */
  @SuppressWarnings("deprecation")
  @Override
  public org.ehcache.expiry.Expiry getExpiry() {
    return ExpiryUtils.convertToExpiry(expiry);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public ExpiryPolicy getExpiryPolicy() {
    return expiry;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public ResourcePools getResourcePools() {
    return resourcePools;
  }

  @Override
  public CacheConfigurationBuilder derive() {
    return newCacheConfigurationBuilder(this);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy