Example usage for org.apache.spark.network.client RpcResponseCallback onSuccess

List of usage examples for org.apache.spark.network.client RpcResponseCallback onSuccess

Introduction

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

Prototype

void onSuccess(ByteBuffer response);

Source Link

Document

Successful serialized result from server.

Usage

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

License:Apache License

@Override
public void receive(TransportClient transportClient, ByteBuffer byteBuffer,
        RpcResponseCallback rpcResponseCallback) {
    try {/*ww w.  j a v  a  2  s. c om*/
        ByteBuf data = Unpooled.wrappedBuffer(byteBuffer);
        DictionaryMessage key = new DictionaryMessage();
        key.readFullLength(data);
        data.release();
        int outPut = processMessage(key);
        key.setDictionaryValue(outPut);
        // Send back the response
        ByteBuf buff = ByteBufAllocator.DEFAULT.buffer();
        key.writeData(buff);
        rpcResponseCallback.onSuccess(buff.nioBuffer());
    } catch (Exception e) {
        LOGGER.error(e);
    }
}

From source file:org.apache.spark.network.NoOpRpcHandler.java

License:Apache License

@Override
public void receive(TransportClient client, byte[] message, RpcResponseCallback callback) {
    callback.onSuccess(new byte[0]);
}

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

License:Apache License

@Override
public void receive(TransportClient client, ByteBuffer buffer, RpcResponseCallback callback) {
    PSRpcCall call;//from  w  w  w.  j  a  va2  s . co  m
    try {
        call = new PSRpcCall(buffer);
    } catch (IOException e) {
        throw new DMLRuntimeException("PSRpcHandler: some error occurred when deserializing the rpc call.", e);
    }
    PSRpcResponse response = null;
    switch (call.getMethod()) {
    case PUSH:
        try {
            _server.push(call.getWorkerID(), call.getData());
            response = new PSRpcResponse(Type.SUCCESS_EMPTY);
        } catch (DMLRuntimeException exception) {
            response = new PSRpcResponse(Type.ERROR, ExceptionUtils.getFullStackTrace(exception));
        } finally {
            try {
                callback.onSuccess(response.serialize());
            } catch (IOException e) {
                throw new DMLRuntimeException(
                        "PSRpcHandler: some error occrred when wrapping the rpc response.", e);
            }
        }
        break;
    case PULL:
        ListObject data;
        try {
            data = _server.pull(call.getWorkerID());
            response = new PSRpcResponse(Type.SUCCESS, data);
        } catch (DMLRuntimeException exception) {
            response = new PSRpcResponse(Type.ERROR, ExceptionUtils.getFullStackTrace(exception));
        } finally {
            try {
                callback.onSuccess(response.serialize());
            } catch (IOException e) {
                throw new DMLRuntimeException(
                        "PSRpcHandler: some error occrred when wrapping the rpc response.", e);
            }
        }
        break;
    default:
        throw new DMLRuntimeException(
                String.format("Does not support the rpc call for method %s", call.getMethod()));
    }
}