Skip to content

Commit

Permalink
Merge pull request #142 from hiddenalpha/SDCISA-10974-DiscloseErrorsI…
Browse files Browse the repository at this point in the history
…nHandlers
  • Loading branch information
hiddenalpha authored Dec 7, 2023
2 parents edf56cc + 07a711d commit 28fce87
Show file tree
Hide file tree
Showing 14 changed files with 286 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.swisspush.redisques.util.RedisquesAPI.*;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;

/**
* Class AddQueueItemHandler.
*
* @author baldim, https://github.com/mcweba [Marc-Andre Weber]
*/
public class AddQueueItemHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(AddQueueItemHandler.class);
private final Message<JsonObject> event;

public AddQueueItemHandler(Message<JsonObject> event) {
Expand All @@ -25,6 +31,7 @@ public void handle(AsyncResult<Response> reply) {
if(reply.succeeded()){
event.reply(new JsonObject().put(STATUS, OK));
} else {
log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;

import static org.swisspush.redisques.util.RedisquesAPI.*;

/**
* Class DeleteLockHandler.
*
* @author baldim
*/
public class DeleteLockHandler implements Handler<AsyncResult<Response>> {
private final Message<JsonObject> event;

public DeleteLockHandler(Message<JsonObject> event) {
this.event = event;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded()) {
event.reply(new JsonObject().put(STATUS, OK));
} else {
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
}
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;

/**
* Class DeleteLockHandler.
*
* @author baldim
*/
public class DeleteLockHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(DeleteLockHandler.class);
private final Message<JsonObject> event;

public DeleteLockHandler(Message<JsonObject> event) {
this.event = event;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded()) {
event.reply(new JsonObject().put(STATUS, OK));
} else {
log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,52 @@
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.swisspush.redisques.util.HandlerUtil;

import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;

import static org.swisspush.redisques.util.RedisquesAPI.*;

/**
* Class GetAllLocksHandler.
*
* @author baldim
*/
public class GetAllLocksHandler implements Handler<AsyncResult<Response>> {

private final Message<JsonObject> event;
private final Optional<Pattern> filterPattern;

public GetAllLocksHandler(Message<JsonObject> event, Optional<Pattern> filterPattern) {
this.event = event;
this.filterPattern = filterPattern;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded() && reply.result() != null) {
JsonObject result = new JsonObject();
Response locks = reply.result();
List<String> filteredLocks = HandlerUtil.filterByPattern(locks, filterPattern);
result.put("locks", new JsonArray(filteredLocks));
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, result));
} else {
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
import org.swisspush.redisques.util.HandlerUtil;

import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;

import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;

/**
* Class GetAllLocksHandler.
*
* @author baldim
*/
public class GetAllLocksHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(GetAllLocksHandler.class);
private final Message<JsonObject> event;
private final Optional<Pattern> filterPattern;

public GetAllLocksHandler(Message<JsonObject> event, Optional<Pattern> filterPattern) {
this.event = event;
this.filterPattern = filterPattern;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded() && reply.result() != null) {
JsonObject result = new JsonObject();
Response locks = reply.result();
List<String> filteredLocks = HandlerUtil.filterByPattern(locks, filterPattern);
result.put("locks", new JsonArray(filteredLocks));
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, result));
} else {
if( reply.failed() ) log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));
}
}

}
80 changes: 45 additions & 35 deletions src/main/java/org/swisspush/redisques/handler/GetLockHandler.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;

import static org.swisspush.redisques.util.RedisquesAPI.*;

/**
* Class GetLockHandler.
*
* @author baldim
*/
public class GetLockHandler implements Handler<AsyncResult<Response>> {
private final Message<JsonObject> event;

public GetLockHandler(Message<JsonObject> event) {
this.event = event;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded()) {
if (reply.result() != null) {
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, reply.result().toString()));
} else {
event.reply(new JsonObject().put(STATUS, NO_SUCH_LOCK));
}
} else {
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
}
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.NO_SUCH_LOCK;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;

/**
* Class GetLockHandler.
*
* @author baldim
*/
public class GetLockHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(GetLockHandler.class);
private final Message<JsonObject> event;

public GetLockHandler(Message<JsonObject> event) {
this.event = event;
}

@Override
public void handle(AsyncResult<Response> reply) {
if (reply.succeeded()) {
if (reply.result() != null) {
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, reply.result().toString()));
} else {
event.reply(new JsonObject().put(STATUS, NO_SUCH_LOCK));
}
} else {
log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));
}
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import static org.swisspush.redisques.util.RedisquesAPI.*;
import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;

/**
* Class GetQueueItemHandler.
*
* @author baldim, https://github.com/mcweba [Marc-Andre Weber]
*/
public class GetQueueItemHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(GetQueueItemHandler.class);
private final Message<JsonObject> event;

public GetQueueItemHandler(Message<JsonObject> event) {
Expand All @@ -24,7 +32,9 @@ public void handle(AsyncResult<Response> reply) {
if (reply.succeeded() && reply.result() != null) {
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, reply.result().toString()));
} else {
if( reply.failed() ) log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.swisspush.redisques.util.RedisquesAPI.*;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;

/**
* Class GetQueueItemsCountHandler.
*
* @author https://github.com/mcweba [Marc-Andre Weber]
*/
public class GetQueueItemsCountHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(GetQueueItemsCountHandler.class);
private final Message<JsonObject> event;

public GetQueueItemsCountHandler(Message<JsonObject> event) {
Expand All @@ -26,6 +33,7 @@ public void handle(AsyncResult<Response> reply) {
Long queueItemCount = reply.result().toLong();
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, queueItemCount));
} else {
log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package org.swisspush.redisques.handler;

import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonArray;

import static org.swisspush.redisques.util.RedisquesAPI.*;

import io.vertx.core.Handler;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.INFO;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;

/**
* Class GetQueueItemsHandler.
*
* @author baldim, https://github.com/mcweba [Marc-Andre Weber]
*/
public class GetQueueItemsHandler implements Handler<AsyncResult<Response>> {

private static final Logger log = getLogger(GetQueueItemsHandler.class);
private final Message<JsonObject> event;
private final Long queueItemCount;

Expand All @@ -39,7 +46,9 @@ public void handle(AsyncResult<Response> reply) {
}
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, values).put(INFO, countInfo));
} else {
log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));
}
}

}
Loading

0 comments on commit 28fce87

Please sign in to comment.