Martin Peřina has uploaded a new change for review. Change subject: core: Delays JNDI binding in Injector until needed ......................................................................
core: Delays JNDI binding in Injector until needed Moves JNDI binding of BeanManager from constructor to private method getManager(), so this JNDI binding is not executed until first injection of a bean. This allow to run tests using CommandsFactory that doesn't need CDI environment (QuotaDependencyTest). Change-Id: I776169e8f1b906395ef9290093c18aeaebf489db Signed-off-by: Martin Perina <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Injector.java 1 file changed, 19 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/04/18904/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Injector.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Injector.java index ec9102a..c6fe96c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Injector.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Injector.java @@ -9,19 +9,28 @@ private BeanManager manager; - public Injector() { - try { - this.manager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); - } catch (NamingException e) { - // if the bean manager couldn't be fetched then we couldn't inject dependencies to non-bean objects - throw new RuntimeException("Couldn't locate a BeanManager instance due to " + e.getMessage() - + " Actions will fail to perform due to runtime missing dependencies"); + /** + * Returns {@code BeanManager} instance. If the instance is not initialized, it performs JNDI lookup to initialize + * it. + * @return {@code BeanManager} instance + */ + private BeanManager getManager() { + if (manager == null) { + try { + this.manager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); + } catch (NamingException e) { + // if the bean manager couldn't be fetched then we couldn't inject dependencies to non-bean objects + throw new RuntimeException("Couldn't locate a BeanManager instance due to " + e.getMessage() + + " Actions will fail to perform due to runtime missing dependencies"); + } } + return manager; } - public <T extends Object> void inject(T instance) { - AnnotatedType type = manager.createAnnotatedType(instance.getClass()); - manager.createInjectionTarget(type).inject(instance, manager.createCreationalContext(null)); + @SuppressWarnings({ "rawtypes", "unchecked" }) + public <T extends Object> void inject(T instance) { + AnnotatedType type = getManager().createAnnotatedType(instance.getClass()); + getManager().createInjectionTarget(type).inject(instance, getManager().createCreationalContext(null)); } } -- To view, visit http://gerrit.ovirt.org/18904 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I776169e8f1b906395ef9290093c18aeaebf489db Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Peřina <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
