org.swisspush.gateleen.scheduler.SchedulerFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gateleen-scheduler Show documentation
Show all versions of gateleen-scheduler Show documentation
Middleware library based on Vert.x to build advanced JSON/REST communication servers
The newest version!
package org.swisspush.gateleen.scheduler;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.vertx.redis.RedisClient;
import org.swisspush.gateleen.core.http.HttpRequest;
import org.swisspush.gateleen.monitoring.MonitoringHandler;
import org.swisspush.gateleen.core.util.StringUtils;
import org.swisspush.gateleen.validation.ValidationException;
import org.swisspush.gateleen.validation.ValidationResult;
import org.swisspush.gateleen.validation.Validator;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* SchedulerFactory is used to create scheduler objects from their text representation.
*
* @author https://github.com/mcweba [Marc-Andre Weber]
*/
public class SchedulerFactory {
private static final String HEADERS = "headers";
private static final String PAYLOAD = "payload";
private static final String REQUESTS = "requests";
private static final String SCHEDULERS = "schedulers";
private final Map properties;
private Vertx vertx;
private RedisClient redisClient;
private MonitoringHandler monitoringHandler;
private String schedulersSchema;
private Logger log = LoggerFactory.getLogger(SchedulerFactory.class);
public SchedulerFactory(Map properties, Vertx vertx, RedisClient redisClient, MonitoringHandler monitoringHandler, String schedulersSchema) {
this.properties = properties;
this.vertx = vertx;
this.redisClient = redisClient;
this.monitoringHandler = monitoringHandler;
this.schedulersSchema = schedulersSchema;
}
public List parseSchedulers(Buffer buffer) throws ValidationException {
List result = new ArrayList<>();
String configString;
try {
configString = StringUtils.replaceWildcardConfigs(buffer.toString("UTF-8"), properties);
} catch(Exception e){
throw new ValidationException(e);
}
ValidationResult validationResult = Validator.validateStatic(Buffer.buffer(configString), schedulersSchema, log);
if(!validationResult.isSuccess()){
throw new ValidationException(validationResult);
}
JsonObject mainObject = new JsonObject(configString);
for(Map.Entry entry: mainObject.getJsonObject(SCHEDULERS).getMap().entrySet()) {
Map schedulerJson = (Map)entry.getValue();
List requests = new ArrayList<>();
for(int i = 0; i< ((ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy