docs: public boolean enlistResource(XAResource xaRes, XARecoveryData recData, int branchCoupling) throws RollbackException, SystemException, IllegalStateException {
          if (tc.isEntryEnabled())
              Tr.entry(tc, "enlistResource", new Object[] {
                                                           xaRes,
                                                           recData,
                                                           branchCoupling });
  
          // Determine if we are attempting to enlist a second resource within a transaction
          // that can't support 2PC anyway.
          if (_disableTwoPhase && (_resourceObjects.size() > 0)) {
              final String msg = "Unable to enlist a second resource within the transaction. Two phase support is disabled " +
                                 "as the recovery log was not available at transaction start";
              final IllegalStateException ise = new IllegalStateException(msg);
              throw ise;
          }
  
          boolean register = false;
  
          boolean matchedSameRM = false;
  
          JTAXAResourceImpl jtaRes = (JTAXAResourceImpl) getResourceTable().get(xaRes);
          if (jtaRes == null) {
              if (tc.isEventEnabled())
                  Tr.event(tc, "enlisting XAResource");
  
              Xid xid;
  
              boolean supportsIsSameRM = recData.supportsIsSameRM();
  
              try {
                  // This code will only be driven in the ESB scenario. There will only ever
                  // be two resources enlisted that will qualify for the isSameRM optimization 
                  // so we perform our check to see if this is the first resource we are enlisting
                  // in the tran. If it is, it could qualify for the optimization, So we check.
                  // If we have enlisted a resource before, then we check to see if the the first 
                  // resource that was enlisted can perform the isSameRM check.
  
                  if (_resourceObjects.isEmpty()) {
                      if (tc.isEventEnabled())
                          Tr.event(tc, "First resource - so we have to make a new branch xid");
                      xid = generateNewBranch();
  
                      // Store the recovery data reference within the resource in order that we can determine the "log early"
                      // behaviour prepare().
  
                      if (supportsIsSameRM) {
                          if (tc.isEventEnabled())
                              Tr.event(tc, "First resource - does implement ResourceManagerSupportsIsSameRM");
  
                          _isCheckingSameRM = true;
                      } else {
                          if (tc.isEventEnabled())
                              Tr.event(tc, "First resource - does not implement ResourceManagerSupportsIsSameRM");
                      }
                  } else {
                      if (tc.isEventEnabled())
                          Tr.event(tc, "Second resource or later, so we should check for isSameRM");
  
                      if (_isCheckingSameRM) {
                          if (xaRes.isSameRM(_sameRMMasterResource.XAResource()) &&
                              // Make sure _sameRMMasterResource also compatible with branchCoupling start flag
                              (_sameRMMasterResource.getBranchCoupling() == branchCoupling)) {
                              if (tc.isEventEnabled())
                                  Tr.event(tc, "isSameRM match successful");
                              matchedSameRM = true;
                              _isCheckingSameRM = false;
  
                              xid = _sameRMMasterResource.getXID();
                          } else {
                              if (tc.isEventEnabled())
                                  Tr.event(tc, "isSameRM match was not successful, so we create a new branch xid");
  
                              xid = generateNewBranch();
                          }
                      } else {
                          if (tc.isEventEnabled())
                              Tr.event(tc, "We are not matching using isSameRM so we create a new branch xid");
  
                          xid = generateNewBranch();
                      }
                  }
              } catch (XAException xae) {
                  _errorCode = xae.errorCode; // Save locally for FFDC
  
                  throw (SystemException) new SystemException("XAResource RM instance matching error:" + XAReturnCodeHelper.convertXACode(_errorCode)).initCause(xae);
              }
  
              // Store the recovery data reference within the resource in order that we can determine the "log early"
              // behaviour prepare().
              jtaRes = new JTAXAResourceImpl(xid, xaRes, recData);
  
              // We set the state on the jta resource here so that when start is sent to it
              // we pass the neccesary flags to perfrom a TMJOIN
  
              if (matchedSameRM) {
                  jtaRes.setState(JTAResource.NOT_ASSOCIATED_AND_TMJOIN);
              }
  
              // If we are enlisting the first resource to the tran and it is capable to
              // perform isSameRM, we set it as the master resource that we make our
              // isSameRM processing against.
  
              if (_isCheckingSameRM && (_sameRMMasterResource == null)) {
                  _sameRMMasterResource = jtaRes;
              }
  
              jtaRes.setBranchCoupling(branchCoupling);
  
              register = true;
              getResourceTable().put(xaRes, jtaRes);
          }
  
          // Remove logEarly checks - PK66133.1
          // Always log at enlist time.  We could delay to prepare/c1p but some versions of db/2 go semi-in-doubt
          // as soon as xa_end is called. Note that the call to logRecoveryEntry will establish the identity
          // of the associated RU. This means that recData.getRecoveryId() below will return the correct RU value
          // rather than 0.       
          try {
              recData.logRecoveryEntry();
          } catch (IllegalStateException ise) // d172471
          {
              FFDCFilter.processException(ise, "com.ibm.tx.jta.impl.RegisteredResources.enlistResource", "483", this);
              if (tc.isEntryEnabled())
                  Tr.exit(tc, "enlistResource (SPI)", ise);
              throw ise;
          } catch (Exception e) {
              FFDCFilter.processException(e, "com.ibm.tx.jta.impl.RegisteredResources.enlistResource", "489", this);
              final Throwable toThrow = new SystemException(e.getLocalizedMessage()).initCause(e);
              if (tc.isEntryEnabled())
                  Tr.exit(tc, "enlistResource (SPI)", toThrow);
              throw (SystemException) toThrow;
          }
  
          //
          // start association and register JTAXAResource object with Transaction if required
          //
          try {
              setXAResourceTransactionTimeout(jtaRes, recData, _transaction.getExpirationTime());
  
              this.startRes(jtaRes);
  
              if (register) {
                  jtaRes.setResourceStatus(StatefulResource.REGISTERED);
  
                  if (matchedSameRM) {
                      _sameRMResource = jtaRes;
                  } else {
                      _resourceObjects.add(jtaRes);
                      if (jtaRes.getPriority() != JTAResource.DEFAULT_COMMIT_PRIORITY)
                          _gotPriorityResourcesEnlisted = true;
                  }
  
                  // Check and update LPS enablement state for the application - LIDB1673.22
                  checkLPSEnablement();
  
                  if (tc.isEventEnabled())
                      Tr.event(tc, "(SPI) RESOURCE registered with Transaction. TX: " + _transaction.getLocalTID() + ", Resource: " + jtaRes);
              }
          } catch (RollbackException rbe) {
              FFDCFilter.processException(rbe, "com.ibm.tx.jta.impl.RegisteredResources.enlistResource", "517", this);
              if (tc.isEntryEnabled())
                  Tr.exit(tc, "enlistResource", rbe);
              throw rbe;
          } catch (SystemException se) {
              FFDCFilter.processException(se, "com.ibm.tx.jta.impl.RegisteredResources.enlistResource", "523", this);
              if (tc.isEntryEnabled())
                  Tr.exit(tc, "enlistResource", se);
              throw se;
          }
  
          if (tc.isEntryEnabled())
              Tr.exit(tc, "enlistResource", Boolean.TRUE);
          return true;
      }