Example usage for org.apache.hadoop.hdfs DFSClient getRandomLocalInterfaceAddr

List of usage examples for org.apache.hadoop.hdfs DFSClient getRandomLocalInterfaceAddr

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs DFSClient getRandomLocalInterfaceAddr.

Prototype

SocketAddress getRandomLocalInterfaceAddr() 

Source Link

Document

Select one of the configured local interfaces at random.

Usage

From source file:com.mellanox.r4h.DFSOutputStream.java

License:Apache License

/**
 * Create a socket for a write pipeline/*from   www .j ava2  s .co  m*/
 * 
 * @param first
 *            the first datanode
 * @param length
 *            the pipeline length
 * @param client
 *            client
 * @return the socket connected to the first datanode
 */
static Socket createSocketForPipeline(final DatanodeInfo first, final int length, final DFSClient client)
        throws IOException {
    final String dnAddr = first.getXferAddr(client.getConf().getConnectToDnViaHostname());
    if (DFSClient.LOG.isDebugEnabled()) {
        DFSClient.LOG.debug("Connecting to datanode " + dnAddr);
    }
    final InetSocketAddress isa = NetUtils.createSocketAddr(dnAddr);
    final Socket sock = client.socketFactory.createSocket();
    final int timeout = client.getDatanodeReadTimeout(length);
    NetUtils.connect(sock, isa, client.getRandomLocalInterfaceAddr(), client.getConf().getSocketTimeout());
    sock.setSoTimeout(timeout);
    sock.setSendBufferSize(HdfsConstants.DEFAULT_DATA_SOCKET_SIZE);
    if (DFSClient.LOG.isDebugEnabled()) {
        DFSClient.LOG.debug("Send buf size " + sock.getSendBufferSize());
    }
    return sock;
}