Example usage for org.apache.commons.configuration Configuration getBoolean

List of usage examples for org.apache.commons.configuration Configuration getBoolean

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getBoolean.

Prototype

Boolean getBoolean(String key, Boolean defaultValue);

Source Link

Document

Get a Boolean associated with the given configuration key.

Usage

From source file:net.sf.jclal.evaluation.method.AbstractEvaluationMethod.java

/**
 *
 * @param configuration The configuration object for Abstract Evaluation
 * Method.//from  w  w  w  .ja  v a  2s.c  o  m
 *
 *The XML labels supported are:
 *
 * <ul>
 * <li>
 * <b>rand-gen-factory type= class</b>
 * <p>
 * Package: net.sf.jclal.util.random
 * </p>
 * <p>
 * Class: All
 * </p>
 * </li>
 * <li>
 * <b>sampling-method type= class</b>
 * <p>
 * Package: net.sf.jclal.sampling
 * </p>
 * <p>
 * Class: All
 * </p>
 * </li>
 * <li><b>multi-label= boolean</b></li>
 * <li><b>multi-instance= boolean</b></li>
 * <li><b>file-dataset= String</b></li>
 * <li><b>file-train= String</b></li>
 * <li><b>file-test= String</b></li>
 * <li><b>file-labeled= String</b></li>
 * <li><b>file-unlabeled= String</b></li>
 * <li><b>class-attribute= int</b></li>
 * <li>
 * <b>algorithm type= class</b>
 * <p>
 * Package: net.sf.jclal.activelearning
 * </p>
 * <p>
 * Class: All
 * </p>
 * </li>
 * <li><b>file-xml= String</b>: If the dataset is multi label</li>
 * </ul>
 */
@Override
public void configure(Configuration configuration) {

    setRandGenSettings(configuration);

    // Set multiLabel flag
    boolean multi = configuration.getBoolean("multi-label", false);
    setMultiLabel(multi);

    // Set multiInstance flag
    boolean multiInstance = configuration.getBoolean("multi-instance", false);
    setMultiInstance(multiInstance);

    // Set the xml file, it is used in the case of a multi-label
    // dataset
    String xml = configuration.getString("file-xml", "");
    setXmlPath(xml);

    //the multi-label elements are verified
    if (multi && xml.isEmpty()) {
        throw new ConfigurationRuntimeException(
                "\nThe multi-label flag is " + "enabled and the xml path is empty. "
                        + "<multi-label>true</multi-label>" + " <file-xml></file-xml>");
    }

    // Set file dataset (default "")
    String fileDatasetT = configuration.getString("file-dataset", "");
    setFileDataset(fileDatasetT);

    if (fileDataset.isEmpty()) {
        // Set file train
        String fileTrain = configuration.getString("file-train", "");
        setFileTrainDataset(fileTrain);
        // Set file test
        String fileTest = configuration.getString("file-test", "");
        setFileTestDataset(fileTest);

        if (fileTest.isEmpty()) {
            throw new ConfigurationRuntimeException("\n If <file-dataset> tag is not specified,"
                    + " then the <file-test> tags must be defined.");
        }

        if (fileTrain.isEmpty()) {

            // Set file labeled
            String fileLabeled = configuration.getString("file-labeled", "");
            setFileLabeledDataset(fileLabeled);

            // Set file labeled
            String fileUnlabeled = configuration.getString("file-unlabeled", "");
            setFileUnlabeledDataset(fileUnlabeled);

            if (fileLabeled.isEmpty() || fileUnlabeled.isEmpty()) {
                throw new ConfigurationRuntimeException(
                        "\n If <file-dataset> and " + " <file-train> tags are not specified,"
                                + " then the <file-labeled> and <file-unlabeled> tags must be defined.");
            }

        }
    }

    // Set class attribute
    int classAttributeT = configuration.getInt("class-attribute", -1);

    setClassAttribute(classAttributeT);

    //Set the configuration of the sampling method
    setSamplingStrategyConfiguration(configuration);

    setAlgorithmSettings(configuration);

}

From source file:dk.dma.ais.abnormal.analyzer.analysis.SpeedOverGroundAnalysis.java

@Inject
public SpeedOverGroundAnalysis(Configuration configuration, AppStatisticsService statisticsService,
        StatisticDataRepository statisticsRepository, EventEmittingTracker trackingService,
        EventRepository eventRepository, BehaviourManager behaviourManager) {
    super(eventRepository, statisticsRepository, trackingService, behaviourManager);
    this.statisticsService = statisticsService;

    setTrackPredictionTimeMax(configuration.getInteger(CONFKEY_ANALYSIS_SOG_PREDICTIONTIME_MAX, -1));

    TOTAL_SHIP_COUNT_THRESHOLD = configuration.getInt(CONFKEY_ANALYSIS_SOG_CELL_SHIPCOUNT_MIN, 1000);
    PD = configuration.getFloat(CONFKEY_ANALYSIS_SOG_PD, 0.001f);
    SHIP_LENGTH_MIN = configuration.getInt(CONFKEY_ANALYSIS_SOG_SHIPLENGTH_MIN, 50);
    USE_AGGREGATED_STATS = configuration.getBoolean(CONFKEY_ANALYSIS_SOG_USE_AGGREGATED_STATS, false);

    LOG.info(getAnalysisName() + " created (" + this + ").");
}

From source file:dk.dma.ais.abnormal.analyzer.analysis.CourseOverGroundAnalysis.java

@Inject
public CourseOverGroundAnalysis(Configuration configuration, AppStatisticsService statisticsService,
        StatisticDataRepository statisticsRepository, EventEmittingTracker trackingService,
        EventRepository eventRepository, BehaviourManager behaviourManager) {
    super(eventRepository, statisticsRepository, trackingService, behaviourManager);
    this.statisticsService = statisticsService;
    setTrackPredictionTimeMax(configuration.getInteger(CONFKEY_ANALYSIS_COG_PREDICTIONTIME_MAX, -1));

    TOTAL_SHIP_COUNT_THRESHOLD = configuration.getInt(CONFKEY_ANALYSIS_COG_CELL_SHIPCOUNT_MIN, 1000);
    PD = configuration.getFloat(CONFKEY_ANALYSIS_COG_PD, 0.001f);
    SHIP_LENGTH_MIN = configuration.getInt(CONFKEY_ANALYSIS_COG_SHIPLENGTH_MIN, 50);
    USE_AGGREGATED_STATS = configuration.getBoolean(CONFKEY_ANALYSIS_COG_USE_AGGREGATED_STATS, false);

    LOG.info(getAnalysisName() + " created (" + this + ").");
}

From source file:net.sf.jclal.listener.ClassicalReporterListener.java

/**
 *
 * @param configuration The configuration of Classical Reporter Listener.
 *
 * The XML labels supported are:/*from   w w w. j  av a 2  s. c  om*/
 *
 * <ul>
 * <li><b>report-title= String</b>, default= untitled</li>
 * <li><b>report-directory= String</b>, default= reports</li>
 * <li><b>report-frequency= int</b></li>
 * <li><b>report-on-console= boolean</b></li>
 * <li><b>report-on-file= boolean</b></li>
 * <li><b>send-email= class</b>
 * <p>
 * Package: net.sf.jclal.util.mail</p>
 * Class: All
 * </li>
 * </ul>
 */
@Override
public void configure(Configuration configuration) {

    // Set report title (default "untitled")
    String reportTitleT = configuration.getString("report-title", reportTitle);
    setReportTitle(reportTitleT);

    // Set report title (default "reports/")
    String reportDirectoryT = configuration.getString("report-directory", reportDirectory);
    setReportDirectory(reportDirectoryT);

    // Set report frequency (default 1 iteration)
    int reportFrequencyT = configuration.getInt("report-frequency", reportFrequency);
    setReportFrequency(reportFrequencyT);

    // Set console report (default on)
    boolean reportOnConsoleT = configuration.getBoolean("report-on-console", reportOnConsole);
    setReportOnConsole(reportOnConsoleT);

    // Set file report (default off)
    boolean reportOnFileT = configuration.getBoolean("report-on-file", reportOnFile);
    setReportOnFile(reportOnFileT);

    String sendError = "send-email type= ";
    try {

        String senderEmailClassname = configuration.getString("send-email[@type]");
        sendError += senderEmailClassname;
        //If a email sender was especified
        if (senderEmailClassname != null) {
            // sender email class
            Class<?> senderEmailClass = Class.forName(senderEmailClassname);

            SenderEmail senderEmailT = (SenderEmail) senderEmailClass.newInstance();

            // Configure listener (if necessary)
            if (senderEmailT instanceof IConfigure) {
                ((IConfigure) senderEmailT).configure(configuration.subset("send-email"));
            }

            setSenderEmail(senderEmailT);
        }

    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("\nIllegal sender email classname: " + sendError, e);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("\nIllegal sender email classname: " + sendError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("\nIllegal sender email classname: " + sendError, e);
    }
}

From source file:com.linkedin.pinot.controller.helix.core.rebalance.ReplicaGroupRebalanceSegmentStrategy.java

/**
 * Rebalance the segments for replica group tables.
 * @param idealState old ideal state/*from  w w  w  .  jav  a  2  s  . c  o  m*/
 * @param tableConfig table config of table tor rebalance
 * @param rebalanceUserConfig custom user configs for specific rebalance strategies
 * @param newPartitionAssignment new rebalaned partition assignments as part of the resource rebalance
 * @return a rebalanced idealstate
 */
@Override
public IdealState rebalanceIdealState(IdealState idealState, TableConfig tableConfig,
        Configuration rebalanceUserConfig, PartitionAssignment newPartitionAssignment)
        throws InvalidConfigException {
    // Currently, only offline table is supported
    if (tableConfig.getTableType() == CommonConstants.Helix.TableType.REALTIME) {
        throw new InvalidConfigException("Realtime table is not supported by replica group rebalancer");
    }
    ReplicaGroupPartitionAssignment newReplicaGroupPartitionAssignment = (ReplicaGroupPartitionAssignment) newPartitionAssignment;
    String tableNameWithType = tableConfig.getTableName();

    // update if not dryRun
    boolean dryRun = rebalanceUserConfig.getBoolean(RebalanceUserConfigConstants.DRYRUN,
            RebalanceUserConfigConstants.DEFAULT_DRY_RUN);
    IdealState newIdealState;
    if (!dryRun) {
        LOGGER.info("Updating ideal state for table {}", tableNameWithType);
        newIdealState = rebalanceSegmentsAndUpdateIdealState(tableConfig, newReplicaGroupPartitionAssignment);
    } else {
        newIdealState = rebalanceSegments(idealState, tableConfig, newReplicaGroupPartitionAssignment);
        LOGGER.info("Dry run. Skip writing ideal state");
    }

    return newIdealState;
}

From source file:com.linkedin.pinot.controller.helix.core.rebalance.DefaultRebalanceSegmentStrategy.java

/**
 * Rebalance partition assignment only for realtime tables, and if includeConsuming=true
 * @param idealState old ideal state/*  ww  w  .  ja  v a  2s.  c o m*/
 * @param tableConfig table config of table tor rebalance
 * @param rebalanceUserConfig custom user configs for specific rebalance strategies
 * @return
 */
@Override
public PartitionAssignment rebalancePartitionAssignment(IdealState idealState, TableConfig tableConfig,
        Configuration rebalanceUserConfig) throws InvalidConfigException {
    String tableNameWithType = tableConfig.getTableName();
    PartitionAssignment newPartitionAssignment = new PartitionAssignment(tableNameWithType);

    if (tableConfig.getTableType().equals(CommonConstants.Helix.TableType.REALTIME)) {
        StreamMetadata streamMetadata = new StreamMetadata(tableConfig.getIndexingConfig().getStreamConfigs());
        if (streamMetadata.hasHighLevelKafkaConsumerType()) {
            LOGGER.info("Table {} uses HLC and will have no partition assignment", tableNameWithType);
            return newPartitionAssignment;
        }

        LOGGER.info("Rebalancing stream partition assignment for table {}", tableConfig.getTableName());

        boolean includeConsuming = rebalanceUserConfig
                .getBoolean(RebalanceUserConfigConstants.INCLUDE_CONSUMING, DEFAULT_INCLUDE_CONSUMING);
        if (includeConsuming) {

            PartitionAssignmentGenerator partitionAssignmentGenerator = new PartitionAssignmentGenerator(
                    _helixManager);
            PartitionAssignment partitionAssignmentFromIdealState = partitionAssignmentGenerator
                    .getPartitionAssignmentFromIdealState(tableConfig, idealState);
            int numPartitions = partitionAssignmentFromIdealState.getNumPartitions();
            newPartitionAssignment = partitionAssignmentGenerator.generatePartitionAssignment(tableConfig,
                    numPartitions);

        } else {
            LOGGER.info("includeConsuming = false. No need to rebalance partition assignment for {}",
                    tableConfig.getTableType());
        }
    }
    return newPartitionAssignment;
}

From source file:com.linkedin.pinot.controller.helix.core.rebalance.DefaultRebalanceSegmentStrategy.java

/**
 * If realtime table and includeConsuming=true, rebalance consuming segments. NewPartitionAssignment will be used only in this case
 * Always rebalance completed (online) segments, NewPartitionAssignment unused in this case
 * @param idealState old ideal state//  w ww .j av  a2  s. c  o m
 * @param tableConfig table config of table tor rebalance
 * @param rebalanceUserConfig custom user configs for specific rebalance strategies
 * @param newPartitionAssignment new rebalanced partition assignments as part of the resource rebalance
 * @return
 */
@Override
public IdealState rebalanceIdealState(IdealState idealState, TableConfig tableConfig,
        Configuration rebalanceUserConfig, PartitionAssignment newPartitionAssignment) {

    String tableNameWithType = tableConfig.getTableName();
    CommonConstants.Helix.TableType tableType = tableConfig.getTableType();
    LOGGER.info("Rebalancing ideal state for table {}", tableNameWithType);

    // get target num replicas
    int targetNumReplicas;
    if (tableType.equals(CommonConstants.Helix.TableType.REALTIME)) {
        String replicasString = tableConfig.getValidationConfig().getReplicasPerPartition();
        try {
            targetNumReplicas = Integer.parseInt(replicasString);
        } catch (Exception e) {
            throw new RuntimeException("Invalid value for replicasPerPartition:'" + replicasString + "'", e);
        }
    } else {
        targetNumReplicas = Integer.parseInt(tableConfig.getValidationConfig().getReplication());
    }

    // update if not dryRun
    boolean dryRun = rebalanceUserConfig.getBoolean(RebalanceUserConfigConstants.DRYRUN, DEFAULT_DRY_RUN);
    IdealState newIdealState;
    if (!dryRun) {
        LOGGER.info("Updating ideal state for table {}", tableNameWithType);
        newIdealState = rebalanceAndUpdateIdealState(tableConfig, targetNumReplicas, rebalanceUserConfig,
                newPartitionAssignment);
    } else {
        LOGGER.info("Dry run. Skip writing ideal state");
        newIdealState = rebalanceIdealState(idealState, tableConfig, targetNumReplicas, rebalanceUserConfig,
                newPartitionAssignment);
    }
    return newIdealState;
}

From source file:edu.berkeley.sparrow.daemon.scheduler.Scheduler.java

public void initialize(Configuration conf, InetSocketAddress socket) throws IOException {
    address = Network.socketAddressToThrift(socket);
    String mode = conf.getString(SparrowConf.DEPLYOMENT_MODE, "unspecified");
    this.conf = conf;
    if (mode.equals("standalone")) {
        state = new StandaloneSchedulerState();
    } else if (mode.equals("configbased")) {
        state = new ConfigSchedulerState();
    } else {//  w ww.  ja v a  2s  .com
        throw new RuntimeException("Unsupported deployment mode: " + mode);
    }

    state.initialize(conf);

    defaultProbeRatioUnconstrained = conf.getDouble(SparrowConf.SAMPLE_RATIO, SparrowConf.DEFAULT_SAMPLE_RATIO);
    defaultProbeRatioConstrained = conf.getDouble(SparrowConf.SAMPLE_RATIO_CONSTRAINED,
            SparrowConf.DEFAULT_SAMPLE_RATIO_CONSTRAINED);

    requestTaskPlacers = Maps.newConcurrentMap();

    useCancellation = conf.getBoolean(SparrowConf.CANCELLATION, SparrowConf.DEFAULT_CANCELLATION);
    if (useCancellation) {
        LOG.debug("Initializing cancellation service");
        cancellationService = new CancellationService(nodeMonitorClientPool);
        new Thread(cancellationService).start();
    } else {
        LOG.debug("Not using cancellation");
    }

    spreadEvenlyTaskSetSize = conf.getInt(SparrowConf.SPREAD_EVENLY_TASK_SET_SIZE,
            SparrowConf.DEFAULT_SPREAD_EVENLY_TASK_SET_SIZE);
}

From source file:com.linkedin.pinot.controller.helix.core.rebalance.ReplicaGroupRebalanceSegmentStrategy.java

/**
 * Rebalance partition assignment for replica group tables.
 * @param idealState old ideal state/*from  w  ww  .j  a  v  a  2  s.  c  o  m*/
 * @param tableConfig table config of table tor rebalance
 * @param rebalanceUserConfig custom user configs for specific rebalance strategies
 * @return a rebalanced replica group partition assignment
 */
@Override
public PartitionAssignment rebalancePartitionAssignment(IdealState idealState, TableConfig tableConfig,
        Configuration rebalanceUserConfig) throws InvalidConfigException {
    // Currently, only offline table is supported
    if (tableConfig.getTableType() == CommonConstants.Helix.TableType.REALTIME) {
        throw new InvalidConfigException("Realtime table is not supported by replica group rebalancer");
    }

    String tableNameWithType = tableConfig.getTableName();
    LOGGER.info("Rebalancing replica group partition assignment for table {}", tableNameWithType);

    ReplicaGroupPartitionAssignmentGenerator partitionAssignmentGenerator = new ReplicaGroupPartitionAssignmentGenerator(
            _propertyStore);

    // Compute new replica group partition assignment
    ReplicaGroupPartitionAssignment newPartitionAssignment = computeNewReplicaGroupMapping(tableConfig,
            partitionAssignmentGenerator);

    boolean dryRun = rebalanceUserConfig.getBoolean(RebalanceUserConfigConstants.DRYRUN,
            RebalanceUserConfigConstants.DEFAULT_DRY_RUN);
    if (!dryRun) {
        LOGGER.info("Updating replica group partition assignment for table {}", tableNameWithType);
        partitionAssignmentGenerator.writeReplicaGroupPartitionAssignment(newPartitionAssignment);
    } else {
        LOGGER.info("Dry run. Skip writing replica group partition assignment to property store");
    }

    return newPartitionAssignment;
}

From source file:com.caricah.iotracah.datastore.ignitecache.IgniteDatastore.java

/**
 * <code>configure</code> allows the base system to configure itself by getting
 * all the settings it requires and storing them internally. The plugin is only expected to
 * pick the settings it has registered on the configuration file for its particular use.
 *
 * @param configuration/* w  ww  .j  av  a2s.  c  om*/
 * @throws UnRetriableException
 */
@Override
public void configure(Configuration configuration) throws UnRetriableException {

    try {

        String driver = configuration.getString(CONFIG_IGNITECACHE_PERSITENCE_DRIVER_NAME,
                CONFIG_IGNITECACHE_PERSITENCE_DRIVER_NAME_VALUE_DEFAULT);
        String url = configuration.getString(CONFIG_IGNITECACHE_PERSITENCE_DB_URL,
                CONFIG_IGNITECACHE_PERSITENCE_DB_URL_VALUE_DEFAULT);
        String username = configuration.getString(CONFIG_IGNITECACHE_PERSITENCE_DB_USERNAME,
                CONFIG_IGNITECACHE_PERSITENCE_DB_USERNAME_VALUE_DEFAULT);
        String password = configuration.getString(CONFIG_IGNITECACHE_PERSITENCE_DB_PASSWORD,
                CONFIG_IGNITECACHE_PERSITENCE_DB_PASSWORD_VALUE_DEFAULT);

        IotDataSource.getInstance().setupDatasource(driver, url, username, password);

        boolean persistanceIsEnabled = configuration.getBoolean(CONFIG_IGNITECACHE_PERSITENCE_ENABLED,
                CONFIG_IGNITECACHE_PERSITENCE_ENABLED_VALUE_DEFAULT);
        setPersistanceEnabled(persistanceIsEnabled);

        partitionHandler.configure(configuration);

        subscriptionFilterHandler.configure(configuration);

        subscriptionHandler.configure(configuration);

        messageHandler.configure(configuration);

        retainedMessageHandler.configure(configuration);

        accountHandler.configure(configuration);

        roleHandler.configure(configuration);

        clientHandler.configure(configuration);

    } catch (NamingException e) {
        throw new UnRetriableException(e);
    }
}