Skip to content

Commit

Permalink
Remove redundant 'ReplyFailure' arg in newReplyException()
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenalpha committed Jul 11, 2024
1 parent 3f47274 commit 24877a3
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/swisspush/redisques/QueueStatsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;

import static io.vertx.core.eventbus.ReplyFailure.RECIPIENT_FAILURE;
import static java.lang.Long.compare;
import static java.lang.System.currentTimeMillis;
import static java.util.Collections.emptyList;
Expand Down Expand Up @@ -72,7 +71,7 @@ public QueueStatsService(

public <CTX> void getQueueStats(CTX mCtx, GetQueueStatsMentor<CTX> mentor) {
if (!incomingRequestQuota.tryAcquire()) {
Throwable ex = exceptionFactory.newReplyException(RECIPIENT_FAILURE, 429,
Throwable ex = exceptionFactory.newReplyException(429,
"Server too busy to handle yet-another-queue-stats-request now", null);
vertx.runOnContext(v -> mentor.onError(ex, mCtx));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.List;
import java.util.Objects;

import static io.vertx.core.eventbus.ReplyFailure.RECIPIENT_FAILURE;
import static org.swisspush.redisques.util.RedisquesAPI.*;

public abstract class AbstractQueueAction implements QueueAction {
Expand Down Expand Up @@ -61,8 +60,8 @@ protected Handler<Throwable> replyErrorMessageHandler(Message<JsonObject> event)
};
}

protected void handleFail(Message<JsonObject> event, String message, Throwable cause) {
event.reply(exceptionFactory.newReplyException(RECIPIENT_FAILURE, 0, null, cause));
protected void handleFail(Message<JsonObject> event, String msg, Throwable cause) {
event.reply(exceptionFactory.newReplyException(msg, cause));
}

protected long getMaxAgeTimestamp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import java.util.List;

import static io.vertx.core.eventbus.ReplyFailure.RECIPIENT_FAILURE;
import static org.swisspush.redisques.util.RedisquesAPI.*;

public class GetQueueItemsAction extends AbstractQueueAction {
Expand All @@ -38,8 +37,8 @@ public void execute(Message<JsonObject> event) {
redisAPI.lrange(keyListRange, "0", String.valueOf(maxQueueItemCountIndex),
new GetQueueItemsHandler(event, queueItemCount));
} else {
event.reply(exceptionFactory.newReplyException(RECIPIENT_FAILURE, 0,
"Operation getQueueItems failed to extract queueItemCount", null));
event.reply(exceptionFactory.newReplyException(
"Operation getQueueItems failed to extract queueItemCount", null));
}
}).onFailure(throwable -> handleFail(event, "Operation getQueueItems failed", throwable)))
.onFailure(throwable -> handleFail(event, "Operation getQueueItems failed", throwable));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.swisspush.redisques.exception;

import io.vertx.core.eventbus.ReplyException;
import io.vertx.core.eventbus.ReplyFailure;


/**
Expand Down Expand Up @@ -30,7 +29,11 @@ public interface RedisQuesExceptionFactory {

public RuntimeException newRuntimeException(String message, Throwable cause);

public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String msg, Throwable cause);
default ReplyException newReplyException(String msg, Throwable cause) {
return newReplyException(0, msg, cause);
}

public ReplyException newReplyException(int failureCode, String msg, Throwable cause);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public RuntimeException newRuntimeException(String message, Throwable cause) {
}

@Override
public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String msg, Throwable cause) {
public ReplyException newReplyException(int failureCode, String msg, Throwable cause) {
// There was once a fix in vertx for this (https://github.com/eclipse-vertx/vert.x/issues/4840)
// but for whatever reason in our case we still see stack-trace recordings. Passing
// this subclass to {@link io.vertx.core.eventbus.Message#reply(Object)} seems to
// do the trick.
if (msg == null && cause != null) msg = cause.getMessage();
return new ReplyException(failureType, failureCode, msg) {
return new ReplyException(ReplyFailure.RECIPIENT_FAILURE, failureCode, msg) {
@Override public Throwable fillInStackTrace() { return this; }
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public RuntimeException newRuntimeException(String message, Throwable cause) {
}

@Override
public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String msg, Throwable cause) {
public ReplyException newReplyException(int failureCode, String msg, Throwable cause) {
if (msg == null && cause != null) msg = cause.getMessage();
ReplyException ex = new ReplyException(failureType, failureCode, msg);
ReplyException ex = new ReplyException(ReplyFailure.RECIPIENT_FAILURE, failureCode, msg);
if (cause != null) ex.initCause(cause);
return ex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.slf4j.Logger;
import org.swisspush.redisques.exception.RedisQuesExceptionFactory;

import static io.vertx.core.eventbus.ReplyFailure.RECIPIENT_FAILURE;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
Expand All @@ -34,7 +33,7 @@ public void handle(AsyncResult<Response> reply) {
if(reply.succeeded()){
event.reply(new JsonObject().put(STATUS, OK));
} else {
event.reply(exceptionFactory.newReplyException(RECIPIENT_FAILURE, 0, null, reply.cause()));
event.reply(exceptionFactory.newReplyException(null, reply.cause()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.slf4j.Logger;
import org.swisspush.redisques.exception.RedisQuesExceptionFactory;

import static io.vertx.core.eventbus.ReplyFailure.RECIPIENT_FAILURE;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
Expand All @@ -34,7 +33,7 @@ public void handle(AsyncResult<Response> reply) {
if (reply.succeeded()) {
event.reply(new JsonObject().put(STATUS, OK));
} else {
event.reply(exceptionFactory.newReplyException(RECIPIENT_FAILURE, 0, null, reply.cause()));
event.reply(exceptionFactory.newReplyException(null, reply.cause()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.slf4j.Logger;
import org.swisspush.redisques.exception.RedisQuesExceptionFactory;

import static io.vertx.core.eventbus.ReplyFailure.RECIPIENT_FAILURE;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.NO_SUCH_LOCK;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
Expand Down Expand Up @@ -40,7 +39,7 @@ public void handle(AsyncResult<Response> reply) {
event.reply(new JsonObject().put(STATUS, NO_SUCH_LOCK));
}
} else {
event.reply(exceptionFactory.newReplyException(RECIPIENT_FAILURE, 0, null, reply.cause()));
event.reply(exceptionFactory.newReplyException(null, reply.cause()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public GetQueueItemHandler(Message<JsonObject> event, RedisQuesExceptionFactory
@Override
public void handle(AsyncResult<Response> reply) {
if(reply.failed()) {
event.reply(exceptionFactory.newReplyException(io.vertx.core.eventbus.ReplyFailure.RECIPIENT_FAILURE, 0, null, reply.cause()));
event.reply(exceptionFactory.newReplyException(null, reply.cause()));
} else if (reply.result() != null) {
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, reply.result().toString()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.Message;
import io.vertx.core.eventbus.ReplyFailure;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Command;
Expand Down Expand Up @@ -87,7 +86,7 @@ public void handle(AsyncResult<Response> handleQueues) {
return;
}
if (redisRequestQuota.availablePermits() <= 0) {
event.reply(exceptionFactory.newReplyException(ReplyFailure.RECIPIENT_FAILURE, 429,
event.reply(exceptionFactory.newReplyException(429,
"Too many simultaneous '" + GetQueuesItemsCountHandler.class.getSimpleName() + "' requests in progress", null));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.slf4j.Logger;
import org.swisspush.redisques.exception.RedisQuesExceptionFactory;

import static io.vertx.core.eventbus.ReplyFailure.RECIPIENT_FAILURE;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
Expand All @@ -34,7 +33,7 @@ public void handle(AsyncResult<Response> reply) {
if(reply.succeeded()){
event.reply(new JsonObject().put(STATUS, OK));
} else {
event.reply(exceptionFactory.newReplyException(RECIPIENT_FAILURE, 0, reply.cause().getMessage(), reply.cause()));
event.reply(exceptionFactory.newReplyException(reply.cause().getMessage(), reply.cause()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.slf4j.Logger;
import org.swisspush.redisques.exception.RedisQuesExceptionFactory;

import static io.vertx.core.eventbus.ReplyFailure.RECIPIENT_FAILURE;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
Expand Down Expand Up @@ -37,7 +36,7 @@ public void handle(AsyncResult<Response> reply) {
} else if(checkRedisErrorCodes(reply.cause().getMessage())) {
event.reply(new JsonObject().put(STATUS, ERROR));
} else {
event.reply(exceptionFactory.newReplyException(RECIPIENT_FAILURE, 0, reply.cause().getMessage(), reply.cause()));
event.reply(exceptionFactory.newReplyException(null, reply.cause()));
}
}

Expand Down

0 comments on commit 24877a3

Please sign in to comment.