How to do std::move() in vertx

29 views
Skip to first unread message

dekst

unread,
Jun 24, 2016, 3:05:02 PM6/24/16
to vert.x
I have multiple WebServer verticles to share one DbService verticle in a Vertx instance.
How can I pass data to be saved to DB to DbService?
The DbClient is an expensive resource, hence cannot be created with each WebServer instance.

1. EventBus:  I think this is for small size messages.
2. LocalMap:  Does it support JsonObject OR I need to use Json.encode() to encode to string and decode it in DbService?
3. In the main class create a shared version DbClient, and pass it to WebServer constructor?

Which one is the right way?
Do we have anything like std::move() in vertx?

public class WebServer extends AbstractVerticle {
    @Override
    public void start() {
        final Router app = Router.router(vertx);

        app.route().handler(BodyHandler.create());

        app.post(RESOURCE_PATH + "/*").handler(new PostHandler());

        vertx.createHttpServer()
            .requestHandler(app::accept)
            .listen(8080, handler -> {
                if (handler.succeeded()) {
                    Log.d(LOG_TAG, "http://localhost:8080/");
                } else {
                    Log.d(LOG_TAG, "Failed to listen on port 8080");
                }
            });
    }
}

public class DbService extends AbstractVerticle {
      DbClient mDbClient = DbClient.create();
}

Thanks!
Reply all
Reply to author
Forward
0 new messages