Example usage for org.apache.spark.network TransportContext createClientFactory

List of usage examples for org.apache.spark.network TransportContext createClientFactory

Introduction

In this page you can find the example usage for org.apache.spark.network TransportContext createClientFactory.

Prototype

public TransportClientFactory createClientFactory(List<TransportClientBootstrap> bootstraps) 

Source Link

Document

Initializes a ClientFactory which runs the given TransportClientBootstraps prior to returning a new Client.

Usage

From source file:org.apache.carbondata.spark.dictionary.client.SecureDictionaryClient.java

License:Apache License

/**
 * start dictionary client//from  w w w . ja v  a  2 s. c  om
 *
 * @param address
 * @param port
 */
@Override
public void startClient(String secretKey, String address, int port, boolean encryptSecureServer) {
    LOGGER.info("Starting client on " + address + " " + port);
    long start = System.currentTimeMillis();

    SecurityManager securityMgr;
    SparkConf conf = new SparkConf().setAppName("Carbon Dictionary Client");

    conf.set("spark.authenticate", "true");

    if (null != secretKey) {
        conf.set("spark.authenticate.secret", secretKey);
    }

    if (encryptSecureServer) {
        conf.set("spark.authenticate.enableSaslEncryption", "true");
    }

    TransportConf transportConf = SparkTransportConf.fromSparkConf(conf, "Carbon Dictionary Client", 0);
    if (null != secretKey) {
        securityMgr = new SecurityManager(conf,
                scala.Option.apply(secretKey.getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET))));
    } else {
        securityMgr = new SecurityManager(conf, null);
    }

    TransportContext context = new TransportContext(transportConf, dictionaryClientHandler);
    clientFactory = context.createClientFactory(Lists.<TransportClientBootstrap>newArrayList(
            new SaslClientBootstrap(transportConf, "Carbon Dictionary Client", securityMgr)));

    try {
        client = clientFactory.createClient(address, port);
    } catch (Exception e) {
        LOGGER.error("Dictionary Client Failed to bind to port:", e);
    }
    LOGGER.info("Dictionary client Started, Total time spent : " + (System.currentTimeMillis() - start));
}