[jboss-cvs] JBossAS SVN: r106334 - in projects/jboss-jca/trunk: core/src/main/java/org/jboss/jca/core and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 29 16:53:12 EDT 2010
Author: jesper.pedersen
Date: 2010-06-29 16:53:10 -0400 (Tue, 29 Jun 2010)
New Revision: 106334
Added:
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/naming/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/naming/SimpleJndiStrategy.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/naming/package.html
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/naming/
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/naming/JndiStrategy.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/naming/package.html
Removed:
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/
projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/
Modified:
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployment.java
projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml
projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml
projects/jboss-jca/trunk/standalone/src/main/resources/bootstrap/jca.xml
Log:
[JBJCA-370] Create a naming SPI
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/naming/SimpleJndiStrategy.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/naming/SimpleJndiStrategy.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/naming/SimpleJndiStrategy.java 2010-06-29 20:53:10 UTC (rev 106334)
@@ -0,0 +1,197 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.naming;
+
+import org.jboss.jca.core.spi.naming.JndiStrategy;
+
+import java.util.Hashtable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.resource.Referenceable;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.naming.Util;
+
+/**
+ * A simple JNDI strategy
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class SimpleJndiStrategy implements JndiStrategy
+{
+ private static Logger log = Logger.getLogger(SimpleJndiStrategy.class);
+
+ /** JNDI prefix */
+ private static final String JNDI_PREFIX = "java:/eis/";
+
+ private static ConcurrentMap<String, Object> connectionFactories = new ConcurrentHashMap<String, Object>();
+
+ /**
+ * Constructor
+ */
+ public SimpleJndiStrategy()
+ {
+ }
+
+ /**
+ * Obtain the connection factory
+ * {@inheritDoc}
+ */
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
+ throws Exception
+ {
+ Reference ref = (Reference)obj;
+ String className = (String)ref.get("class").getContent();
+ String cfname = (String)ref.get("name").getContent();
+
+ return connectionFactories.get(qualifiedName(cfname, className));
+ }
+
+ /**
+ * Bind connection factories for a deployment
+ * @param deployment The deployment name
+ * @param cfs The connection factories
+ * @return The JNDI names for the connection factories
+ * @exception Throwable Thrown if an error occurs
+ */
+ public String[] bindConnectionFactories(String deployment, Object[] cfs) throws Throwable
+ {
+ if (deployment == null)
+ throw new IllegalArgumentException("Deployment is null");
+
+ if (deployment.trim().equals(""))
+ throw new IllegalArgumentException("Deployment is empty");
+
+ if (cfs == null)
+ throw new IllegalArgumentException("CFS is null");
+
+ if (cfs.length == 0)
+ throw new IllegalArgumentException("CFS is empty");
+
+ if (cfs.length > 1)
+ throw new IllegalArgumentException("SimpleJndiStrategy only support " +
+ "a single connection factory per deployment");
+
+ String jndiName = JNDI_PREFIX + deployment;
+
+ Object cf = cfs[0];
+
+ Context context = new InitialContext();
+ try
+ {
+ String className = cf.getClass().getName();
+ Reference ref = new Reference(className,
+ new StringRefAddr("class", className),
+ SimpleJndiStrategy.class.getName(),
+ null);
+ ref.add(new StringRefAddr("name", jndiName));
+
+ if (connectionFactories.putIfAbsent(qualifiedName(jndiName, className), cf) != null)
+ throw new Exception("Deployment " + className + " failed, " + jndiName + " is already deployed");
+
+ Referenceable referenceable = (Referenceable)cf;
+ referenceable.setReference(ref);
+
+ Util.bind(context, jndiName, cf);
+ }
+ finally
+ {
+ context.close();
+ }
+
+ return new String[] {jndiName};
+ }
+
+ /**
+ * Unbind connection factories for a deployment
+ * @param deployment The deployment name
+ * @param jndiNames The JNDI names for the connection factories
+ * @exception Throwable Thrown if an error occurs
+ */
+ public void unbindConnectionFactories(String deployment, String[] jndiNames) throws Throwable
+ {
+ if (jndiNames == null)
+ throw new IllegalArgumentException("JndiNames is null");
+
+ Context context = null;
+ try
+ {
+ context = new InitialContext();
+
+ for (String jndiName : jndiNames)
+ {
+ connectionFactories.remove(jndiName);
+
+ try
+ {
+ Util.unbind(context, jndiName);
+ }
+ catch (Throwable it)
+ {
+ log.warn("Exception during JNDI unbind for: " + jndiName, it);
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ log.warn("Exception during JNDI initialization", t);
+ }
+ finally
+ {
+ if (context != null)
+ {
+ try
+ {
+ context.close();
+ }
+ catch (NamingException ne)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ /**
+ * Clone the JNDI strategy implementation
+ * @return A copy of the implementation
+ * @exception CloneNotSupportedException Thrown if the copy operation isn't supported
+ *
+ */
+ public JndiStrategy clone() throws CloneNotSupportedException
+ {
+ return (JndiStrategy)super.clone();
+ }
+
+ private static String qualifiedName(String name, String className)
+ {
+ return className + "#" + name;
+ }
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/naming/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/naming/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/naming/package.html 2010-06-29 20:53:10 UTC (rev 106334)
@@ -0,0 +1,3 @@
+<body>
+This package contains implementation of naming strategies for connection factory binding.
+</body>
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/naming/JndiStrategy.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/naming/JndiStrategy.java (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/naming/JndiStrategy.java 2010-06-29 20:53:10 UTC (rev 106334)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.spi.naming;
+
+import javax.naming.spi.ObjectFactory;
+
+/**
+ * The SPI for a JNDI strategy
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public interface JndiStrategy extends Cloneable, ObjectFactory
+{
+ /**
+ * Bind connection factories for a deployment
+ * @param deployment The deployment name
+ * @param cfs The connection factories
+ * @return The JNDI names for the connection factories
+ * @exception Throwable Thrown if an error occurs
+ */
+ public String[] bindConnectionFactories(String deployment, Object[] cfs) throws Throwable;
+
+ /**
+ * Unbind connection factories for a deployment
+ * @param deployment The deployment name
+ * @param jndiNames The JNDI names for the connection factories
+ * @exception Throwable Thrown if an error occurs
+ */
+ public void unbindConnectionFactories(String deployment, String[] jndiNames) throws Throwable;
+
+ /**
+ * Clone the JNDI strategy implementation
+ * @return A copy of the implementation
+ * @exception CloneNotSupportedException Thrown if the copy operation isn't supported
+ *
+ */
+ public JndiStrategy clone() throws CloneNotSupportedException;
+}
Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/naming/package.html
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/naming/package.html (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/naming/package.html 2010-06-29 20:53:10 UTC (rev 106334)
@@ -0,0 +1,3 @@
+<body>
+This package contains the SPI for the JNDI strategy for connection factory binding.
+</body>
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java 2010-06-29 20:02:22 UTC (rev 106333)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java 2010-06-29 20:53:10 UTC (rev 106334)
@@ -23,17 +23,14 @@
package org.jboss.jca.deployers.fungal;
import org.jboss.jca.common.annotations.Annotations;
-import org.jboss.jca.common.api.ConnectionFactoryBuilder;
-import org.jboss.jca.common.api.ConnectionFactoryJndiNameBuilder;
import org.jboss.jca.common.metadata.Metadata;
-import org.jboss.jca.common.util.ContainerConnectionFactoryJndiNameBuilder;
-import org.jboss.jca.common.util.LocalConnectionFactoryBuilder;
import org.jboss.jca.core.api.CloneableBootstrapContext;
import org.jboss.jca.core.connectionmanager.AbstractConnectionManager;
import org.jboss.jca.core.connectionmanager.notx.NoTxConnectionManager;
import org.jboss.jca.core.connectionmanager.pool.PoolParams;
import org.jboss.jca.core.connectionmanager.pool.strategy.OnePool;
import org.jboss.jca.core.connectionmanager.tx.TxConnectionManager;
+import org.jboss.jca.core.spi.naming.JndiStrategy;
import org.jboss.jca.validator.Failure;
import org.jboss.jca.validator.FailureHelper;
import org.jboss.jca.validator.Key;
@@ -65,8 +62,6 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
-import javax.naming.Context;
-import javax.naming.InitialContext;
import javax.resource.Referenceable;
import javax.resource.spi.BootstrapContext;
import javax.resource.spi.ManagedConnectionFactory;
@@ -87,7 +82,6 @@
import org.jboss.metadata.rar.spec.JCA10DTDMetaData;
import org.jboss.metadata.rar.spec.MessageListenerMetaData;
import org.jboss.metadata.rar.spec.TransactionSupportMetaData;
-import org.jboss.util.naming.Util;
import com.github.fungal.api.classloading.ClassLoaderFactory;
import com.github.fungal.api.classloading.KernelClassLoader;
@@ -138,6 +132,9 @@
/** Scope deployment */
private static AtomicBoolean scopeDeployment = new AtomicBoolean(false);
+ /** JNDI strategy */
+ private static JndiStrategy jndiStrategy = null;
+
/**
* Constructor
*/
@@ -308,6 +305,24 @@
}
/**
+ * Set the JNDI strategy
+ * @param value The value
+ */
+ public synchronized void setJndiStrategy(JndiStrategy value)
+ {
+ jndiStrategy = value;
+ }
+
+ /**
+ * Get the JNDI strategy
+ * @return The handle
+ */
+ public synchronized JndiStrategy getJndiStrategy()
+ {
+ return jndiStrategy;
+ }
+
+ /**
* Deploy
* @param url The url
* @param parent The parent classloader
@@ -382,7 +397,7 @@
List<Failure> partialFailures = null;
List<Object> beanValidationObjects = new ArrayList<Object>();
- List<String> jndiNames = null;
+ String[] jndiNames = null;
// Create objects and inject values
if (cmd != null)
@@ -548,17 +563,11 @@
{
if (cdMetas.size() == 1)
{
- if (jndiNames == null)
- jndiNames = new ArrayList<String>(1);
-
- ConnectionFactoryJndiNameBuilder jndiNameBuilder = getJndiNameBuilder();
String deploymentName = f.getName().substring(0, f.getName().indexOf(".rar"));
- jndiNameBuilder.setConnectionFactory(cf.getClass().getName());
- jndiNameBuilder.setDeploymentName(deploymentName);
- String jndiName = jndiNameBuilder.build();
+ String[] jns = bindConnectionFactory(deploymentName, cf);
- bindConnectionFactory(jndiName, (Serializable)cf, mcf);
- jndiNames.add(jndiName);
+ if (jns != null)
+ jndiNames = jns;
}
else
{
@@ -727,7 +736,7 @@
log.info("Deployed: " + url.toExternalForm());
- return new RADeployment(url, resourceAdapter, jndiNames, destination, cl);
+ return new RADeployment(url, resourceAdapter, jndiStrategy, jndiNames, destination, cl);
}
catch (DeployException de)
{
@@ -878,17 +887,6 @@
return false;
}
- private ConnectionFactoryBuilder getConnectionFactoryBuilder()
- {
- return new LocalConnectionFactoryBuilder();
- }
-
- private ConnectionFactoryJndiNameBuilder getJndiNameBuilder()
- {
- return new ContainerConnectionFactoryJndiNameBuilder();
- }
-
-
/**
* Start the resource adapter
* @param resourceAdapter The resource adapter
@@ -1028,29 +1026,16 @@
/**
* Bind connection factory into JNDI
- * @param name The JNDI name
+ * @param deployment The deployment name
* @param cf The connection factory
- * @param mcf The managed connection factory
+ * @return The JNDI names bound
* @exception Exception thrown if an error occurs
*/
- private void bindConnectionFactory(String name, Serializable cf, ManagedConnectionFactory mcf) throws Exception
+ private String[] bindConnectionFactory(String deployment, Object cf) throws Throwable
{
- ConnectionFactoryBuilder cfb = getConnectionFactoryBuilder();
- cfb.setManagedConnectionFactory(mcf).setConnectionFactory(cf).setName(name);
- Context context = new InitialContext();
- try
- {
+ JndiStrategy js = jndiStrategy.clone();
- Referenceable referenceable = (Referenceable)cf;
- referenceable.setReference(cfb.build());
-
- Util.bind(context, name, cf);
-
- }
- finally
- {
- context.close();
- }
+ return js.bindConnectionFactories(deployment, new Object[] {cf});
}
/**
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployment.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployment.java 2010-06-29 20:02:22 UTC (rev 106333)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployment.java 2010-06-29 20:53:10 UTC (rev 106334)
@@ -22,15 +22,13 @@
package org.jboss.jca.deployers.fungal;
+import org.jboss.jca.core.spi.naming.JndiStrategy;
+
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import java.util.List;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
import javax.resource.spi.ResourceAdapter;
import org.jboss.logging.Logger;
@@ -53,8 +51,11 @@
/** The resource adapter instance */
private ResourceAdapter ra;
+ /** The JNDI strategy */
+ private JndiStrategy jndiStrategy;
+
/** JNDI names for connection factories */
- private List<String> jndiNames;
+ private String[] jndiNames;
/** The temporary directory */
private File tmpDirectory;
@@ -66,14 +67,21 @@
* Constructor
* @param deployment The deployment
* @param ra The resource adapter instance if present
+ * @param jndiStrategy The JNDI strategy
* @param jndiNames The JNDI names for connection factories
* @param tmpDirectory The temporary directory
* @param cl The classloader for the deployment
*/
- public RADeployment(URL deployment, ResourceAdapter ra, List<String> jndiNames, File tmpDirectory, ClassLoader cl)
+ public RADeployment(URL deployment,
+ ResourceAdapter ra,
+ JndiStrategy jndiStrategy,
+ String[] jndiNames,
+ File tmpDirectory,
+ ClassLoader cl)
{
this.deployment = deployment;
this.ra = ra;
+ this.jndiStrategy = jndiStrategy;
this.jndiNames = jndiNames;
this.tmpDirectory = tmpDirectory;
this.cl = cl;
@@ -106,41 +114,14 @@
if (jndiNames != null)
{
- Context context = null;
try
{
- context = new InitialContext();
-
- for (String jndiName : jndiNames)
- {
- try
- {
- Util.unbind(context, jndiName);
- }
- catch (Throwable it)
- {
- log.warn("Exception during JNDI unbind for: " + jndiName, it);
- }
- }
+ jndiStrategy.unbindConnectionFactories(null, jndiNames);
}
catch (Throwable t)
{
- log.warn("Exception during JNDI initialization", t);
+ log.warn("Exception during JNDI unbinding", t);
}
- finally
- {
- if (context != null)
- {
- try
- {
- context.close();
- }
- catch (NamingException ne)
- {
- // Ignore
- }
- }
- }
}
if (ra != null)
Modified: projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml
===================================================================
--- projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml 2010-06-29 20:02:22 UTC (rev 106333)
+++ projects/jboss-jca/trunk/embedded/src/main/resources/jca.xml 2010-06-29 20:53:10 UTC (rev 106334)
@@ -80,6 +80,11 @@
<property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
</bean>
+ <!-- JNDI strategy -->
+ <bean name="JNDIStrategy"
+ interface="org.jboss.jca.core.spi.naming.JndiStrategy"
+ class="org.jboss.jca.core.naming.SimpleJndiStrategy"/>
+
<!-- RA deployer -->
<bean name="RADeployer" interface="com.github.fungal.spi.deployers.Deployer" class="org.jboss.jca.deployers.fungal.RADeployer">
<property name="ArchiveValidation">true</property>
@@ -88,6 +93,7 @@
<property name="BeanValidation">true</property>
<property name="PrintStream"><inject bean="JBossStdioContext" property="Out"/></property>
<property name="DefaultBootstrapContext"><inject bean="DefaultBootstrapContext"/></property>
+ <property name="JndiStrategy"><inject bean="JNDIStrategy"/></property>
<property name="TransactionManager"><inject bean="RealTransactionManager"/></property>
<depends>BeanValidation</depends>
<depends>JBossStdioContextSelector</depends>
Modified: projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml 2010-06-29 20:02:22 UTC (rev 106333)
+++ projects/jboss-jca/trunk/sjc/src/main/resources/bootstrap/jca.xml 2010-06-29 20:53:10 UTC (rev 106334)
@@ -83,6 +83,11 @@
<property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
</bean>
+ <!-- JNDI strategy -->
+ <bean name="JNDIStrategy"
+ interface="org.jboss.jca.core.spi.naming.JndiStrategy"
+ class="org.jboss.jca.core.naming.SimpleJndiStrategy"/>
+
<!-- RA deployer -->
<bean name="RADeployer" interface="com.github.fungal.spi.deployers.Deployer" class="org.jboss.jca.deployers.fungal.RADeployer">
<property name="ArchiveValidation">true</property>
@@ -91,6 +96,7 @@
<property name="BeanValidation">true</property>
<property name="PrintStream"><inject bean="JBossStdioContext" property="Out"/></property>
<property name="DefaultBootstrapContext"><inject bean="DefaultBootstrapContext"/></property>
+ <property name="JndiStrategy"><inject bean="JNDIStrategy"/></property>
<property name="TransactionManager"><inject bean="RealTransactionManager"/></property>
<depends>BeanValidation</depends>
<depends>JBossStdioContextSelector</depends>
Modified: projects/jboss-jca/trunk/standalone/src/main/resources/bootstrap/jca.xml
===================================================================
--- projects/jboss-jca/trunk/standalone/src/main/resources/bootstrap/jca.xml 2010-06-29 20:02:22 UTC (rev 106333)
+++ projects/jboss-jca/trunk/standalone/src/main/resources/bootstrap/jca.xml 2010-06-29 20:53:10 UTC (rev 106334)
@@ -78,4 +78,9 @@
<property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
</bean>
+ <!-- JNDI strategy -->
+ <bean name="JNDIStrategy"
+ interface="org.jboss.jca.core.spi.naming.JndiStrategy"
+ class="org.jboss.jca.core.naming.SimpleJndiStrategy"/>
+
</deployment>
More information about the jboss-cvs-commits
mailing list