Search in sources :

Example 1 with BusyConnectionException

use of com.datastax.oss.driver.api.core.connection.BusyConnectionException in project zipkin by openzipkin.

the class ResultSetFutureCallTest method isOverCapacity.

// below are load related exceptions which should result in a backoff of storage requests
@Test
public void isOverCapacity() {
    assertThat(ResultSetFutureCall.isOverCapacity(new RequestThrottlingException("The session is shutting down"))).isTrue();
    assertThat(ResultSetFutureCall.isOverCapacity(new BusyConnectionException(100))).isTrue();
    assertThat(ResultSetFutureCall.isOverCapacity(mock(QueryConsistencyException.class))).isTrue();
    // not applicable
    assertThat(ResultSetFutureCall.isOverCapacity(new IllegalStateException("Rejected execution"))).isFalse();
}
Also used : BusyConnectionException(com.datastax.oss.driver.api.core.connection.BusyConnectionException) QueryConsistencyException(com.datastax.oss.driver.api.core.servererrors.QueryConsistencyException) RequestThrottlingException(com.datastax.oss.driver.api.core.RequestThrottlingException) Test(org.junit.Test)

Example 2 with BusyConnectionException

use of com.datastax.oss.driver.api.core.connection.BusyConnectionException in project java-driver by datastax.

the class InFlightHandler method write.

private void write(ChannelHandlerContext ctx, RequestMessage message, ChannelPromise promise) {
    if (closingGracefully) {
        promise.setFailure(new IllegalStateException("Channel is closing"));
        streamIds.cancelPreAcquire();
        return;
    }
    int streamId = streamIds.acquire();
    if (streamId < 0) {
        // Should not happen with the preAcquire mechanism, but handle gracefully
        promise.setFailure(new BusyConnectionException(String.format("Couldn't acquire a stream id from InFlightHandler on %s", ctx.channel())));
        streamIds.cancelPreAcquire();
        return;
    }
    if (inFlight.containsKey(streamId)) {
        promise.setFailure(new IllegalStateException("Found pending callback for stream id " + streamId));
        streamIds.cancelPreAcquire();
        return;
    }
    LOG.trace("[{}] Writing {} on stream id {}", logPrefix, message.responseCallback, streamId);
    Frame frame = Frame.forRequest(protocolVersion.getCode(), streamId, message.tracing, message.customPayload, message.request);
    inFlight.put(streamId, message.responseCallback);
    ChannelFuture writeFuture = ctx.write(frame, promise);
    writeFuture.addListener(future -> {
        if (future.isSuccess()) {
            message.responseCallback.onStreamIdAssigned(streamId);
        } else {
            release(streamId, ctx);
        }
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Frame(com.datastax.oss.protocol.internal.Frame) BusyConnectionException(com.datastax.oss.driver.api.core.connection.BusyConnectionException)

Example 3 with BusyConnectionException

use of com.datastax.oss.driver.api.core.connection.BusyConnectionException in project java-driver by datastax.

the class ChannelHandlerRequest method send.

void send() {
    assert channel.eventLoop().inEventLoop();
    if (!inFlightHandler.preAcquireId()) {
        fail(new BusyConnectionException(String.format("%s has reached its maximum number of simultaneous requests", channel)));
    } else {
        DriverChannel.RequestMessage message = new DriverChannel.RequestMessage(getRequest(), false, Frame.NO_PAYLOAD, this);
        ChannelFuture writeFuture = channel.writeAndFlush(message);
        writeFuture.addListener(this::writeListener);
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) BusyConnectionException(com.datastax.oss.driver.api.core.connection.BusyConnectionException)

Aggregations

BusyConnectionException (com.datastax.oss.driver.api.core.connection.BusyConnectionException)3 ChannelFuture (io.netty.channel.ChannelFuture)2 RequestThrottlingException (com.datastax.oss.driver.api.core.RequestThrottlingException)1 QueryConsistencyException (com.datastax.oss.driver.api.core.servererrors.QueryConsistencyException)1 Frame (com.datastax.oss.protocol.internal.Frame)1 Test (org.junit.Test)1