Example usage for org.apache.cassandra.transport Message.Request attach

List of usage examples for org.apache.cassandra.transport Message.Request attach

Introduction

In this page you can find the example usage for org.apache.cassandra.transport Message.Request attach.

Prototype

public void attach(Connection connection) 

Source Link

Usage

From source file:com.datastax.driver.core.Connection.java

License:Apache License

public void write(ResponseCallback callback) throws ConnectionException, BusyConnectionException {

    Message.Request request = callback.request();

    request.attach(this);

    ResponseHandler handler = new ResponseHandler(dispatcher, callback);
    dispatcher.add(handler);//  ww w.  j a v a2  s  . c  om
    request.setStreamId(handler.streamId);

    /*
     * We check for close/defunct *after* having set the handler because closing/defuncting
     * will set their flag and then error out handler if need. So, by doing the check after
     * having set the handler, we guarantee that even if we race with defunct/close, we may
     * never leave a handler that won't get an answer or be errored out.
     */
    if (isDefunct) {
        dispatcher.removeHandler(handler.streamId);
        throw new ConnectionException(address, "Write attempt on defunct connection");
    }

    if (isClosed) {
        dispatcher.removeHandler(handler.streamId);
        throw new ConnectionException(address, "Connection has been closed");
    }

    logger.trace("[{}] writing request {}", name, request);
    writer.incrementAndGet();
    channel.write(request).addListener(writeHandler(request, handler));
}