Search in sources :

Example 1 with RequestMessage

use of com.datastax.oss.driver.internal.core.channel.DriverChannel.RequestMessage in project java-driver by datastax.

the class InFlightHandler method write.

@Override
public void write(ChannelHandlerContext ctx, Object in, ChannelPromise promise) throws Exception {
    if (in == DriverChannel.GRACEFUL_CLOSE_MESSAGE) {
        LOG.debug("[{}] Received graceful close request", logPrefix);
        startGracefulShutdown(ctx);
    } else if (in == DriverChannel.FORCEFUL_CLOSE_MESSAGE) {
        LOG.debug("[{}] Received forceful close request, aborting pending queries", logPrefix);
        abortAllInFlight(new ClosedConnectionException("Channel was force-closed"));
        ctx.channel().close();
    } else if (in instanceof HeartbeatException) {
        abortAllInFlight(new ClosedConnectionException("Heartbeat query failed", ((HeartbeatException) in)));
        ctx.close();
    } else if (in instanceof RequestMessage) {
        write(ctx, (RequestMessage) in, promise);
    } else if (in instanceof ResponseCallback) {
        cancel(ctx, (ResponseCallback) in, promise);
    } else {
        promise.setFailure(new IllegalArgumentException("Unsupported message type " + in.getClass().getName()));
    }
}
Also used : ClosedConnectionException(com.datastax.oss.driver.api.core.connection.ClosedConnectionException) HeartbeatException(com.datastax.oss.driver.api.core.connection.HeartbeatException) RequestMessage(com.datastax.oss.driver.internal.core.channel.DriverChannel.RequestMessage)

Aggregations

ClosedConnectionException (com.datastax.oss.driver.api.core.connection.ClosedConnectionException)1 HeartbeatException (com.datastax.oss.driver.api.core.connection.HeartbeatException)1 RequestMessage (com.datastax.oss.driver.internal.core.channel.DriverChannel.RequestMessage)1