-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve Javadoc for VertxInstance stuff #1143
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1053,10 +1053,25 @@ Hibernate Reactive session associated with the context. | |
=== Vert.x instance service | ||
|
||
The `VertxInstance` service defines how Hibernate Reactive obtains an instance | ||
of Vert.x. The default implementation just creates one the first time it's | ||
needed. But if your program requires control over how the Vert.x instance is | ||
created, or how it's obtained, you can override the default implementation and | ||
provide your own `VertxInstance`. Let's consider this example: | ||
of Vert.x when there is no instance associated with the calling thread. The | ||
default implementation just creates one the first time it's needed. But if your | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't it create one when the service is started? So when the SessionFactory is started There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. So then it's sort-of a bigger problem than I thought. But default we go creating an instance of Vert.x even if we don't know we're going to need it. |
||
program requires control over how the Vert.x instance is created, or how it's | ||
obtained, you can override the default implementation and provide your own | ||
`VertxInstance`. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about anything written after this point. I think there are only two things to mention:
The user needs to do something only if this is not the behaviour they want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sorry, I mean it logs the message when a new Vertx instance is created There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also mention that when Hibernate Reactive creates a new instance of Vert.x, it will also shut it down when the factory gets closed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See what I documented is how I actually want it to work. But you're right: it doesn't work like that today. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well, naively. |
||
IMPORTANT: If your program starts Vert.x externally to Hibernate Reactive, and | ||
you don't tell Hibernate Reactive how to obtain this instance of Vert.x by | ||
specifying an implementation of `VertxInstance`, you might end up with multiple | ||
instances of `Vertx` in your program, resulting in confusing error messages. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this a bug from our side? Shouldn't everything work anyway even if we start a different Vert.x instance? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I would expect it to work if one uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the program already has a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember reading that one could use these scenario if they want different event busses for different groups of Verticles. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found it! It was in the Vert.x documentation:
|
||
|
||
There are two ways to solve this problem: | ||
|
||
- make sure Hibernate Reactive is never called from a thread with no current | ||
Vert.x context, by using `runOnContext()` in a disciplined way, as described | ||
in the previous section, or | ||
- provide your own implementation of `VertxInstance`. | ||
|
||
Let's consider this example: | ||
|
||
[source, JAVA, indent=0] | ||
---- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,15 @@ | |
* A singleton instance of {@link Vertx} that is created on | ||
* demand and destroyed automatically along with the Hibernate | ||
* {@link org.hibernate.SessionFactory#close() session factory}. | ||
* <p> | ||
* Programs which require Hibernate reactive to use an instance | ||
* of {@code Vertx} whose lifecycle is managed externally to | ||
* Hibernate Reactive should use {@link ProvidedVertxInstance} | ||
* instead. | ||
* | ||
* @author Sanne Grinovero <[email protected]> | ||
* @see ProvidedVertxInstance if you need to a different instance | ||
* | ||
* @see ProvidedVertxInstance | ||
*/ | ||
public final class DefaultVertxInstance implements VertxInstance, Stoppable, Startable { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
|
||
/** | ||
* An implementation of {@link VertxInstance} which allows the client | ||
* to provide an instance of {@link Vertx} whose lifecyle is managed | ||
* to provide an instance of {@link Vertx} whose lifecycle is managed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not part of your changes, but a few lines after this it states:
This is not true though, isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's copied from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yah, looks wrong. |
||
* externally to Hibernate Reactive. The {@code ProvidedVertxInstance} | ||
* must be registered explicitly with Hibernate by calling | ||
* {@link org.hibernate.reactive.provider.ReactiveServiceRegistryBuilder#addService}. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, it also defines how Hibernate Reactive obtains Vert.x even if there is one associated to the Thread.
Isn't this a bit misleading?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ummmmm. Hrrrrmmmm. Yeah, right. See there's a bit of a slightly confusing interplay between
VertxContext
andVertxInstance
here. TBH I've never completely understood the significance of:Like .... why don't we just use the
Vertx.currentContext()
if there is one? Why do we insist on it being the one coming from "our" Vert.x?I mean, I know why we do it that way: because that's what @cescoffier and @vietj told us to do, but I think I need to understand it better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
io.vertx.core.Vertx
.io.vertx.core.Context
.So,
DefaultVertxInstance
is responsible for1
,org.hibernate.reactive.context.impl.VertxContext
is responsible for2
.But the
VertxInstance
service is always called when the factory is started (with or without an existing Vert.x instance), that's why I said that the linewhen there is no instance associated with the calling thread.
doesn't seem correct (it implies that it gets called only when there is no Vert.x instance).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it makes sure that 1. we are running in a context (it will create a new one if one doesn't exist) and 2. an existing session run the operations always in the same context and that should imply the same thread (this is the part where I'm never sure).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I need to think more about this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, me too.
And I think perhaps we should wait until @Sanne gets back and discuss it thoroughly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember in the beginning we had a lot of issues with operations not running in the right context when using Quarkus.