docs: public void end(Xid xid, int flags) throws XAException
     {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "end",
                                             new Object[] {xid, ""+flags});
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Current state = " + state);
        
        if (state == ResourceState.UNENLISTED)
        {
           // We are not already enlisted here - something is a bit wrong
           if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "We are not enlisted - rejecting this call");
           throw new XAException(XAException.XAER_PROTO); 
        }
        else if (state == ResourceState.JOINED)
        {
           // Unjoin the resource...
           if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "state == JOINED. Unjoining the resource.");
           joinedResource.unjoin(this);
        }
        
        // Now decide whether to do the end() or not. If this resource was joined to another one then
        // we perform the end now only if there are no more joined resources and if end() has been
        // called on the master XAResource.
        boolean performEndNow = false;
        if (joinedResource != null)
        {
           if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Joined resource state: " + joinedResource.state);
           
           performEndNow = (!joinedResource.hasJoinedResources()) && 
                           (joinedResource.endHasBeenCalled); 
        }
        // Otherwise, we can perform an end() if there are no other resources joined to us
        else
        {
           performEndNow = (!hasJoinedResources());
        }
        
        // Now perform the end if we need to now
        if (performEndNow)
        {
           if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Ending the resource.");
           
           internalEnd(xid, flags);
           
           HashMap<Xid, SIXAResourceProxy> map = getLinkLevelXAResourceMap();
           synchronized(map)
           {
              map.remove(xid);
           }
        }
  
        // Now we are not enlisted
        state = ResourceState.UNENLISTED;
        joinedResource = null;
        endHasBeenCalled = true;
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "end");
     }