io.rainfall.jcache.CacheConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rainfall-jcache Show documentation
Show all versions of rainfall-jcache Show documentation
Rainfall-core is the core of the Rainfall framework
/*
* Copyright 2014 Aurélien Broszniowski
*
* 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 io.rainfall.jcache;
import io.rainfall.Configuration;
import io.rainfall.ObjectGenerator;
import io.rainfall.generator.IterationSequenceGenerator;
import io.rainfall.utils.ConcurrentPseudoRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.cache.Cache;
/**
* @author Aurelien Broszniowski
*/
public class CacheConfig extends Configuration {
private List> caches = new ArrayList>();
private ObjectGenerator keyGenerator = null;
private ObjectGenerator valueGenerator = null;
private IterationSequenceGenerator sequenceGenerator = null;
private ConcurrentPseudoRandom randomizer = new ConcurrentPseudoRandom();
public static CacheConfig cacheConfig() {
return new CacheConfig();
}
public CacheConfig caches(final Cache... caches) {
Collections.addAll(this.caches, caches);
return this;
}
public CacheConfig using(final ObjectGenerator keyGenerator, final ObjectGenerator valueGenerator) {
if (this.keyGenerator != null) {
throw new IllegalStateException("KeyGenerator already chosen.");
}
this.keyGenerator = keyGenerator;
if (this.valueGenerator != null) {
throw new IllegalStateException("ValueGenerator already chosen.");
}
this.valueGenerator = valueGenerator;
return this;
}
public CacheConfig sequentially() {
if (this.sequenceGenerator != null) {
throw new IllegalStateException("SequenceGenerator already chosen.");
}
this.sequenceGenerator = new IterationSequenceGenerator();
return this;
}
public List> getCaches() {
return caches;
}
public ObjectGenerator getKeyGenerator() {
return keyGenerator;
}
public ObjectGenerator getValueGenerator() {
return valueGenerator;
}
public IterationSequenceGenerator getSequenceGenerator() {
return sequenceGenerator;
}
public ConcurrentPseudoRandom getRandomizer() {
return randomizer;
}
@Override
public List getDescription() {
return Arrays.asList("Using " + caches.size() + " cache" + (caches.size() > 1 ? "s" : ""));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy