Example usage for org.apache.spark.network.client TransportClient sendRpcSync

List of usage examples for org.apache.spark.network.client TransportClient sendRpcSync

Introduction

In this page you can find the example usage for org.apache.spark.network.client TransportClient sendRpcSync.

Prototype

public ByteBuffer sendRpcSync(ByteBuffer message, long timeoutMs) 

Source Link

Document

Synchronously sends an opaque message to the RpcHandler on the server-side, waiting for up to a specified timeout for a response.

Usage

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

License:Apache License

/**
 * client send request to server/*  w ww  .  j av  a 2 s .  c o m*/
 *
 * @param key DictionaryMessage
 * @return DictionaryMessage
 */
public DictionaryMessage getDictionary(DictionaryMessage key, TransportClient client) {
    DictionaryMessage dictionaryMessage;
    ByteBuffer resp = null;
    try {

        ByteBuf buffer = ByteBufAllocator.DEFAULT.heapBuffer();
        key.writeData(buffer);
        resp = client.sendRpcSync(buffer.nioBuffer(), 100000);
    } catch (Exception e) {
        LOGGER.error("Error while send request to server ", e);
    }
    try {
        if (resp == null) {
            StringBuilder message = new StringBuilder();
            message.append("DictionaryMessage { ColumnName: ").append(key.getColumnName())
                    .append(", DictionaryValue: ").append(key.getDictionaryValue()).append(", type: ")
                    .append(key.getType()).append(" }");
            throw new RuntimeException("Request timed out for key : " + message);
        }
        DictionaryMessage newKey = new DictionaryMessage();
        ByteBuf data = Unpooled.wrappedBuffer(resp);
        newKey.readFullLength(data);
        data.release();
        return newKey;
    } catch (Exception e) {
        LOGGER.error(e);
        throw new RuntimeException(e);
    }
}