Example usage for org.apache.hadoop.conf Configuration getBoolean

List of usage examples for org.apache.hadoop.conf Configuration getBoolean

Introduction

In this page you can find the example usage for org.apache.hadoop.conf Configuration getBoolean.

Prototype

public boolean getBoolean(String name, boolean defaultValue) 

Source Link

Document

Get the value of the name property as a boolean.

Usage

From source file:com.mongodb.hadoop.util.MapredMongoConfigUtil.java

License:Apache License

/**
 * If sharding is enabled, Use the sharding configured chunks to split up data.
 *//*  ww  w  .  j av a  2s . co  m*/
public static boolean isShardChunkedSplittingEnabled(final Configuration conf) {
    return conf.getBoolean(SPLITS_USE_CHUNKS, true);
}

From source file:com.mongodb.hadoop.util.MapredMongoConfigUtil.java

License:Apache License

public static boolean canReadSplitsFromSecondary(final Configuration conf) {
    return conf.getBoolean(SPLITS_SLAVE_OK, false);
}

From source file:com.mongodb.hadoop.util.MapredMongoConfigUtil.java

License:Apache License

public static void setReadSplitsFromSecondary(final Configuration conf, final boolean value) {
    conf.getBoolean(SPLITS_SLAVE_OK, value);
}

From source file:com.mongodb.hadoop.util.MapredMongoConfigUtil.java

License:Apache License

public static boolean createInputSplits(final Configuration conf) {
    return conf.getBoolean(CREATE_INPUT_SPLITS, true);
}

From source file:com.mongodb.hadoop.util.MapredMongoConfigUtil.java

License:Apache License

public static boolean isNoTimeout(final Configuration conf) {
    return conf.getBoolean(INPUT_NOTIMEOUT, false);
}

From source file:com.mongodb.hadoop.util.MapredMongoConfigUtil.java

License:Apache License

public static boolean getBSONReadSplits(final Configuration conf) {
    return conf.getBoolean(BSON_READ_SPLITS, true);
}

From source file:com.mongodb.hadoop.util.MapredMongoConfigUtil.java

License:Apache License

public static boolean getBSONWriteSplits(final Configuration conf) {
    return conf.getBoolean(BSON_WRITE_SPLITS, true);
}

From source file:com.mongodb.hadoop.util.MapredMongoConfigUtil.java

License:Apache License

public static boolean getBSONOutputBuildSplits(final Configuration conf) {
    return conf.getBoolean(BSON_OUTPUT_BUILDSPLITS, false);
}

From source file:com.moz.fiji.hadoop.configurator.ConfigurationMethod.java

License:Apache License

/**
 * Calls an object's method with the value read from a Configuration instance.
 *
 * @param instance The object to populate.
 * @param conf The configuration to read from.
 * @throws IllegalAccessException If the method cannot be called on the object.
 * @throws HadoopConfigurationException If there is a problem with the annotation definition.
 *///w w w .j  ava 2  s  .  c o  m
public void call(Object instance, Configuration conf) throws IllegalAccessException {
    final String key = getKey();
    if (null == key) {
        throw new HadoopConfigurationException("Missing 'key' attribute of @HadoopConf on "
                + instance.getClass().getName() + "." + mMethod.getName());
    }

    if (!mMethod.isAccessible()) {
        mMethod.setAccessible(true);
    }

    final Class<?>[] parameterTypes = mMethod.getParameterTypes();
    if (1 != parameterTypes.length) {
        throw new HadoopConfigurationException(
                "Methods annotated with @HadoopConf must have exactly one parameter: "
                        + instance.getClass().getName() + "." + mMethod.getName());
    }

    final Class<?> parameterType = parameterTypes[0];

    try {
        try {
            if (boolean.class == parameterType) {
                mMethod.invoke(instance, conf.getBoolean(key, Boolean.parseBoolean(getDefault())));
            } else if (float.class == parameterType) {
                mMethod.invoke(instance, conf.getFloat(key, Float.parseFloat(getDefault())));
            } else if (double.class == parameterType) {
                mMethod.invoke(instance, conf.getFloat(key, Float.parseFloat(getDefault())));
            } else if (int.class == parameterType) {
                mMethod.invoke(instance, conf.getInt(key, Integer.parseInt(getDefault())));
            } else if (long.class == parameterType) {
                mMethod.invoke(instance, conf.getLong(key, Long.parseLong(getDefault())));
            } else if (parameterType.isAssignableFrom(String.class)) {
                mMethod.invoke(instance, conf.get(key, getDefault()));
            } else if (parameterType.isAssignableFrom(Collection.class)) {
                mMethod.invoke(instance, conf.getStringCollection(key));
            } else if (String[].class == parameterType) {
                mMethod.invoke(instance, new Object[] { conf.getStrings(key) });
            } else {
                throw new HadoopConfigurationException(
                        "Unsupported method parameter type annotated by @HadoopConf: "
                                + instance.getClass().getName() + "." + mMethod.getName());
            }
        } catch (NumberFormatException e) {
            mMethod.invoke(instance, getDefault());
        }
    } catch (InvocationTargetException e) {
        throw new HadoopConfigurationException(e);
    }
}

From source file:com.moz.fiji.hadoop.configurator.ConfigurationVariable.java

License:Apache License

/**
 * Populates an object's field with the value read from a Configuration instance.
 *
 * @param instance The object to populate.
 * @param conf The configuration to read from.
 * @throws IllegalAccessException If the field cannot be set on the object.
 * @throws HadoopConfigurationException If there is a problem with the annotation definition.
 *//*  w  w w  .j av a  2  s . c o m*/
public void setValue(Object instance, Configuration conf) throws IllegalAccessException {
    final String key = getKey();
    if (null == key) {
        throw new HadoopConfigurationException("Missing 'key' attribute of @HadoopConf on "
                + instance.getClass().getName() + "." + mField.getName());
    }
    if (null == conf.get(key) && mAnnotation.defaultValue().isEmpty()) {
        // Nothing set in the configuration, and no default value
        // specified. Just leave the field alone.
        return;
    }

    if (!mField.isAccessible()) {
        mField.setAccessible(true);
    }

    try {
        if (boolean.class == mField.getType()) {
            mField.setBoolean(instance, conf.getBoolean(key, getDefaultBoolean(instance)));
        } else if (float.class == mField.getType()) {
            mField.setFloat(instance, conf.getFloat(key, getDefaultFloat(instance)));
        } else if (double.class == mField.getType()) {
            mField.setDouble(instance, conf.getFloat(key, getDefaultDouble(instance)));
        } else if (int.class == mField.getType()) {
            mField.setInt(instance, conf.getInt(key, getDefaultInt(instance)));
        } else if (long.class == mField.getType()) {
            mField.setLong(instance, conf.getLong(key, getDefaultLong(instance)));
        } else if (mField.getType().isAssignableFrom(String.class)) {
            mField.set(instance, conf.get(key, getDefaultString(instance)));
        } else if (mField.getType().isAssignableFrom(Collection.class)) {
            mField.set(instance, conf.getStringCollection(key));
        } else if (String[].class == mField.getType()) {
            mField.set(instance, conf.getStrings(key));
        } else {
            throw new HadoopConfigurationException("Unsupported field type annotated by @HadoopConf: "
                    + instance.getClass().getName() + "." + mField.getName());
        }
    } catch (NumberFormatException e) {
        // That's okay. The default value for the field will be kept.
    }
}