Example usage for java.net Socket getSendBufferSize

List of usage examples for java.net Socket getSendBufferSize

Introduction

In this page you can find the example usage for java.net Socket getSendBufferSize.

Prototype

public synchronized int getSendBufferSize() throws SocketException 

Source Link

Document

Get value of the SocketOptions#SO_SNDBUF SO_SNDBUF option for this Socket , that is the buffer size used by the platform for output on this Socket .

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket client = new Socket("google.com", 80);
    client.setSendBufferSize(1000);/*  w w  w . j a  v a 2s  . c  om*/
    System.out.println(client.getSendBufferSize());

    client.close();
}

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

/**
 * Create a socket for a write pipeline/*from   w  w w. j ava2s  .c o 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;
}

From source file:org.apache.hadoop.hdfs.DataStreamer.java

/**
 * Create a socket for a write pipeline/*w  w w.  j  ava 2s  .c o 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().connectToDnViaHostname);
    if (DFSClient.LOG.isDebugEnabled()) {
        DFSClient.LOG.debug("Connecting to datanode " + dnAddr);
    }
    final InetSocketAddress isa = NetUtils.createSocketAddr(dnAddr);
    SocketFactory socketFactory = new StandardSocketFactory();
    final Socket sock = socketFactory.createSocket();
    final int timeout = client.getDatanodeReadTimeout(length);
    NetUtils.connect(sock, isa, client.getRandomLocalInterfaceAddr(), client.getConf().socketTimeout);
    sock.setSoTimeout(timeout);
    sock.setSendBufferSize(HdfsConstants.DEFAULT_DATA_SOCKET_SIZE);
    if (DFSClient.LOG.isDebugEnabled()) {
        DFSClient.LOG.debug("Send buf size " + sock.getSendBufferSize());
    }
    return sock;
}

From source file:org.apache.hadoop.hdfs.DataStreamer.java

/**
 * Create a socket for a write pipeline/*from   ww w. j av a2  s .com*/
 *
 * @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 DfsClientConf conf = client.getConf();
    final String dnAddr = first.getXferAddr(conf.isConnectToDnViaHostname());
    if (LOG.isDebugEnabled()) {
        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(), conf.getSocketTimeout());
    sock.setSoTimeout(timeout);
    sock.setSendBufferSize(HdfsConstants.DEFAULT_DATA_SOCKET_SIZE);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Send buf size " + sock.getSendBufferSize());
    }
    return sock;
}

From source file:org.mule.transport.tcp.TcpConnector.java

public void configureSocket(boolean client, Socket socket) throws SocketException {
    // There is some overhead in setting socket timeout and buffer size, so we're
    // careful here only to set if needed

    if (newValue(getReceiveBufferSize(), socket.getReceiveBufferSize())) {
        socket.setReceiveBufferSize(getReceiveBufferSize());
    }/*  w  ww  . j  av a  2 s  .c o m*/
    if (newValue(getSendBufferSize(), socket.getSendBufferSize())) {
        socket.setSendBufferSize(getSendBufferSize());
    }
    if (client) {
        if (newValue(getClientSoTimeout(), socket.getSoTimeout())) {
            socket.setSoTimeout(getClientSoTimeout());
        }
    } else {
        if (newValue(getServerSoTimeout(), socket.getSoTimeout())) {
            socket.setSoTimeout(getServerSoTimeout());
        }
    }
    if (newValue(getSocketSoLinger(), socket.getSoLinger())) {
        socket.setSoLinger(true, getSocketSoLinger());
    }
    try {
        socket.setTcpNoDelay(isSendTcpNoDelay());
    } catch (SocketException e) {
        // MULE-2800 - Bug in Solaris
    }
    socket.setKeepAlive(isKeepAlive());
}

From source file:voldemort.store.socket.SocketPoolableObjectFactory.java

private void recordSocketCreation(SocketDestination dest, Socket socket) throws SocketException {
    int numCreated = created.incrementAndGet();
    logger.debug("Created socket " + numCreated + " for " + dest.getHost() + ":" + dest.getPort());

    // check buffer sizes--you often don't get out what you put in!
    int sendBufferSize = socket.getSendBufferSize();
    int receiveBufferSize = socket.getReceiveBufferSize();
    if (receiveBufferSize != this.socketBufferSize)
        logger.debug("Requested socket receive buffer size was " + this.socketBufferSize
                + " bytes but actual size is " + receiveBufferSize + " bytes.");
    if (sendBufferSize != this.socketBufferSize)
        logger.debug("Requested socket send buffer size was " + this.socketBufferSize
                + " bytes but actual size is " + sendBufferSize + " bytes.");
}