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

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

Introduction

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

Prototype

public Class<?> getClassByName(String name) throws ClassNotFoundException 

Source Link

Document

Load a class by name.

Usage

From source file:org.apache.hama.bsp.sync.SyncServiceFactory.java

License:Apache License

public static SyncClient getMasterSyncClient(Configuration conf) throws ClassNotFoundException {
    return (SyncClient) ReflectionUtils.newInstance(
            conf.getClassByName(conf.get(SYNC_MASTER_CLASS, ZKSyncBSPMasterClient.class.getName())), conf);
}

From source file:org.apache.hama.bsp.sync.SyncServiceFactory.java

License:Apache License

/**
 * Returns a sync server via reflection based on what was configured.
 *//*  w ww .  j av a 2  s  . c o  m*/
public static SyncServer getSyncServer(Configuration conf) throws ClassNotFoundException {
    return (SyncServer) ReflectionUtils.newInstance(conf.getClassByName(conf.get(SYNC_SERVER_CLASS,
            org.apache.hama.bsp.sync.ZooKeeperSyncServerImpl.class.getCanonicalName())), conf);
}

From source file:org.apache.hama.ipc.AsyncServer.java

License:Apache License

static Class<?> getProtocolClass(String protocolName, Configuration conf) throws ClassNotFoundException {
    Class<?> protocol = PROTOCOL_CACHE.get(protocolName);
    if (protocol == null) {
        protocol = conf.getClassByName(protocolName);
        PROTOCOL_CACHE.put(protocolName, protocol);
    }/* w w  w .  j a  v  a  2 s. c  o  m*/
    return protocol;
}

From source file:org.apache.hama.util.BSPNetUtils.java

License:Apache License

/**
 * Get the socket factory corresponding to the given proxy URI. If the given
 * proxy URI corresponds to an absence of configuration parameter, returns
 * null. If the URI is malformed raises an exception.
 * /*w  w  w.java2  s.co  m*/
 * @param propValue the property which is the class name of the SocketFactory
 *          to instantiate; assumed non null and non empty.
 * @return a socket factory as defined in the property value.
 */
public static SocketFactory getSocketFactoryFromProperty(Configuration conf, String propValue) {

    try {
        Class<?> theClass = conf.getClassByName(propValue);
        return (SocketFactory) org.apache.hadoop.util.ReflectionUtils.newInstance(theClass, conf);

    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException("Socket Factory class not found: " + cnfe);
    }
}

From source file:org.apache.hawq.pxf.plugins.hdfs.utilities.HdfsUtilities.java

License:Apache License

private static Class<? extends CompressionCodec> getCodecClass(Configuration conf, String name) {

    Class<? extends CompressionCodec> codecClass;
    try {//ww  w  .  ja v a 2  s.  c  o  m
        codecClass = conf.getClassByName(name).asSubclass(CompressionCodec.class);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("Compression codec " + name + " was not found.", e);
    }
    return codecClass;
}

From source file:org.apache.lens.lib.query.LensFileOutputFormat.java

License:Apache License

/**
 * Gets the output compressor class./*from   w  w  w  . ja  v  a2  s.c o m*/
 *
 * @param conf the conf
 * @return the output compressor class
 */
public static Class<? extends CompressionCodec> getOutputCompressorClass(Configuration conf) {
    Class<? extends CompressionCodec> codecClass;

    String name = conf.get(LensConfConstants.QUERY_OUTPUT_COMPRESSION_CODEC,
            LensConfConstants.DEFAULT_OUTPUT_COMPRESSION_CODEC);
    try {
        codecClass = conf.getClassByName(name).asSubclass(CompressionCodec.class);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("Compression codec " + name + " was not found.", e);
    }
    return codecClass;
}

From source file:org.apache.lens.server.api.driver.hooks.ChainedDriverQueryHook.java

License:Apache License

public static ChainedDriverQueryHook from(Configuration conf, String key) throws LensException {
    String[] classNames = conf.getStrings(key);
    List<DriverQueryHook> hooks = Lists.newArrayList();
    if (classNames != null) {
        for (String className : classNames) {
            Class<? extends DriverQueryHook> clazz;
            try {
                clazz = conf.getClassByName(className).asSubclass(DriverQueryHook.class);
            } catch (ClassNotFoundException e) {
                throw new LensException("Couldn't load class " + className, e);
            }//  www .j a v a  2 s.c  om
            DriverQueryHook instance;
            try {
                instance = clazz.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                throw new LensException("Couldn't create instance of class " + clazz.getName(), e);
            }
            if (instance instanceof Configurable) {
                ((Configurable) instance).setConf(conf);
            }
            hooks.add(instance);
        }
    }
    return new ChainedDriverQueryHook(hooks);
}

From source file:org.apache.lens.server.api.retry.ChainedRetryPolicyDecider.java

License:Apache License

public static <FC extends FailureContext> ChainedRetryPolicyDecider<FC> from(Configuration conf, String key)
        throws LensException {
    String[] classNames = conf.getStrings(key);
    List<RetryPolicyDecider<FC>> retryPolicyDeciders = Lists.newArrayList();
    if (classNames != null) {
        for (String className : classNames) {
            Class<? extends RetryPolicyDecider<FC>> clazz;
            try {
                clazz = (Class<? extends RetryPolicyDecider<FC>>) conf.getClassByName(className)
                        .asSubclass(RetryPolicyDecider.class);
            } catch (ClassNotFoundException e) {
                throw new LensException("Couldn't load class " + className, e);
            }/*from  www. j  a v  a  2s  . c o  m*/
            RetryPolicyDecider<FC> instance;
            try {
                instance = clazz.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                throw new LensException("Couldn't create instance of class " + clazz.getName(), e);
            }
            if (instance instanceof Configurable) {
                ((Configurable) instance).setConf(conf);
            }
            retryPolicyDeciders.add(instance);
        }
    }
    return new ChainedRetryPolicyDecider<>(retryPolicyDeciders);
}

From source file:org.apache.mahout.clustering.conversion.InputMapper.java

License:Apache License

@Override
protected void setup(Context context) throws IOException, InterruptedException {
    super.setup(context);
    Configuration conf = context.getConfiguration();
    String vectorImplClassName = conf.get("vector.implementation.class.name");
    try {//from w  w  w .j  a v  a2 s .c  o  m
        Class<? extends Vector> outputClass = conf.getClassByName(vectorImplClassName).asSubclass(Vector.class);
        constructor = outputClass.getConstructor(int.class);
    } catch (NoSuchMethodException e) {
        throw new IllegalStateException(e);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.apache.mahout.clustering.syntheticcontrol.canopy.InputMapper.java

License:Apache License

@Override
protected void setup(Context context) throws IOException, InterruptedException {
    super.setup(context);
    Configuration conf = context.getConfiguration();
    String vectorImplClassName = conf.get("vector.implementation.class.name");
    try {/* w  w w  . j  a  v a 2  s .c  o  m*/
        Class<? extends Vector> outputClass = conf.getClassByName(vectorImplClassName).asSubclass(Vector.class);
        constructor = outputClass.getConstructor(int.class);
    } catch (NoSuchMethodException e) {
        throw new IllegalStateException(e);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    }

}