Package edu.brown.hstore.callbacks

Source Code of edu.brown.hstore.callbacks.ClientResponseCallback

/**
*
*/
package edu.brown.hstore.callbacks;

import org.voltdb.ClientResponseImpl;
import org.voltdb.exceptions.ClientConnectionLostException;
import org.voltdb.network.Connection;

import com.google.protobuf.RpcCallback;

import edu.brown.hstore.ClientInterface;

/**
* Thin wrapper to sent a ClientResponse back to the client over a Connection handle
* @author pavlo
*/
public class ClientResponseCallback implements RpcCallback<ClientResponseImpl> {

    private final ClientInterface clientInterface;
    private final Connection conn;
    private final int messageSize;
   
    public ClientResponseCallback(ClientInterface clientInterface, Connection conn, int messageSize) {
        this.clientInterface = clientInterface;
        this.conn = conn;
        this.messageSize = messageSize;
    }
   
   
    @Override
    public void run(ClientResponseImpl parameter) {
        // Always reduce backpressure before we throw the exception
        boolean ret = this.conn.writeStream().enqueue(parameter);
        this.clientInterface.reduceBackpressure(this.messageSize);
        if (ret == false) {
            throw new ClientConnectionLostException(parameter.getTransactionId());
        }
    }
   
    public String toString() {
        return (this.conn.toString());
    }

}
TOP

Related Classes of edu.brown.hstore.callbacks.ClientResponseCallback

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.