commit be72d8e642c8e4e169bb9f8eecc98750b0206f67 Author: Sanjeeb Sahoo Date: Tue Nov 15 00:11:29 2011 +0530 Lazy loading of naming proxies: - Added a new annotation called NamingObjectForPrefixes. It is annotated as Contract and has an index attribute. - NamedNamingObjectProxies use this annotation to describe the naming prefixes handled by them. - Changed every existing NamedNamingObjectProxy to be annotated with this new one. - Changed NamingManager implementation to select the proxy by looking at the prefix metadata. - This allows lazy instantiation of proxies. Changed JTA to register a NamingProxy for UserTransaction in startup service. It registers a proxy that replaces itself by actual object. This avoids circular dependency between naming and transaction. diff --git appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/impl/JavaModuleNamingProxy.java appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/impl/JavaModuleNamingProxy.java index 9d78773..0e6c110 100644 --- appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/impl/JavaModuleNamingProxy.java +++ appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/impl/JavaModuleNamingProxy.java @@ -41,9 +41,8 @@ package com.sun.enterprise.container.common.impl; +import org.glassfish.api.naming.NamingObjectForPrefixes; import org.glassfish.api.naming.NamedNamingObjectProxy; -import org.glassfish.api.invocation.ComponentInvocation; -import org.glassfish.api.admin.*; import com.sun.enterprise.deployment.*; @@ -60,7 +59,6 @@ import com.sun.enterprise.container.common.spi.ManagedBeanManager; import com.sun.logging.LogDomains; import javax.naming.*; -import java.util.Hashtable; import java.util.logging.Level; import java.util.logging.Logger; @@ -69,6 +67,10 @@ import org.glassfish.api.admin.ProcessEnvironment.ProcessType; @Service +@NamingObjectForPrefixes({JavaModuleNamingProxy.JAVA_APP_CONTEXT, + JavaModuleNamingProxy.JAVA_APP_NAME, + JavaModuleNamingProxy.JAVA_MODULE_CONTEXT, + JavaModuleNamingProxy.JAVA_MODULE_NAME}) public class JavaModuleNamingProxy implements NamedNamingObjectProxy, PostConstruct { @@ -96,16 +98,16 @@ public class JavaModuleNamingProxy processType = processEnv.getProcessType(); } - private static final String JAVA_MODULE_CONTEXT + static final String JAVA_MODULE_CONTEXT = "java:module/"; - private static final String JAVA_APP_CONTEXT + static final String JAVA_APP_CONTEXT = "java:app/"; - private static final String JAVA_APP_NAME + static final String JAVA_APP_NAME = "java:app/AppName"; - private static final String JAVA_MODULE_NAME + static final String JAVA_MODULE_NAME = "java:module/ModuleName"; public Object handle(String name) throws NamingException { diff --git appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextNamingProxy.java appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextNamingProxy.java index 747442f..15ca3d0 100644 --- appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextNamingProxy.java +++ appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContextNamingProxy.java @@ -40,12 +40,12 @@ package com.sun.ejb.containers; +import org.glassfish.api.naming.NamingObjectForPrefixes; import org.glassfish.api.naming.NamedNamingObjectProxy; import org.glassfish.api.invocation.ComponentInvocation; import com.sun.ejb.EjbInvocation; -import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.annotations.Service; import javax.naming.NamingException; @@ -58,10 +58,11 @@ import javax.naming.NamingException; * @author Ken Saks */ @Service +@NamingObjectForPrefixes(EJBContextNamingProxy.EJB_CONTEXT) public class EJBContextNamingProxy implements NamedNamingObjectProxy { - private static final String EJB_CONTEXT + static final String EJB_CONTEXT = "java:comp/EJBContext"; public Object handle(String name) throws NamingException { diff --git appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/InternalInterceptorBindingNamingProxy.java appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/InternalInterceptorBindingNamingProxy.java index c5fc387..09e4eb1 100644 --- appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/InternalInterceptorBindingNamingProxy.java +++ appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/InternalInterceptorBindingNamingProxy.java @@ -40,10 +40,8 @@ package com.sun.ejb.containers; +import org.glassfish.api.naming.NamingObjectForPrefixes; import org.glassfish.api.naming.NamedNamingObjectProxy; -import org.glassfish.api.invocation.ComponentInvocation; - -import com.sun.ejb.EjbInvocation; import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.annotations.Service; @@ -58,13 +56,14 @@ import javax.naming.NamingException; * @author Ken Saks */ @Service +@NamingObjectForPrefixes(InternalInterceptorBindingNamingProxy.INTERCEPTOR_BINDING) public class InternalInterceptorBindingNamingProxy implements NamedNamingObjectProxy { @Inject private Habitat habitat; - private static final String INTERCEPTOR_BINDING + static final String INTERCEPTOR_BINDING = "java:org.glassfish.ejb.container.interceptor_binding_spi"; public Object handle(String name) throws NamingException { diff --git appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/TimerServiceNamingProxy.java appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/TimerServiceNamingProxy.java index 12142de..201aee1 100644 --- appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/TimerServiceNamingProxy.java +++ appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/TimerServiceNamingProxy.java @@ -40,12 +40,12 @@ package com.sun.ejb.containers; +import org.glassfish.api.naming.NamingObjectForPrefixes; import org.glassfish.api.naming.NamedNamingObjectProxy; import org.glassfish.api.invocation.ComponentInvocation; import com.sun.ejb.EjbInvocation; -import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.annotations.Service; import javax.naming.NamingException; @@ -58,10 +58,11 @@ import javax.naming.NamingException; * @author Marina Vatkina */ @Service +@NamingObjectForPrefixes(TimerServiceNamingProxy.EJB_TIMER_SERVICE) public class TimerServiceNamingProxy implements NamedNamingObjectProxy { - private static final String EJB_TIMER_SERVICE + static final String EJB_TIMER_SERVICE = "java:comp/TimerService"; public Object handle(String name) throws NamingException { diff --git appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/HandleDelegateNamingProxy.java appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/HandleDelegateNamingProxy.java index 40d83db..fa83254 100644 --- appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/HandleDelegateNamingProxy.java +++ appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/HandleDelegateNamingProxy.java @@ -40,6 +40,7 @@ package org.glassfish.enterprise.iiop.api; +import org.glassfish.api.naming.NamingObjectForPrefixes; import org.glassfish.api.naming.NamedNamingObjectProxy; import org.jvnet.hk2.annotations.Service; @@ -57,9 +58,10 @@ import javax.naming.NamingException; * @author Ken Saks */ @Service +@NamingObjectForPrefixes(HandleDelegateNamingProxy.HANDLE_DELEGATE) public class HandleDelegateNamingProxy implements NamedNamingObjectProxy { - private static final String HANDLE_DELEGATE + static final String HANDLE_DELEGATE = "java:comp/HandleDelegate"; @Inject diff --git appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ORBNamingProxy.java appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ORBNamingProxy.java index c190fa2..a0a7950 100644 --- appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ORBNamingProxy.java +++ appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ORBNamingProxy.java @@ -40,6 +40,7 @@ package org.glassfish.enterprise.iiop.api; +import org.glassfish.api.naming.NamingObjectForPrefixes; import org.glassfish.api.naming.NamedNamingObjectProxy; import org.jvnet.hk2.annotations.Service; @@ -56,9 +57,10 @@ import javax.naming.NamingException; * @author Ken Saks */ @Service +@NamingObjectForPrefixes(ORBNamingProxy.ORB_CONTEXT) public class ORBNamingProxy implements NamedNamingObjectProxy { - private static final String ORB_CONTEXT + static final String ORB_CONTEXT = "java:comp/ORB"; @Inject diff --git appserver/transaction/internal-api/src/main/java/com/sun/enterprise/transaction/connector/TxStartupService.java appserver/transaction/internal-api/src/main/java/com/sun/enterprise/transaction/connector/TxStartupService.java new file mode 100644 index 0000000..6f8d924 --- /dev/null +++ appserver/transaction/internal-api/src/main/java/com/sun/enterprise/transaction/connector/TxStartupService.java @@ -0,0 +1,93 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + + +package com.sun.enterprise.transaction.connector; + +import com.sun.enterprise.transaction.config.TransactionService; +import org.glassfish.api.Startup; +import org.glassfish.api.naming.GlassfishNamingManager; +import org.glassfish.api.naming.NamingObjectProxy; +import org.glassfish.hk2.Services; +import org.jvnet.hk2.annotations.Inject; +import org.jvnet.hk2.annotations.Service; +import org.jvnet.hk2.component.PostConstruct; + +import javax.naming.Context; +import javax.naming.NamingException; + +/** + * @author Sanjeeb.Sahoo@Sun.COM + */ +@Service +public class TxStartupService implements Startup, PostConstruct { + + @Inject(optional = true) + TransactionService transactionService; + + @Inject + GlassfishNamingManager nm; + + @Inject + Services services; + + static final String USER_TX_NO_JAVA_COMP = "UserTransaction"; + + @Override + public Lifecycle getLifecycle() { + return Lifecycle.START; + } + + @Override + public void postConstruct() { + if (nm != null) { + try { + nm.publishObject(USER_TX_NO_JAVA_COMP, new NamingObjectProxy.InitializationNamingObjectProxy() { + @Override + public Object create(Context ic) throws NamingException { + return services.forContract("javax.transaction.UserTransaction").get(); + } + }, false); + } catch (NamingException e) { + throw new RuntimeException(e); // TODO(Sahoo): Proper Exception Handling + } + } + } +} diff --git appserver/transaction/jta/src/main/java/com/sun/enterprise/transaction/TransactionNamingProxy.java appserver/transaction/jta/src/main/java/com/sun/enterprise/transaction/TransactionNamingProxy.java index 70b6e67..d2d2854 100644 --- appserver/transaction/jta/src/main/java/com/sun/enterprise/transaction/TransactionNamingProxy.java +++ appserver/transaction/jta/src/main/java/com/sun/enterprise/transaction/TransactionNamingProxy.java @@ -40,10 +40,7 @@ package com.sun.enterprise.transaction; -import org.glassfish.api.naming.GlassfishNamingManager; -import org.glassfish.api.naming.NamedNamingObjectProxy; -import org.glassfish.api.naming.NamingObjectProxy; -import org.glassfish.api.naming.NamingObjectsProvider; +import org.glassfish.api.naming.*; //import org.glassfish.api.naming.GlassfishNamingManager; //import org.glassfish.api.admin.ProcessEnvironment; //import org.glassfish.api.admin.ProcessEnvironment.ProcessType; @@ -72,8 +69,12 @@ import java.util.logging.Logger; * @author Marina Vatkina */ @Service +@NamingObjectForPrefixes({TransactionNamingProxy.USER_TX, + TransactionNamingProxy.TRANSACTION_SYNC_REGISTRY, + TransactionNamingProxy.APPSERVER_TRANSACTION_MGR, + TransactionNamingProxy.APPSERVER_TRANSACTION_SYNC_REGISTRY}) public class TransactionNamingProxy - implements NamedNamingObjectProxy, NamingObjectsProvider, PostConstruct { + implements NamedNamingObjectProxy/*, NamingObjectsProvider, PostConstruct*/ { @Inject private Habitat habitat; @@ -86,19 +87,19 @@ public class TransactionNamingProxy private static Logger logger = LogDomains.getLogger(TransactionNamingProxy.class, LogDomains.JTA_LOGGER); - private static final String USER_TX = "java:comp/UserTransaction"; - private static final String USER_TX_NO_JAVA_COMP = "UserTransaction"; + static final String USER_TX = "java:comp/UserTransaction"; + static final String USER_TX_NO_JAVA_COMP = "UserTransaction"; - private static final String TRANSACTION_SYNC_REGISTRY + static final String TRANSACTION_SYNC_REGISTRY = "java:comp/TransactionSynchronizationRegistry"; - private static final String APPSERVER_TRANSACTION_SYNC_REGISTRY + static final String APPSERVER_TRANSACTION_SYNC_REGISTRY = "java:appserver/TransactionSynchronizationRegistry"; - private static final String TRANSACTION_MGR + static final String TRANSACTION_MGR = "java:pm/TransactionManager"; - private static final String APPSERVER_TRANSACTION_MGR + static final String APPSERVER_TRANSACTION_MGR = "java:appserver/TransactionManager"; public void postConstruct() { diff --git appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanManagerNamingProxy.java appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanManagerNamingProxy.java index ca983d3..c0df608 100644 --- appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanManagerNamingProxy.java +++ appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanManagerNamingProxy.java @@ -44,6 +44,7 @@ import javax.naming.NamingException; import org.glassfish.api.invocation.ComponentInvocation; import org.glassfish.api.invocation.InvocationManager; +import org.glassfish.api.naming.NamingObjectForPrefixes; import org.glassfish.api.naming.NamedNamingObjectProxy; import org.jboss.weld.bootstrap.WeldBootstrap; import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive; @@ -63,6 +64,7 @@ import com.sun.enterprise.deployment.WebBundleDescriptor; * @author Ken Saks */ @Service +@NamingObjectForPrefixes(value = BeanManagerNamingProxy.BEAN_MANAGER_CONTEXT) public class BeanManagerNamingProxy implements NamedNamingObjectProxy { @Inject @@ -74,7 +76,7 @@ public class BeanManagerNamingProxy implements NamedNamingObjectProxy { @Inject private WeldDeployer weldDeployer; - private static final String BEAN_MANAGER_CONTEXT + static final String BEAN_MANAGER_CONTEXT = "java:comp/BeanManager"; diff --git nucleus/common/glassfish-api/src/main/java/org/glassfish/api/naming/NamingObjectForPrefixes.java nucleus/common/glassfish-api/src/main/java/org/glassfish/api/naming/NamingObjectForPrefixes.java new file mode 100644 index 0000000..db18330 --- /dev/null +++ nucleus/common/glassfish-api/src/main/java/org/glassfish/api/naming/NamingObjectForPrefixes.java @@ -0,0 +1,66 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + + +package org.glassfish.api.naming; + +import org.jvnet.hk2.annotations.Contract; +import org.jvnet.hk2.annotations.Index; +import org.jvnet.hk2.annotations.Service; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Goes with {@link Service} annotation on a {@link NamedNamingObjectProxy}. Using this annotation + * a {@link NamedNamingObjectProxy} indicates what namespace prefixes are handled by a proxy. This extra metadata + * enabled lazy instantiation of {@link NamedNamingObjectProxy} objects. + * + * @author Sanjeeb.Sahoo@Sun.COM + */ +@Contract +@Retention(RUNTIME) +@Target(ElementType.TYPE) +public @interface NamingObjectForPrefixes { + @Index String[] value(); +} diff --git nucleus/common/glassfish-naming/src/main/java/com/sun/enterprise/naming/impl/NamedNamingObjectManager.java nucleus/common/glassfish-naming/src/main/java/com/sun/enterprise/naming/impl/NamedNamingObjectManager.java index 90ff61c..47253d0 100644 --- nucleus/common/glassfish-naming/src/main/java/com/sun/enterprise/naming/impl/NamedNamingObjectManager.java +++ nucleus/common/glassfish-naming/src/main/java/com/sun/enterprise/naming/impl/NamedNamingObjectManager.java @@ -41,13 +41,18 @@ package com.sun.enterprise.naming.impl; import org.glassfish.api.naming.NamedNamingObjectProxy; -import org.glassfish.api.naming.GlassfishNamingManager; +import org.glassfish.api.naming.NamingObjectForPrefixes; import org.jvnet.hk2.component.Habitat; +import org.jvnet.hk2.component.Inhabitant; import javax.naming.NamingException; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import java.util.List; -import java.util.ArrayList; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @author Mahesh Kannan @@ -55,43 +60,90 @@ import java.util.ArrayList; */ public class NamedNamingObjectManager { - private static AtomicReference gotAllNamedProxies - = new AtomicReference(); + private static final AtomicReference habitat + = new AtomicReference(); - private static List proxies = new ArrayList(); + private static final Map proxies = new HashMap(); + private static final ReadWriteLock rwLock = new ReentrantReadWriteLock(); + + private static final Logger logger = Logger.getLogger(NamedNamingObjectManager.class.getPackage().getName()); public static void checkAndLoadProxies(Habitat habitat) - throws NamingException { - if (gotAllNamedProxies.get() != habitat) { + throws NamingException { + if (NamedNamingObjectManager.habitat.get() != habitat) { if (habitat != null) { - synchronized (gotAllNamedProxies) { - if (gotAllNamedProxies.get() != habitat) { + rwLock.writeLock().lock(); + try { + if (NamedNamingObjectManager.habitat.get() != habitat) { + NamedNamingObjectManager.habitat.set(habitat); proxies.clear(); - GlassfishNamingManager nm = - habitat.getByContract(GlassfishNamingManager.class); - for (NamedNamingObjectProxy proxy : habitat.getAllByContract(NamedNamingObjectProxy.class)) { - //System.out.println("Got NamedNamingObjectProxy: " + proxy.getClass().getName()); - proxies.add(proxy); - } - gotAllNamedProxies.set(habitat); } + } finally { + rwLock.writeLock().unlock(); } } } } public static Object tryNamedProxies(String name) - throws NamingException { + throws NamingException { + + NamedNamingObjectProxy proxy = getCachedProxy(name); + if (proxy != null) { + logger.logp(Level.INFO, "NamedNamingObjectManager", "tryNamedProxies", "found cached proxy [{0}] for [{1}]", new Object[]{proxy, name}); + return proxy.handle(name); + } - Object obj = null; - for (NamedNamingObjectProxy proxy : proxies) { - obj = proxy.handle(name); - if (obj != null) { - break; +// for (Binding b : getHabitat().getBindings(new NamingDescriptor())) { +// for (String prefix : b.getDescriptor().getNames()) { +// if (name.startsWith(prefix)) { +// proxy = (NamedNamingObjectProxy) b.getProvider().get(); +// System.out.println("NamedNamingObjectManager.tryNamedProxies: found a proxy " + proxy + " for " + name); +// cacheProxy(prefix, proxy); +// return proxy.handle(name); +// } +// } +// } + for (Inhabitant inhabitant : getHabitat().getInhabitants(NamingObjectForPrefixes.class)) { + for (String prefix : inhabitant.getDescriptor().getNames()) { + if (name.startsWith(prefix)) { + proxy = (NamedNamingObjectProxy) inhabitant.get(); + logger.logp(Level.INFO, "NamedNamingObjectManager", "tryNamedProxies", "found a new proxy [{0}] for [{1}]", new Object[]{proxy, name}); + cacheProxy(prefix, proxy); + return proxy.handle(name); + } } } - return obj; + return null; } + + private static Habitat getHabitat() { + return habitat.get(); + } + + private static NamedNamingObjectProxy getCachedProxy(String name) { + rwLock.readLock().lock(); + try { + for (String proxyPrefix : proxies.keySet()) { + if (name.startsWith(proxyPrefix)) { + return proxies.get(proxyPrefix); + } + } + } finally { + rwLock.readLock().unlock(); + } + return null; + } + + private static void cacheProxy(String prefix, NamedNamingObjectProxy proxy) { + rwLock.writeLock().lock(); + try { + proxies.put(prefix, proxy); + } finally { + rwLock.writeLock().unlock(); + } + } + } diff --git nucleus/core/kernel/src/main/java/org/glassfish/kernel/bean_validator/BeanValidatorNamingProxy.java nucleus/core/kernel/src/main/java/org/glassfish/kernel/bean_validator/BeanValidatorNamingProxy.java index d10c41d..f01bd5e 100644 --- nucleus/core/kernel/src/main/java/org/glassfish/kernel/bean_validator/BeanValidatorNamingProxy.java +++ nucleus/core/kernel/src/main/java/org/glassfish/kernel/bean_validator/BeanValidatorNamingProxy.java @@ -45,10 +45,13 @@ import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorContext; import javax.validation.ValidatorFactory; + +import org.glassfish.api.naming.NamingObjectForPrefixes; import org.glassfish.api.naming.NamedNamingObjectProxy; import org.jvnet.hk2.annotations.Service; @Service +@NamingObjectForPrefixes({BeanValidatorNamingProxy.nameForValidator, BeanValidatorNamingProxy.nameForValidatorFactory}) public class BeanValidatorNamingProxy implements NamedNamingObjectProxy { static final String nameForValidator = "java:comp/Validator";