Register rule stats by class
Since we can now register the same rule in multiple
places when migrating existing optimizers incrementally,
we need to avoid registering the same rule twice to
prevent conflicts when constructing objectnames
@@ -25,25 +25,25 @@ import java.util.Map;
public class StatsRecorder
{
- private final Map<Rule, RuleStats> stats = new HashMap<>();
+ private final Map<Class<?>, RuleStats> stats = new HashMap<>();
public void registerAll(Collection<Rule> rules)
{
for (Rule rule : rules) {
- stats.put(rule, new RuleStats());
+ stats.put(rule.getClass(), new RuleStats());
}
}
public void record(Rule rule, long nanos, boolean match)
{
- stats.get(rule).record(nanos, match);
+ stats.get(rule.getClass()).record(nanos, match);
}
void export(MBeanExporter exporter)
{
- for (Map.Entry<Rule, RuleStats> entry : stats.entrySet()) {
+ for (Map.Entry<Class<?>, RuleStats> entry : stats.entrySet()) {
String name = ObjectNames.builder(IterativeOptimizer.class)
- .withProperty("rule", entry.getKey().getClass().getSimpleName())
+ .withProperty("rule", entry.getKey().getSimpleName())
.build();
exporter.export(name, entry.getValue());
@@ -52,9 +52,9 @@ public class StatsRecorder
void unexport(MBeanExporter exporter)
{
- for (Rule rule : stats.keySet()) {
+ for (Class<?> rule : stats.keySet()) {
String name = ObjectNames.builder(IterativeOptimizer.class)
- .withProperty("rule", rule.getClass().getSimpleName())
+ .withProperty("rule", rule.getSimpleName())
.build();
exporter.unexport(name);
