io.github.icodegarden.commons.lang.metrics.NamesCachedInstanceMetrics Maven / Gradle / Ivy
package io.github.icodegarden.commons.lang.metrics;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import io.github.icodegarden.commons.lang.NamesCachedObjectReader;
import io.github.icodegarden.commons.lang.registry.RegisteredInstance;
/**
*
* 只关注给定的serviceNames
*
* @author Fangfang.Xu
*
*/
public class NamesCachedInstanceMetrics implements InstanceMetrics {
private final InstanceMetrics extends Metrics> delegator;
private final NamesCachedObjectReader namesCachedObjectReader;
public NamesCachedInstanceMetrics(List serviceNames, InstanceMetrics extends Metrics> delegator,
long cacheRefreshIntervalMillis) throws IllegalArgumentException {
if (serviceNames == null || serviceNames.isEmpty()) {
throw new IllegalArgumentException("serviceNames must not empty");
}
if (delegator == null) {
throw new IllegalArgumentException("param delegator must not null");
}
this.delegator = delegator;
namesCachedObjectReader = new NamesCachedObjectReader(serviceNames, delegator, cacheRefreshIntervalMillis);
}
@Override
public List listNamedObjects(String serviceName) {
return (List) namesCachedObjectReader.listNamedObjects(serviceName);
}
@Override
public void setMetrics(T instance, Metrics metrics) {
delegator.setMetrics(instance, metrics);
}
@Override
public Metrics getMetrics(T instance) {
return delegator.getMetrics(instance);
}
@Override
public void removeMetrics(T instance) {
delegator.removeMetrics(instance);
}
/**
* 停止调度
*/
@Override
public void close() throws IOException {
namesCachedObjectReader.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy