How to stop vertx threads?

264 views Asked by At

So here's the situation: I'm implementing the caching of our webapp using vertx-redis (we were formerly using lettuce). Pretty simple mechanism, there is an anotation we use on endpoints which is responsible to invoke the redis-client (whatever implementation we are using) and, if there is cached info for the given key it should be used as response body and the request should be finished with no processing.

But there's this really annoying behavior with the vertx-redis implementation in which ending the request doesn't stop the processing. I make the request, get the quick response since there was cached info, but I can still see in the logs that the app keeps the processing going on, as if the request was still open. I believe that it's because I'm ending the response inside the handler for the Redis client call, like this:

client.get("key", onResponse -> {
    if (onResponse.succeeded() && onResponse.result() != null) {
        //ending request from here
    }
});

I realize that I could maybe reproduce the behavior as it was before if I could do something like this:

String cachedInfo = client.get("key").map(onResponse -> onResponse.result());
// endResponse

But as we know, vertx-redis is a semantic API and every method returns the same instance of RedisClient. I also thought about doing something like this:

private String cachedInfo; 

...

client.get("key", onResult -> {
    if (onResponse.succeeded()) {
        this.cachedInfo = onResponse.result();
    }
});

if (cachedInfo != null) { // The value could be unset since the lambda is running in other thread 
    //end request
}

Really don't know what to do, is there a way to return the contents of the AsyncResult to a variable or maybe set it to a variable synchronously somehow? I've also been searching for ways to somehow stop the whole flow of the current request but couldn't find any satisfactory, non-aggressive solution so far, but I'm really open to this option either.

0

There are 0 answers