net.sf.ehcache.management.service.impl.CacheManagerConfigurationEntityBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache Show documentation
Show all versions of ehcache Show documentation
Ehcache is an open source, standards-based cache used to boost performance,
offload the database and simplify scalability. Ehcache is robust, proven and full-featured and
this has made it the most widely-used Java-based cache.
/*
* All content copyright (c) 2003-2012 Terracotta, Inc., except as may otherwise be noted in a separate copyright
* notice. All rights reserved.
*/
package net.sf.ehcache.management.service.impl;
import net.sf.ehcache.management.resource.CacheManagerConfigEntity;
import net.sf.ehcache.management.sampled.CacheManagerSampler;
import org.terracotta.management.resource.AgentEntity;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @author brandony
*/
final class CacheManagerConfigurationEntityBuilder {
private final List cmSamplers = new ArrayList();
static CacheManagerConfigurationEntityBuilder createWith(CacheManagerSampler sampler) {
return new CacheManagerConfigurationEntityBuilder(sampler);
}
private CacheManagerConfigurationEntityBuilder(CacheManagerSampler sampler) {
addSampler(sampler);
}
CacheManagerConfigurationEntityBuilder add(CacheManagerSampler sampler) {
addSampler(sampler);
return this;
}
Collection build() {
Collection cmces = new ArrayList(cmSamplers.size());
for (CacheManagerSampler sampler : cmSamplers) {
CacheManagerConfigEntity cmce = new CacheManagerConfigEntity();
cmce.setCacheManagerName(sampler.getName());
cmce.setAgentId(AgentEntity.EMBEDDED_AGENT_ID);
cmce.setVersion(this.getClass().getPackage().getImplementationVersion());
cmce.setXml(sampler.generateActiveConfigDeclaration());
cmces.add(cmce);
}
return cmces;
}
private void addSampler(CacheManagerSampler sampler) {
if (sampler == null) throw new IllegalArgumentException("sampler == null");
cmSamplers.add(sampler);
}
}