-
Notifications
You must be signed in to change notification settings - Fork 34
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
React Renderer: refactor the code, clean it up and make it more generic #859
React Renderer: refactor the code, clean it up and make it more generic #859
Conversation
@@ -13,12 +13,10 @@ | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package io.micronaut.views.react; | |||
package io.micronaut.views.react.util; |
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.
this class should be in micronaut-logging
views-react/src/main/java/io/micronaut/views/react/util/OutputStreamToSLF4J.java
Show resolved
Hide resolved
views-react/src/main/java/io/micronaut/views/react/ReactJSBeanFactory.java
Outdated
Show resolved
Hide resolved
views-react/src/main/java/io/micronaut/views/react/ReactJSContext.java
Outdated
Show resolved
Hide resolved
views-react/src/main/java/io/micronaut/views/react/ReactJSBeanFactory.java
Outdated
Show resolved
Hide resolved
views-react/src/main/java/io/micronaut/views/react/ReactJSBeanFactory.java
Outdated
Show resolved
Hide resolved
views-react/src/main/java/io/micronaut/views/react/ReactJSContext.java
Outdated
Show resolved
Hide resolved
views-react/src/main/java/io/micronaut/views/react/ReactJSContext.java
Outdated
Show resolved
Hide resolved
*/ | ||
@Internal | ||
public class BeanPool<T> { | ||
// TODO: Use @Scheduled to occasionally clear out beans that weren't accessed for a while to recover from traffic spikes. |
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.
address this TODO
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.
Shall we do it in a separate PR? This one is trying to be a functionality no-op as far as possible.
Can this be merged? |
views-react/src/main/java/io/micronaut/views/react/ReactJSBeanFactory.java
Outdated
Show resolved
Hide resolved
@dstepanov PTAL |
I didn't check the PR more closely before, so now I have a better look.
IMHO, the best would be to have |
Sometimes, we would make builders as beans which will allow users to alter the configuration |
Being able to control the context via config etc is a good idea, but it feels like a separate PR. I'm trying to keep this one a functionality no-op, just a refactoring. It's already got quite large. The BeanPool is purged when source files on disk change not when configuration changes, so I didn't fully understand that suggestion, apologies. The existing refresh mechanisms don't seem applicable here. When you say group the synchronized methods with the state, could you elaborate what you have in mind? The style linter doesn't allow fields to be moved next to the methods that manipulate them. Do you mean move the file change listener into the factory? The issue is that the things in the BeanPool are vended by the Factory, so the factory has to be told to re-create the beans in the same way as initially, but it's the owner of the pool that has to clear them. |
I’m talking about the design. The configuration should be affected by the listener, and the bean pool should be affected by the configuration. Now it’s a bit messy. |
Which configuration do you mean? The bean pool is only affected by a change in the checksum of the files on disk, which isn't reflected in any configuration bean. This is for hot reload scenarios. |
I call all the files that affect the context instance as configuration. |
@dstepanov How does it look now? |
@mikehearn Please check mikehearn#1 |
@mikehearn Can you please resolve conflicts and make sure the build is passing? |
Looks like the Java 21 build hit a Gradle bug?! |
This version fixes a JVM crash that occurs with the latest GraalVM, and removes the need for the prior test disables related to sandboxing. The JSON object ordering isn't stable across versions so fix the assumption that it is.
This is a new generic utility useful for not only other Truffle languages, but Micronaut in general. Improved the documentation, efficiency and usability of the class along the way.
This class is generally useful and could be a part of Micronaut (or really, SLF4J itself).
This class is generally useful and could be a part of Micronaut (or really, SLF4J itself).
This makes the code a bit more generic.
List/map access wasn't previously allowed, so in sandbox mode lists and maps wouldn't be exposed to JS and would appear empty.
… and not JS specific.
…that uses Truffle classes.
It's no longer really needed.
…e resources ourselves.
1. ContextPoolManager now encapsulates source loading and reloading. 2. Encapsulated @nAmed("react") behind a custom annotation. 3. The named qualifier resolver is no longer needed.
071be79
to
443862e
Compare
This series of commits is functionally nearly identical to the current code (save for a bug fix to the sandbox that nobody uses yet). However it improves the code in these ways:
utils
sub-package contains classes that could be integrated into Micronaut Core. They aren't React, Graal or Views specific.truffle
sub-package contains classes that could be re-used for a more generic Truffle integration.I hope that in future the generic code can find a new home in other modules.