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();
}
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);
}
});
}
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);
}
}
Aggregations