com.ringcentral.platform.metrics.infoProviders.ConcurrentMaskTreeMetricNamedInfoProvider Maven / Gradle / Ivy
The newest version!
package com.ringcentral.platform.metrics.infoProviders;
import com.ringcentral.platform.metrics.names.MetricNamed;
import com.ringcentral.platform.metrics.predicates.MetricNamedPredicate;
import java.util.List;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Predicate;
public class ConcurrentMaskTreeMetricNamedInfoProvider
extends MaskTreeMetricNamedInfoProvider
implements ConcurrentMetricNamedInfoProvider {
private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
@Override
public MaskTreeMetricNamedInfoProvider addInfo(String key, MetricNamedPredicate predicate, I info) {
try {
rwLock.writeLock().lock();
return super.addInfo(key, predicate, info);
} finally {
rwLock.writeLock().unlock();
}
}
@Override
public MaskTreeMetricNamedInfoProvider removeInfo(String key) {
try {
rwLock.writeLock().lock();
return super.removeInfo(key);
} finally {
rwLock.writeLock().unlock();
}
}
@Override
public PredicativeMetricNamedInfoProvider removeInfos(Predicate keyPredicate) {
try {
rwLock.writeLock().lock();
return super.removeInfos(keyPredicate);
} finally {
rwLock.writeLock().unlock();
}
}
@Override
public List infosFor(MetricNamed named) {
try {
rwLock.readLock().lock();
return super.infosFor(named);
} finally {
rwLock.readLock().unlock();
}
}
}