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

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

Introduction

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

Prototype

public Message setStreamId(int streamId) 

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);//  www.j  a v a2 s .  co  m
    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));
}