Skip to content
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

Implementation of EntityPart API #4859

Merged
merged 2 commits into from
Sep 22, 2021
Merged

Conversation

jansupol
Copy link
Contributor

Signed-off-by: jansupol [email protected]

@@ -50,6 +52,8 @@

private final Set<HeaderDelegateProvider> hps;
private final Map<Class<?>, HeaderDelegate<?>> map;
private static final Object EPB_LOCK = new Object();
private static volatile EntityPartBuilderProvider cachedEntityPartBuilderProvider;
Copy link
Member

@jbescos jbescos Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get rid of both variables with an inner static class. The good advantage is that there is no need for volatile and to have a lock.

private static class Lazy {

    private static final EntityPartBuilderProvider cachedEntityPartBuilderProvider = findEntityPartBuilderProvider();

    /**
     * Obtain a {@code RuntimeDelegate} instance using the method described in {@link #getInstance}.
     *
     * @return an instance of {@code RuntimeDelegate}.
     */
    private static EntityPartBuilderProvider findEntityPartBuilderProvider() {
        for (final EntityPartBuilderProvider entityPartBuilder : ServiceFinder.find(EntityPartBuilderProvider.class)) {
            if (entityPartBuilder != null) {
                return entityPartBuilder;
            }
        }
        throw new IllegalArgumentException(LocalizationMessages.NO_ENTITYPART_BUILDER_FOUND());
    }
}

And later get the instance in this way. It will be loaded the first time is used.
Lazy.cachedEntityPartBuilderProvider

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may utilize Jersey LazyValue for this

@senivam senivam added this to the 3.1.0 milestone Sep 22, 2021
@jansupol jansupol self-assigned this Sep 22, 2021
@jansupol jansupol merged commit 552fb69 into eclipse-ee4j:3.1 Sep 22, 2021
@jansupol jansupol deleted the entitypart1 branch September 22, 2021 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adopt Multipart API from the new 3.1 API and make Jersey multipart working with the new API
3 participants