Example usage for org.apache.hadoop.ipc Server setSocketSendBufSize

List of usage examples for org.apache.hadoop.ipc Server setSocketSendBufSize

Introduction

In this page you can find the example usage for org.apache.hadoop.ipc Server setSocketSendBufSize.

Prototype

public void setSocketSendBufSize(int size) 

Source Link

Document

Sets the socket buffer size used for responding to RPCs

Usage

From source file:rpc.TestRPC.java

License:Apache License

private void testCallsInternal(Configuration conf) throws IOException {
    Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl())
            .setBindAddress(ADDRESS).setPort(0).build();
    TestProtocol proxy = null;/*  www  .  jav a 2 s.  com*/
    try {
        server.start();

        InetSocketAddress addr = NetUtils.getConnectAddress(server);
        proxy = RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf);

        proxy.ping();

        String stringResult = proxy.echo("foo");
        assertEquals(stringResult, "foo");

        stringResult = proxy.echo((String) null);
        assertEquals(stringResult, null);

        String[] stringResults = proxy.echo(new String[] { "foo", "bar" });
        assertTrue(Arrays.equals(stringResults, new String[] { "foo", "bar" }));

        stringResults = proxy.echo((String[]) null);
        assertTrue(Arrays.equals(stringResults, null));

        // create multiple threads and make them do large data transfers
        System.out.println("Starting multi-threaded RPC test...");
        server.setSocketSendBufSize(1024);
        Thread threadId[] = new Thread[numThreads];
        for (int i = 0; i < numThreads; i++) {
            Transactions trans = new Transactions(proxy, datasize);
            threadId[i] = new Thread(trans, "TransactionThread-" + i);
            threadId[i].start();
        }

        // wait for all transactions to get over
        System.out.println("Waiting for all threads to finish RPCs...");
        for (int i = 0; i < numThreads; i++) {
            try {
                threadId[i].join();
            } catch (InterruptedException e) {
                i--; // retry
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        server.stop();
        if (proxy != null)
            RPC.stopProxy(proxy);
    }
}