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

net.sf.ehcache.management.service.impl.CacheManagerConfigurationEntityBuilder Maven / Gradle / Ivy

Go to download

A product library implementing the ehcache management resource service interfaces and integrating with ehcache to construct the relevant management resource entities.

The newest version!
/*
 * 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);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy