[jboss-cvs] JBossAS SVN: r110805 - branches/JBPAPP_5_1_0_Final_JBPAPP-5820/connector/src/main/org/jboss/resource/connectionmanager.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 1 08:27:39 EST 2011


Author: raggz
Date: 2011-03-01 08:27:39 -0500 (Tue, 01 Mar 2011)
New Revision: 110805

Modified:
   branches/JBPAPP_5_1_0_Final_JBPAPP-5820/connector/src/main/org/jboss/resource/connectionmanager/ManagedConnectionFactoryDeployment.java
Log:
Final iteration of JBPAPP-5292.

Modified: branches/JBPAPP_5_1_0_Final_JBPAPP-5820/connector/src/main/org/jboss/resource/connectionmanager/ManagedConnectionFactoryDeployment.java
===================================================================
--- branches/JBPAPP_5_1_0_Final_JBPAPP-5820/connector/src/main/org/jboss/resource/connectionmanager/ManagedConnectionFactoryDeployment.java	2011-03-01 10:09:39 UTC (rev 110804)
+++ branches/JBPAPP_5_1_0_Final_JBPAPP-5820/connector/src/main/org/jboss/resource/connectionmanager/ManagedConnectionFactoryDeployment.java	2011-03-01 13:27:39 UTC (rev 110805)
@@ -150,7 +150,6 @@
    private XAResourceRecoveryRegistry xrrr = null;
    private SubjectFactory subjectFactory = null;
    private ManagedConnection recoverMC = null;
-   private String securityDomain = null;
    private String recoverSecurityDomain = null;
    private String recoverUserName = null;
    private String recoverPassword = null;
@@ -450,6 +449,8 @@
                recoverSecurityDomain = recoverSecurityDomainMD.getDomain();
 
             SecurityMetaData securityDomainMD = xdsdm.getSecurityMetaData();
+            String securityDomain = null;
+
             if (securityDomainMD != null)
                securityDomain = securityDomainMD.getDomain();
 
@@ -480,6 +481,9 @@
             if (recoverPassword == null) 
                recoverPassword = xdsdm.getPassWord();
 
+            if (recoverSecurityDomain == null)
+               recoverSecurityDomain = securityDomain;
+
             if (log.isDebugEnabled())
                log.debug("Registered for XA Resource Recovery: " + xdsdm.getJndiName());
 
@@ -487,7 +491,6 @@
             recoverUserName = getSubstitutionValue(recoverUserName);
             recoverPassword = getSubstitutionValue(recoverPassword);
             recoverSecurityDomain = getSubstitutionValue(recoverSecurityDomain);
-            securityDomain = getSubstitutionValue(securityDomain);
 
             if (log.isDebugEnabled())
             {
@@ -499,14 +502,18 @@
                {
                   log.debug("RecoverSecurityDomain=" + recoverSecurityDomain);
                }
-               else if (securityDomain != null)
-               {
-                  log.debug("RecoverSecurityDomain=" + securityDomain);
-               }
             }
 
-            getXAResourceRecoveryRegistry().addXAResourceRecovery(this);
-            recoveryRegistered = true;
+            if ((recoverUserName != null && recoverPassword != null) ||
+                (recoverSecurityDomain != null))
+            {
+               getXAResourceRecoveryRegistry().addXAResourceRecovery(this);
+               recoveryRegistered = true;
+            }
+            else
+            {
+               log.warn("Unable to register recovery for " + dmd.getJndiName());
+            }
          }
       }
    }
@@ -561,8 +568,8 @@
                Object connection = null;
                try
                {
+                  connection = openConnection(mc, subject);
                   xaResource = mc.getXAResource();
-                  connection = openConnection(mc, subject);
                }
                catch (ResourceException reconnect)
                {
@@ -607,21 +614,30 @@
                   if (b != null)
                      isSameRMOverrideValue = b;
 
-                  if(wrapXAResource)
+                  if (wrapXAResource)
                   {
                      String eisProductName = null;
                      String eisProductVersion = null;
 
                      try
                      {
-                        eisProductName = mc.getMetaData().getEISProductName();
-                        eisProductVersion = mc.getMetaData().getEISProductVersion();
+                        if (mc.getMetaData() != null)
+                        {
+                           eisProductName = mc.getMetaData().getEISProductName();
+                           eisProductVersion = mc.getMetaData().getEISProductVersion();
+                        }
                      }
                      catch (ResourceException re)
                      {
                         // Ignore
                      }
 
+                     if (eisProductName == null)
+                        eisProductName = dmd.getJndiName();
+
+                     if (eisProductVersion == null)
+                        eisProductVersion = dmd.getJndiName();
+
                      xaResource = new XAResourceWrapperImpl(xaResource, 
                                                             padXid,
                                                             isSameRMOverrideValue,
@@ -702,29 +718,24 @@
                // Security-domain use-case
                try
                {
-                  // Create a security context on the association
-                  SecurityContext securityContext = SecurityContextFactory.createSecurityContext(recoverSecurityDomain);
-                  SecurityContextAssociation.setSecurityContext(securityContext);
+                  if (recoverSecurityDomain != null)
+                  {
+                     // Create a security context on the association
+                     SecurityContext securityContext = SecurityContextFactory.createSecurityContext(recoverSecurityDomain);
+                     SecurityContextAssociation.setSecurityContext(securityContext);
                
-                  // Unauthenticated
-                  Subject unauthenticated = new Subject();
+                     // Unauthenticated
+                     Subject unauthenticated = new Subject();
                   
-                  // Leave the subject empty as we don't have any information to do the
-                  // authentication with - and we only need it to be able to get the
-                  // real subject from the SubjectFactory
+                     // Leave the subject empty as we don't have any information to do the
+                     // authentication with - and we only need it to be able to get the
+                     // real subject from the SubjectFactory
                   
-                  // Set the authenticated subject
-                  securityContext.getSubjectInfo().setAuthenticatedSubject(unauthenticated);
+                     // Set the authenticated subject
+                     securityContext.getSubjectInfo().setAuthenticatedSubject(unauthenticated);
 
-                  // Select the domain
-                  String domain = recoverSecurityDomain;
-                  if (domain == null)
-                     domain = securityDomain;
-
-                  if (domain != null)
-                  {
                      // Use the unauthenticated subject to get the real recovery subject instance
-                     Subject subject = subjectFactory.createSubject(domain);
+                     Subject subject = subjectFactory.createSubject(recoverSecurityDomain);
 
                      if (log.isDebugEnabled())
                         log.debug("Recovery Subject=" + subject);
@@ -758,6 +769,9 @@
    {
       if (recoverMC == null)
       {
+         if (log.isDebugEnabled())
+            log.debug("Creating new managed connection for recovery");
+
          recoverMC = createManagedConnection(s, null);
       }
 
@@ -770,6 +784,9 @@
     */
    private void close(ManagedConnection mc)
    {
+      if (log.isDebugEnabled())
+         log.debug("Closing managed connection for recovery");
+
       if (mc != null)
       {
          try
@@ -795,6 +812,7 @@
       }
 
       mc = null;
+      recoverMC = null;
    }
 
    /**
@@ -806,6 +824,9 @@
     */
    private Object openConnection(ManagedConnection mc, Subject s) throws ResourceException
    {
+      if (log.isDebugEnabled())
+         log.debug("Creating connection for recovery check");
+
       return mc.getConnection(s, null);
    }
 
@@ -816,6 +837,9 @@
     */
    private boolean closeConnection(Object c)
    {
+      if (log.isDebugEnabled())
+         log.debug("Closing connection for recovery check");
+
       if (c != null)
       {
          if (c instanceof javax.resource.cci.Connection)
@@ -828,25 +852,58 @@
             catch (ResourceException ire)
             {
                log.warn("Error during recovery connection close", ire);
+
+               if (log.isDebugEnabled())
+                  log.debug("Forcing recreate of managed connection");
+
                return true;
             }
          }
          else
          {
+            Method method = null;
             try
             {
-               Method method = c.getClass().getMethod("close", new Class[0]);
+               method = c.getClass().getMethod("isValid", new Class[] {int.class});
                method.setAccessible(true);
-               method.invoke(c, new Object[0]);
+               Boolean b = (Boolean)method.invoke(c, new Object[] {new Integer(5)});
+               return !b.booleanValue();
             }
             catch (NoSuchMethodException nsme)
             {
-               log.warn("No close() method defined on connection interface. Destroying managed connection to clean-up", nsme);
+               try
+               {
+                  method = c.getClass().getMethod("close", (Class<?>)null);
+                  method.setAccessible(true);
+                  method.invoke(c, (Object)null);
+               }
+               catch (Throwable it)
+               {
+                  log.warn("No close() method defined on connection interface. Destroying managed connection to clean-up", it);
+
+                  if (log.isDebugEnabled())
+                     log.debug("Forcing recreate of managed connection");
+
+                  return true;
+               }
+            }
+            catch (InvocationTargetException ite)
+            {
+               if (log.isDebugEnabled())
+               {
+                  log.debug("Unable to execute isValid() due to " + ite.getMessage());
+                  log.debug("Forcing recreate of managed connection");
+               }
+
                return true;
             }
             catch (Throwable t)
             {
-               log.warn("Error during recovery connection close", t);
+               log.warn("Error during recovery connection isValid", t);
+
+               if (log.isDebugEnabled())
+                  log.debug("Forcing recreate of managed connection");
+
                return true;
             }
          }



More information about the jboss-cvs-commits mailing list