javapostgresqlkotlinvert.xapache-cayenne

Configure Apache Cayenne to be used in an asynchronous manner with Vertx


I'm using Apache Cayenne with Vertx. Vertx relies on everything to be asynchronous and it actively looks for threads that block.

So performing something like...

List<Artist> artists = ObjectSelect.query(Artist.class).select(context);

...will result in Vertx complaining with the following:

WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 4750 ms, time limit is 2000

Please note that there are in fact ways to get around this by wrapping the code in an executeBlocking function as follows:

// Turning synchronous code to async in Vertx
vertx.executeBlocking<Any>({ future ->
     List<Artist> artists = ObjectSelect.query(Artist.class).select(context)
     future.complete(artists)
}, { res ->
     // The result
})

However, it becomes a pain to keep wrapping my ORM functions like that.

I wonder if there's a flag or a switch to turn Cayenne asynchronous? Or, if there isn't such a flag, I wonder if there's a way to use the Postgres Async Driver by Mauricio. I pick that specific async driver because Vertx provides native support for it.


Solution

  • Sorry, there is no magic switch to make Cayenne async. Cayenne internally relies heavily on JDBC, which in it's turn is synchronous (and probably will be forever, see good discussion here).

    Moreover dependency on JDBC makes it really hard to use non-jdbc drivers, so no luck here too.

    So custom wrapper suitable for your environment seems your best (if not only) option.