use of org.apache.commons.daemon.DaemonInitException in project incubator-rya by apache.
the class QueryManagerDaemon method init.
@Override
public void init(final DaemonContext context) throws DaemonInitException, Exception {
requireNonNull(context);
// Parse the command line arguments for the configuration file to use.
final String[] args = context.getArguments();
final DaemonParameters params = new DaemonParameters();
try {
new JCommander(params).parse(args);
} catch (final ParameterException e) {
throw new DaemonInitException("Unable to parse the command line arguments.", e);
}
final Path configFile = params.config != null ? Paths.get(params.config) : DEFAULT_CONFIGURATION_PATH;
log.info("Loading the following configuration file: " + configFile);
// Unmarshall the configuration file into an object.
final QueryManagerConfig config;
try (final InputStream stream = Files.newInputStream(configFile)) {
config = QueryManagerConfigUnmarshaller.unmarshall(stream);
} catch (final JAXBException | SAXException e) {
throw new DaemonInitException("Unable to marshall the configuration XML file: " + configFile, e);
}
// Read the source polling period from the configuration.
final QueryChanngeLogDiscoveryPeriod periodConfig = config.getPerformanceTunning().getQueryChanngeLogDiscoveryPeriod();
final long period = periodConfig.getValue().longValue();
final TimeUnit units = TimeUnit.valueOf(periodConfig.getUnits().toString());
log.info("Query Change Log Polling Period: " + period + " " + units);
final Scheduler scheduler = Scheduler.newFixedRateSchedule(0, period, units);
// Initialize a QueryChangeLogSource.
final Kafka kafka = config.getQueryChangeLogSource().getKafka();
log.info("Kafka Source: " + kafka.getHostname() + ":" + kafka.getPort());
final QueryChangeLogSource source = new KafkaQueryChangeLogSource(kafka.getHostname(), kafka.getPort(), scheduler);
// Initialize a QueryExecutor.
final String zookeeperServers = config.getQueryExecutor().getLocalKafkaStreams().getZookeepers();
final KafkaStreamsFactory streamsFactory = new SingleThreadKafkaStreamsFactory(kafka.getHostname() + ":" + kafka.getPort());
final QueryExecutor queryExecutor = new LocalQueryExecutor(new CreateKafkaTopic(zookeeperServers), streamsFactory);
// Initialize the QueryManager using the configured resources.
manager = new QueryManager(queryExecutor, source, period, units);
}
Aggregations