package org.ehcache.management.providers.settings;
import org.ehcache.CacheManager;
import org.ehcache.core.HumanReadable;
import org.ehcache.management.ManagementRegistryServiceConfiguration;
import org.ehcache.management.providers.CacheBinding;
import org.ehcache.management.providers.CacheBindingManagementProvider;
import org.terracotta.management.model.capabilities.descriptors.Descriptor;
import org.terracotta.management.model.capabilities.descriptors.Settings;
import org.terracotta.management.registry.Named;
import org.terracotta.management.registry.RequiredContext;
import java.util.ArrayList;
import java.util.Collection;
@Named("SettingsCapability")
@RequiredContext({@Named("cacheManagerName")})
public class EhcacheSettingsProvider extends CacheBindingManagementProvider {
private final ManagementRegistryServiceConfiguration configuration;
private final CacheManager cacheManager;
public EhcacheSettingsProvider(ManagementRegistryServiceConfiguration configuration, CacheManager cacheManager) {
super(configuration);
this.configuration = configuration;
this.cacheManager = cacheManager;
}
@Override
protected ExposedCacheSettings wrap(CacheBinding cacheBinding) {
return new ExposedCacheSettings(registryConfiguration, cacheBinding);
}
@Override
public Collection<? extends Descriptor> getDescriptors() {
Collection<Descriptor> descriptors = new ArrayList<>(super.getDescriptors());
descriptors.add(cacheManagerSettings());
return descriptors;
}
private Descriptor cacheManagerSettings() {
return new Settings()
.set("cacheManagerDescription", ((HumanReadable)cacheManager.getRuntimeConfiguration()).readableString())
.set("instanceId", configuration.getInstanceId())
.set("managementContext", new Settings(registryConfiguration.getContext()))
.set("tags", registryConfiguration.getTags().toArray(new String[0]));
}
}