[jboss-cvs] JBossAS SVN: r110802 - in projects/jboss-jca/trunk/core/src: main/java/org/jboss/jca/core/spi/rar and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 28 12:30:46 EST 2011


Author: jesper.pedersen
Date: 2011-02-28 12:30:45 -0500 (Mon, 28 Feb 2011)
New Revision: 110802

Modified:
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/rar/ActivationImpl.java
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/rar/SimpleResourceAdapterRepository.java
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/rar/Activation.java
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/rar/ResourceAdapterRepository.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/inflow/HornetQTestCase.java
Log:
[JBJCA-503] Added getResourceAdapters(Class)

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/rar/ActivationImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/rar/ActivationImpl.java	2011-02-28 11:46:42 UTC (rev 110801)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/rar/ActivationImpl.java	2011-02-28 17:30:45 UTC (rev 110802)
@@ -23,11 +23,15 @@
 package org.jboss.jca.core.rar;
 
 import org.jboss.jca.core.spi.rar.Activation;
+import org.jboss.jca.core.spi.rar.NotFoundException;
 
+import java.lang.ref.WeakReference;
 import java.util.Map;
 import java.util.Set;
 
+import javax.resource.ResourceException;
 import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.ResourceAdapter;
 
 /**
  * An activation implementation
@@ -36,28 +40,34 @@
  */
 public class ActivationImpl implements Activation
 {
+   /** Resource adapter */
+   private WeakReference<ResourceAdapter> rar;
+
+   /** ActivationSpec class */
+   private WeakReference<Class<?>> activationSpecClass;
+
    /** Config properties */
    private Map<String, Class<?>> configProperties;
 
    /** Required config properties */
    private Set<String> requiredConfigProperties;
 
-   /** ActivationSpec instance */
-   private ActivationSpec instance;
-
    /**
     * Constructor
+    * @param rar The resource adapter
+    * @param activationSpecClass The activation spec class
     * @param configProperties The config properties
     * @param requiredConfigProperties The required config properties
-    * @param instance The instance
     */
-   ActivationImpl(Map<String, Class<?>> configProperties,
-                  Set<String> requiredConfigProperties,
-                  ActivationSpec instance)
+   ActivationImpl(ResourceAdapter rar,
+                  Class<?> activationSpecClass,
+                  Map<String, Class<?>> configProperties,
+                  Set<String> requiredConfigProperties)
    {
+      this.rar = new WeakReference<ResourceAdapter>(rar);
+      this.activationSpecClass = new WeakReference<Class<?>>(activationSpecClass);
       this.configProperties = configProperties;
       this.requiredConfigProperties = requiredConfigProperties;
-      this.instance = instance;
    }
 
    /**
@@ -79,8 +89,22 @@
    /**
     * {@inheritDoc}
     */
-   public ActivationSpec getInstance()
+   public ActivationSpec createInstance()
+      throws NotFoundException, InstantiationException, IllegalAccessException, ResourceException
    {
+      Class<?> clz = activationSpecClass.get();
+
+      if (clz == null)
+         throw new NotFoundException("The activation spec class is no longer available");
+
+      ResourceAdapter ra = rar.get();
+
+      if (ra == null)
+         throw new NotFoundException("The resource adapter is no longer available");
+
+      ActivationSpec instance = ActivationSpec.class.cast(clz.newInstance());
+      instance.setResourceAdapter(ra);
+
       return instance;
    }
 }

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/rar/SimpleResourceAdapterRepository.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/rar/SimpleResourceAdapterRepository.java	2011-02-28 11:46:42 UTC (rev 110801)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/rar/SimpleResourceAdapterRepository.java	2011-02-28 17:30:45 UTC (rev 110802)
@@ -44,10 +44,10 @@
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import javax.resource.ResourceException;
-import javax.resource.spi.ActivationSpec;
 import javax.resource.spi.ResourceAdapter;
 
+import org.jboss.logging.Logger;
+
 /**
  * A simple implementation of the resource adapter repository
  * 
@@ -55,6 +55,9 @@
  */
 public class SimpleResourceAdapterRepository implements ResourceAdapterRepository
 {
+   /** The logger */
+   private static Logger log = Logger.getLogger(SimpleResourceAdapterRepository.class);
+
    /** Resource adapters */
    private Map<String, WeakReference<ResourceAdapter>> rars;
 
@@ -157,6 +160,93 @@
    /**
     * {@inheritDoc}
     */
+   public Set<String> getResourceAdapters(Class<?> messageListenerType)
+   {
+      if (messageListenerType == null)
+         throw new IllegalArgumentException("MessageListenerType is null");
+      
+      if (mdr == null)
+         throw new IllegalStateException("MDR is null");
+      
+      Set<String> result = new HashSet<String>();
+
+      Iterator<Map.Entry<String, WeakReference<ResourceAdapter>>> it = rars.entrySet().iterator();
+      while (it.hasNext())
+      {
+         Map.Entry<String, WeakReference<ResourceAdapter>> entry = it.next();
+
+         String raKey = entry.getKey();
+         WeakReference<ResourceAdapter> ra = entry.getValue();
+
+         if (ra.get() != null)
+         {
+            ResourceAdapter rar = ra.get();
+            Connector md = null;
+
+            Set<String> mdrKeys = mdr.getResourceAdapters();
+            Iterator<String> mdrIt = mdrKeys.iterator();
+
+            while (md == null && mdrIt.hasNext())
+            {
+               String mdrId = mdrIt.next();
+               try
+               {
+                  Connector c = mdr.getResourceAdapter(mdrId);
+            
+                  if (c.getResourceadapter() != null && c.getResourceadapter() instanceof ResourceAdapter1516)
+                  {
+                     ResourceAdapter1516 ra1516 = (ResourceAdapter1516)c.getResourceadapter();
+                     String clz = ra1516.getResourceadapterClass();
+
+                     if (rar.getClass().getName().equals(clz))
+                        md = c;
+                  }
+               }
+               catch (Throwable t)
+               {
+                  // We will ignore
+                  log.debugf("Resource adapter %s is ignored", rar.getClass().getName()); 
+               }
+            }
+
+            if (md != null && md.getResourceadapter() != null && md.getResourceadapter() instanceof ResourceAdapter1516)
+            {
+               ResourceAdapter1516 ra1516 = (ResourceAdapter1516)md.getResourceadapter();
+
+               if (ra1516.getInboundResourceadapter() != null &&
+                   ra1516.getInboundResourceadapter().getMessageadapter() != null &&
+                   ra1516.getInboundResourceadapter().getMessageadapter().getMessagelisteners() != null &&
+                   ra1516.getInboundResourceadapter().getMessageadapter().getMessagelisteners().size() > 0)
+               {
+                  List<org.jboss.jca.common.api.metadata.ra.MessageListener> listeners =
+                     ra1516.getInboundResourceadapter().getMessageadapter().getMessagelisteners();
+
+                  for (org.jboss.jca.common.api.metadata.ra.MessageListener ml : listeners)
+                  {
+                     try
+                     {
+                        ClassLoader cl = rar.getClass().getClassLoader();
+                        Class<?> mlType = Class.forName(ml.getMessagelistenerType().getValue(), true, cl);
+
+                        if (mlType.isAssignableFrom(messageListenerType))
+                           result.add(raKey);
+                     }
+                     catch (Throwable t)
+                     {
+                        // We will ignore
+                     }
+                  }
+               }
+            }
+         }
+      }
+
+      return Collections.unmodifiableSet(result);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
    public synchronized Endpoint getEndpoint(String uniqueId) throws NotFoundException
    {
       if (uniqueId == null)
@@ -304,21 +394,14 @@
          }
 
          Class<?> asClz = Class.forName(as.getActivationspecClass().getValue(), true, cl);
-         ActivationSpec instance = (ActivationSpec)asClz.newInstance();
-         instance.setResourceAdapter(rar);
 
-         ActivationImpl a = new ActivationImpl(Collections.unmodifiableMap(configProperties),
-                                               Collections.unmodifiableSet(requiredConfigProperties),
-                                               instance);
+         ActivationImpl a = new ActivationImpl(rar,
+                                               asClz,
+                                               Collections.unmodifiableMap(configProperties),
+                                               Collections.unmodifiableSet(requiredConfigProperties));
 
          return new MessageListenerImpl(type, a);
       }
-      catch (ResourceException re)
-      {
-         InstantiationException ie = new InstantiationException("Unable to create representation");
-         ie.initCause(re);
-         throw ie;
-      }
       catch (ClassNotFoundException cnfe)
       {
          InstantiationException ie = new InstantiationException("Unable to create representation");

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/rar/Activation.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/rar/Activation.java	2011-02-28 11:46:42 UTC (rev 110801)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/rar/Activation.java	2011-02-28 17:30:45 UTC (rev 110802)
@@ -25,6 +25,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.resource.ResourceException;
 import javax.resource.spi.ActivationSpec;
 
 /**
@@ -47,11 +48,13 @@
    public Set<String> getRequiredConfigProperties();
 
    /**
-    * Get an instance of the associated activation spec.
-    * 
-    * Note, that there is only one instance associated with
-    * implementations of this interface
+    * Create an instance of the associated activation spec.
     * @return The value
+    * @exception NotFoundException Thrown if the class is no longer available
+    * @exception InstantiationException Thrown if an object couldn't created
+    * @exception IllegalAccessException Thrown if object access is inaccessible
+    * @exception ResourceException Thrown if the activation spec can't be associated with the resource adapter
     */
-   public ActivationSpec getInstance();
+   public ActivationSpec createInstance()
+      throws NotFoundException, InstantiationException, IllegalAccessException, ResourceException;
 }

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/rar/ResourceAdapterRepository.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/rar/ResourceAdapterRepository.java	2011-02-28 11:46:42 UTC (rev 110801)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/spi/rar/ResourceAdapterRepository.java	2011-02-28 17:30:45 UTC (rev 110802)
@@ -55,6 +55,14 @@
    public Set<String> getResourceAdapters();
 
    /**
+    * Get the resource adapters unique ids registered which has the specified
+    * message listener type
+    * @param messageListenerType The message listener type
+    * @return The unique ids
+    */
+   public Set<String> getResourceAdapters(Class<?> messageListenerType);
+
+   /**
     * Get an endpoint representation for a resource adapter
     * @param uniqueId An unique id that represents the deployment
     * @return The endpoint

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/inflow/HornetQTestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/inflow/HornetQTestCase.java	2011-02-28 11:46:42 UTC (rev 110801)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/inflow/HornetQTestCase.java	2011-02-28 17:30:45 UTC (rev 110802)
@@ -152,7 +152,7 @@
 
          assertNotNull(raRepository);
 
-         Set<String> ids = raRepository.getResourceAdapters();
+         Set<String> ids = raRepository.getResourceAdapters(javax.jms.MessageListener.class);
 
          assertNotNull(ids);
          assertEquals(1, ids.size());
@@ -169,7 +169,7 @@
 
          MessageListener listener = listeners.get(0);
 
-         ActivationSpec as = listener.getActivation().getInstance();
+         ActivationSpec as = listener.getActivation().createInstance();
          assertNotNull(as);
          assertNotNull(as.getResourceAdapter());
 



More information about the jboss-cvs-commits mailing list