Example usage for org.apache.commons.daemon DaemonInitException DaemonInitException

List of usage examples for org.apache.commons.daemon DaemonInitException DaemonInitException

Introduction

In this page you can find the example usage for org.apache.commons.daemon DaemonInitException DaemonInitException.

Prototype

public DaemonInitException(String message, Throwable cause) 

Source Link

Usage

From source file:SimpleDaemon.java

/**
 * init and destroy were added in jakarta-tomcat-daemon.
 *///from  ww  w . j a  v  a2  s .  com
public void init(DaemonContext context) throws Exception {
    System.err.println("SimpleDaemon: instance " + this.hashCode() + " init");

    int port = 1200;

    String[] a = context.getArguments();
    try {
        if (a.length > 0)
            port = Integer.parseInt(a[0]);
    } catch (NumberFormatException ex) {
        throw new DaemonInitException("parsing port", ex);
    }
    if (a.length > 1)
        this.directory = a[1];
    else
        this.directory = "/tmp";

    /* Dump a message */
    System.err.println("SimpleDaemon: loading on port " + port);

    /* Set up this simple daemon */
    this.controller = context.getController();
    this.server = new ServerSocket(port);
    this.thread = new Thread(this);
}

From source file:com.amazonaws.codepipeline.jobworker.JobWorkerDaemon.java

private void loadConfiguration(final String[] arguments) throws DaemonInitException {
    if (arguments.length == 1) {
        final String configurationClassName = arguments[0];
        try {//from  w ww . j a  va  2  s . co  m
            final JobWorkerConfiguration jobWorkerConfiguration = (JobWorkerConfiguration) Class
                    .forName(configurationClassName).newInstance();
            initConfiguration(jobWorkerConfiguration);
        } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException
                | ClassCastException | RegionNotFoundException e) {
            throw new DaemonInitException(
                    String.format("Provided job worker configuration class '%s' could not be loaded.",
                            configurationClassName),
                    e);
        }
    }
}

From source file:org.apache.rya.streams.querymanager.QueryManagerDaemon.java

@Override
public void init(final DaemonContext context) throws DaemonInitException, Exception {
    requireNonNull(context);/*from   w w w  .j a  v  a 2s  .com*/

    // 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);
}