-
Notifications
You must be signed in to change notification settings - Fork 355
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
Conversation
Signed-off-by: jansupol <[email protected]>
e90bfc5
to
1b18333
Compare
@@ -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; |
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.
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
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.
We may utilize Jersey LazyValue
for this
Signed-off-by: jansupol <[email protected]>
Signed-off-by: jansupol [email protected]