2015-02-17 12:26:41 +01:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
2015-03-24 13:06:06 +01:00
|
|
|
package org.elasticsearch.watcher.condition;
|
2015-02-17 12:26:41 +01:00
|
|
|
|
|
|
|
import org.elasticsearch.common.inject.AbstractModule;
|
|
|
|
import org.elasticsearch.common.inject.multibindings.MapBinder;
|
2015-04-14 18:27:34 -07:00
|
|
|
import org.elasticsearch.watcher.condition.always.AlwaysCondition;
|
|
|
|
import org.elasticsearch.watcher.condition.always.AlwaysConditionFactory;
|
2015-05-18 22:06:48 +02:00
|
|
|
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
|
|
|
import org.elasticsearch.watcher.condition.compare.CompareConditionFactory;
|
2015-04-14 18:27:34 -07:00
|
|
|
import org.elasticsearch.watcher.condition.never.NeverCondition;
|
|
|
|
import org.elasticsearch.watcher.condition.never.NeverConditionFactory;
|
|
|
|
import org.elasticsearch.watcher.condition.script.ScriptCondition;
|
|
|
|
import org.elasticsearch.watcher.condition.script.ScriptConditionFactory;
|
2015-02-17 12:26:41 +01:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ConditionModule extends AbstractModule {
|
|
|
|
|
2015-04-14 18:27:34 -07:00
|
|
|
private final Map<String, Class<? extends ConditionFactory>> factories = new HashMap<>();
|
2015-02-17 12:26:41 +01:00
|
|
|
|
2015-04-14 18:27:34 -07:00
|
|
|
public void registerCondition(String type, Class<? extends ConditionFactory> factoryType) {
|
|
|
|
factories.put(type, factoryType);
|
2015-02-17 12:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void configure() {
|
|
|
|
|
2015-04-14 18:27:34 -07:00
|
|
|
MapBinder<String, ConditionFactory> factoriesBinder = MapBinder.newMapBinder(binder(), String.class, ConditionFactory.class);
|
|
|
|
|
|
|
|
bind(ScriptConditionFactory.class).asEagerSingleton();
|
|
|
|
factoriesBinder.addBinding(ScriptCondition.TYPE).to(ScriptConditionFactory.class);
|
|
|
|
|
|
|
|
bind(NeverConditionFactory.class).asEagerSingleton();
|
|
|
|
factoriesBinder.addBinding(NeverCondition.TYPE).to(NeverConditionFactory.class);
|
|
|
|
|
|
|
|
bind(AlwaysConditionFactory.class).asEagerSingleton();
|
|
|
|
factoriesBinder.addBinding(AlwaysCondition.TYPE).to(AlwaysConditionFactory.class);
|
2015-02-17 12:26:41 +01:00
|
|
|
|
2015-05-18 22:06:48 +02:00
|
|
|
bind(CompareConditionFactory.class).asEagerSingleton();
|
|
|
|
factoriesBinder.addBinding(CompareCondition.TYPE).to(CompareConditionFactory.class);
|
|
|
|
|
2015-04-14 18:27:34 -07:00
|
|
|
for (Map.Entry<String, Class<? extends ConditionFactory>> entry : factories.entrySet()) {
|
2015-02-17 12:26:41 +01:00
|
|
|
bind(entry.getValue()).asEagerSingleton();
|
2015-04-14 18:27:34 -07:00
|
|
|
factoriesBinder.addBinding(entry.getKey()).to(entry.getValue());
|
2015-02-17 12:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bind(ConditionRegistry.class).asEagerSingleton();
|
|
|
|
}
|
|
|
|
}
|