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

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

Introduction

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

Prototype

public TransportServer createServer(String host, int port, List<TransportServerBootstrap> bootstraps) 

Source Link

Document

Create a server which will attempt to bind to a specific host and port.

Usage

From source file:org.apache.carbondata.spark.dictionary.server.SecureDictionaryServer.java

License:Apache License

/**
 * Binds dictionary server to an available port.
 *
 */// w  w  w .j a  va2 s  . c o  m
@Override
public void bindToPort() {
    long start = System.currentTimeMillis();
    // Configure the server.
    int i = 0;
    while (i < 10) {
        int newPort = port + i;
        try {
            SecurityManager securityManager;
            SparkConf conf = this.conf.clone();
            conf.setAppName("Carbon Dictionary Server");

            // As spark.network.sasl.serverAlwaysEncrypt is not exposed parameter
            // set it explicitly so that Dictionary Server and Client communication
            // occurs encrypted. The below parameter can be removed once spark Documents it.
            // conf.set("spark.network.sasl.serverAlwaysEncrypt", "true");
            conf.set("spark.authenticate.enableSaslEncryption", "true");

            if (conf.get("spark.authenticate.enableSaslEncryption", "false").equalsIgnoreCase("true")) {
                setEncryptSecureServer(true);
            } else {
                setEncryptSecureServer(false);
            }

            TransportConf transportConf = SparkTransportConf.fromSparkConf(conf, "Carbon Dictionary Server", 0);
            securityManager = new SecurityManager(conf, Some.<byte[]>empty());
            secretKey = securityManager.getSecretKey();
            TransportContext context = new TransportContext(transportConf, secureDictionaryServerHandler);
            TransportServerBootstrap bootstrap = new SaslServerBootstrap(transportConf, securityManager);
            String host = findLocalIpAddress(LOGGER);
            //iteratively listening to newports
            context.createServer(host, newPort, Lists.<TransportServerBootstrap>newArrayList(bootstrap));
            LOGGER.info("Dictionary Server started, Time spent " + (System.currentTimeMillis() - start)
                    + " Listening on port " + newPort);
            this.port = newPort;
            this.host = host;
            break;
        } catch (Exception e) {
            LOGGER.error("Dictionary Server Failed to bind to port: " + newPort, e);
            if (i == 9) {
                throw new RuntimeException("Dictionary Server Could not bind to any port");
            }
        }
        i++;
    }
}

From source file:org.apache.sysml.runtime.controlprogram.paramserv.rpc.PSRpcFactory.java

License:Apache License

/**
 * Create and start the server/*from   w w w  . ja v  a  2 s.com*/
 * @return server
 */
public static TransportServer createServer(SparkConf conf, LocalParamServer ps, String host) {
    TransportContext context = createTransportContext(conf, ps);
    return context.createServer(host, 0, Collections.emptyList()); // bind rpc to an ephemeral port
}