Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.google.gerrit.server.plugins.PluginMetricMaker Maven / Gradle / Ivy
package com.google.gerrit.server.plugins;
import com.google.gerrit.extensions.events.LifecycleListener;
import com.google.gerrit.extensions.registration.RegistrationHandle;
import com.google.gerrit.metrics.CallbackMetric;
import com.google.gerrit.metrics.CallbackMetric0;
import com.google.gerrit.metrics.CallbackMetric1;
import com.google.gerrit.metrics.Counter0;
import com.google.gerrit.metrics.Counter1;
import com.google.gerrit.metrics.Counter2;
import com.google.gerrit.metrics.Counter3;
import com.google.gerrit.metrics.Description;
import com.google.gerrit.metrics.Field;
import com.google.gerrit.metrics.Histogram0;
import com.google.gerrit.metrics.Histogram1;
import com.google.gerrit.metrics.Histogram2;
import com.google.gerrit.metrics.Histogram3;
import com.google.gerrit.metrics.MetricMaker;
import com.google.gerrit.metrics.Timer0;
import com.google.gerrit.metrics.Timer1;
import com.google.gerrit.metrics.Timer2;
import com.google.gerrit.metrics.Timer3;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class PluginMetricMaker extends MetricMaker implements LifecycleListener {
private final MetricMaker root;
private final String prefix;
private final Set cleanup;
public PluginMetricMaker (MetricMaker root, String prefix) {
this .root = root;
this .prefix = prefix.endsWith("/" ) ? prefix : prefix + "/" ;
cleanup = Collections.synchronizedSet(new HashSet<>());
}
@Override
public Counter0 newCounter (String name, Description desc) {
Counter0 m = root.newCounter(prefix + name, desc);
cleanup.add(m);
return m;
}
@Override
public Counter1 newCounter (String name, Description desc, Field field1) {
Counter1 m = root.newCounter(prefix + name, desc, field1);
cleanup.add(m);
return m;
}
@Override
public Counter2 newCounter (
String name, Description desc, Field field1, Field field2) {
Counter2 m = root.newCounter(prefix + name, desc, field1, field2);
cleanup.add(m);
return m;
}
@Override
public Counter3 newCounter (
String name, Description desc, Field field1, Field field2, Field field3) {
Counter3 m = root.newCounter(prefix + name, desc, field1, field2, field3);
cleanup.add(m);
return m;
}
@Override
public Timer0 newTimer (String name, Description desc) {
Timer0 m = root.newTimer(prefix + name, desc);
cleanup.add(m);
return m;
}
@Override
public Timer1 newTimer (String name, Description desc, Field field1) {
Timer1 m = root.newTimer(prefix + name, desc, field1);
cleanup.add(m);
return m;
}
@Override
public Timer2 newTimer (
String name, Description desc, Field field1, Field field2) {
Timer2 m = root.newTimer(prefix + name, desc, field1, field2);
cleanup.add(m);
return m;
}
@Override
public Timer3 newTimer (
String name, Description desc, Field field1, Field field2, Field field3) {
Timer3 m = root.newTimer(prefix + name, desc, field1, field2, field3);
cleanup.add(m);
return m;
}
@Override
public Histogram0 newHistogram (String name, Description desc) {
Histogram0 m = root.newHistogram(prefix + name, desc);
cleanup.add(m);
return m;
}
@Override
public Histogram1 newHistogram (String name, Description desc, Field field1) {
Histogram1 m = root.newHistogram(prefix + name, desc, field1);
cleanup.add(m);
return m;
}
@Override
public Histogram2 newHistogram (
String name, Description desc, Field field1, Field field2) {
Histogram2 m = root.newHistogram(prefix + name, desc, field1, field2);
cleanup.add(m);
return m;
}
@Override
public Histogram3 newHistogram (
String name, Description desc, Field field1, Field field2, Field field3) {
Histogram3 m = root.newHistogram(prefix + name, desc, field1, field2, field3);
cleanup.add(m);
return m;
}
@Override
public CallbackMetric0 newCallbackMetric (
String name, Class valueClass, Description desc) {
CallbackMetric0 m = root.newCallbackMetric(prefix + name, valueClass, desc);
cleanup.add(m);
return m;
}
@Override
public CallbackMetric1 newCallbackMetric (
String name, Class valueClass, Description desc, Field field1) {
CallbackMetric1 m = root.newCallbackMetric(prefix + name, valueClass, desc, field1);
cleanup.add(m);
return m;
}
@Override
public RegistrationHandle newTrigger (Set > metrics, Runnable trigger) {
final RegistrationHandle handle = root.newTrigger(metrics, trigger);
cleanup.add(handle);
return () -> {
handle.remove();
cleanup.remove(handle);
};
}
@Override
public void start () {}
@Override
public void stop () {
synchronized (cleanup) {
Iterator itr = cleanup.iterator();
while (itr.hasNext()) {
itr.next().remove();
itr.remove();
}
}
}
}