public static void startSchedule() {
Config config = ConfigFactory.load().getConfig(COORDINATOR);
String host = config.getString(METADATA_SERVICE_HOST);
int port = config.getInt(METADATA_SERVICE_PORT);
String context = config.getString(METADATA_SERVICE_CONTEXT);
IMetadataServiceClient client = new MetadataServiceClientImpl(host, port, context);
long initDelayMillis = config.getLong(DYNAMIC_POLICY_LOADER_INIT_MILLS);
long delayMillis = config.getLong(DYNAMIC_POLICY_LOADER_DELAY_MILLS);
ScheduledExecutorService scheduleSrv = Executors.newScheduledThreadPool(2, r -> {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
});
DynamicPolicyLoader loader = new DynamicPolicyLoader(client);
loader.addPolicyChangeListener(new PolicyChangeHandler(config, client));
scheduleSrv.scheduleAtFixedRate(loader, initDelayMillis, delayMillis, TimeUnit.MILLISECONDS);
if (config.hasPath(DYNAMIC_SCHEDULE_STATE_CLEAR_MIN) && config.hasPath(DYNAMIC_SCHEDULE_STATE_RESERVE_CAPACITY)) {
int period = config.getInt(DYNAMIC_SCHEDULE_STATE_CLEAR_MIN);
int capacity = config.getInt(DYNAMIC_SCHEDULE_STATE_RESERVE_CAPACITY);
ScheduleStateCleaner cleaner = new ScheduleStateCleaner(client, capacity);
scheduleSrv.scheduleAtFixedRate(cleaner, period, period, TimeUnit.MINUTES);
}
Runtime.getRuntime().addShutdownHook(new Thread(new CoordinatorShutdownHook(scheduleSrv)));
LOG.info("Eagle Coordinator started ...");
}