Invoked when enlisting in a z/OS RRS (Resource Recovery Services) global transaction.
777431
@Override
    public void enlistRRS() {
        stateMgr.setStateNoValidate(WSStateManager.RRS_GLOBAL_TRANSACTION_ACTIVE); 
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(this, tc, "Setting transaction state to RRS_GLOBAL_TRANSACTION_ACTIVE"); 
    }
1178601
synchronized void registerService(Promotable service)
    {
        m_services.add(service);
        if (m_isLeader) {
            try {
                service.acceptPromotion();
            }
            catch (Exception e) {
                VoltDB.crashLocalVoltDB("Unable to promote global service.", true, e);
            }
        }
    }
1041695
public void registerTransaction(TransactionImpl tran) {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "registerTransaction", new Object[] { this, tran });

        _recoveringTransactions.add(tran);

        if (tc.isEntryEnabled())
            Tr.exit(tc, "registerTransaction", _recoveringTransactions.size());
    }
569042
private void registerSynchronization(TransactionImpl odmgTrans, Transaction transaction)
    {
        // todo only need for development
        if (odmgTrans == null || transaction == null)
        {
            log.error("One of the given parameters was null --> cannot do synchronization!" +
                    " omdg transaction was null: " + (odmgTrans == null) +
                    ", external transaction was null: " + (transaction == null));
            return;
        }

        int status = -1; // default status.
        try
        {
            status = transaction.getStatus();
            if (status != Status.STATUS_ACTIVE)
            {
                throw new OJBRuntimeException(
                        "Transaction synchronization failed - wrong status of external container tx: " +
                        getStatusString(status));
            }
        }
        catch (SystemException e)
        {
            throw new OJBRuntimeException("Can't read status of external tx", e);
        }

        try
        {
            //Sequence of the following method calls is significant
            // 1. register the synchronization with the ODMG notion of a transaction.
            transaction.registerSynchronization((J2EETransactionImpl) odmgTrans);
            // 2. mark the ODMG transaction as being in a JTA Transaction
            // Associate external transaction with the odmg transaction.
            txRepository.set(new TxBuffer(odmgTrans, transaction));
        }
        catch (Exception e)
        {
            log.error("Cannot associate PersistenceBroker with running Transaction", e);
            throw new OJBRuntimeException(
                    "Transaction synchronization failed - wrong status of external container tx", e);
        }
    }
789858
public void enlistWithTransaction(javax.transaction.Synchronization sync)
                    throws CSIException
    {
        SynchronizationRegistryUOWScope uowScope = getCurrentTransactionalUOW(false);
        if (uowScope == null)
        {
            throw new IllegalStateException("No active transaction");
        }

        enlistWithTransaction(uowScope, sync);
    }
634186
public final void rollbackRemoteTransaction(GlobalTransaction gtx) {
      RpcManager rpcManager = cache.getRpcManager();
      CommandsFactory factory = cache.getComponentRegistry().getCommandsFactory();
      try {
         RollbackCommand rollbackCommand = factory.buildRollbackCommand(gtx);
         rollbackCommand.setTopologyId(rpcManager.getTopologyId());
         CompletionStage<Void> cs = rpcManager
               .invokeCommandOnAll(rollbackCommand, validOnly(), rpcManager.getSyncRpcOptions());
         factory.initializeReplicableCommand(rollbackCommand, false);
         rollbackCommand.invokeAsync().join();
         cs.toCompletableFuture().join();
      } catch (Throwable throwable) {
         throw Util.rewrapAsCacheException(throwable);
      } finally {
         forgetTransaction(gtx, rpcManager, factory);
      }
   }
42085
private void executeGlobalPostProcessing(boolean processBundleFlag, StopWatch stopWatch) {
		// Launch global postprocessing
		if (resourceTypePostprocessor != null) {
			if (stopWatch != null) {
				stopWatch.start("Global postprocessing");
			}
			GlobalPostProcessingContext ctx = new GlobalPostProcessingContext(config, this, resourceHandler,
					processBundleFlag);

			resourceTypePostprocessor.processBundles(ctx, this.bundles);
			if (stopWatch != null) {
				stopWatch.stop();
			}
		}
	}
667476
@Override
    public void enlist() throws ResourceException {

        final boolean isTracingEnabled = TraceComponent.isAnyTracingEnabled();

        if (isTracingEnabled && tc.isEntryEnabled())
            Tr.entry(this, tc, "enlist", mcWrapper.getUOWCoordinator());

        if (this.hasRollbackOccured) {
            ResourceException x = new ResourceException("Attempt to continue working after transaction rolledback !");
            if (isTracingEnabled && tc.isEntryEnabled())
                Tr.exit(tc, "enlist", "It is NOT valid to continue working under a transaction that has already rolledback");
            throw x;
        }
        if (enlisted == true) {

            if (isTracingEnabled && tc.isEntryEnabled()) {
                Tr.exit(this, tc, "enlist", "already enlisted");
            }

            return; // Already enlisted, no-op.

        }

        try {
            int branchCoupling = mcWrapper.getCm().getResourceRefInfo().getBranchCoupling();
            int startFlag = XAResource.TMNOFLAGS;
            if (branchCoupling != ResourceRefInfo.BRANCH_COUPLING_UNSET) {
                startFlag = mcWrapper.getCm().supportsBranchCoupling(branchCoupling, mcWrapper.get_managedConnectionFactory());
                if (startFlag == -1)
                    throw new ResourceException("Branch coupling attribute not implemented for this resource");
            }
            int recoveryToken = mcWrapper.getRecoveryToken();
            EmbeddableWebSphereTransactionManager tranMgr = mcWrapper.pm.connectorSvc.transactionManager;
            if (tranMgr.enlist(mcWrapper.getUOWCoordinator(), this, recoveryToken, startFlag) != true) {
                Tr.error(tc, "BAD_RETURN_VALUE_FROM_ENLIST_J2CA0087", this, mcWrapper.gConfigProps.cfName);
                ResourceException x = new ResourceException("Error on enlist");
                if (isTracingEnabled && tc.isEntryEnabled())
                    Tr.exit(this, tc, "enlist", x);
                throw x;
            }
        } catch (ResourceException e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(
                                                        e,
                                                        "com.ibm.ejs.j2c.XATransactionWrapper.enlist",
                                                        "535",
                                                        this);

            Tr.error(tc, "ENLIST_RESOURCE_EXCP_J2CA0030", "enlist", e, "ResourceException", mcWrapper.gConfigProps.cfName);

            mcWrapper.markTransactionError();
            try {
                EmbeddableWebSphereTransactionManager tranMgr = mcWrapper.pm.connectorSvc.transactionManager;
                tranMgr.getTransaction().setRollbackOnly();
            } catch (Exception ex) {

                com.ibm.ws.ffdc.FFDCFilter.processException(ex, "com.ibm.ejs.j2c.XATransactionWrapper.enlist",
                                                            "630", this);
                if (isTracingEnabled && tc.isEventEnabled()) {
                    Tr.event(this, tc, "Caught Exception while trying to mark transaction RollbackOnly - Exception:" + ex);
                }

            }

            if (isTracingEnabled && tc.isEntryEnabled())
                Tr.exit(this, tc, "enlist", e);
            throw e;
        } catch (Exception e) {

            com.ibm.ws.ffdc.FFDCFilter.processException(
                                                        e,
                                                        "com.ibm.ejs.j2c.XATransactionWrapper.enlist",
                                                        "546",
                                                        this);

            String pmiName = null;
            if (mcWrapper != null) {
                pmiName = mcWrapper.gConfigProps.cfName;
            }
            Object[] parms = new Object[] { "enlist", e, "ResourceException", pmiName };
            Tr.error(tc, "ENLIST_RESOURCE_EXCP_J2CA0030", parms);

            mcWrapper.markTransactionError();
            try {
                EmbeddableWebSphereTransactionManager tranMgr = mcWrapper.pm.connectorSvc.transactionManager;
                tranMgr.getTransaction().setRollbackOnly();
            } catch (Exception ex) {
                com.ibm.ws.ffdc.FFDCFilter.processException(ex, "com.ibm.ejs.j2c.XATransactionWrapper.enlist",
                                                            "663", this);
                if (isTracingEnabled && tc.isEventEnabled()) {
                    Tr.event(this, tc, "Caught Exception while trying to mark transaction RollbackOnly - Exception:" + ex);
                }

            }

            ResourceException re = new ResourceException("enlist: caught Exception");
            re.initCause(e);
            if (isTracingEnabled && tc.isEntryEnabled())
                Tr.exit(this, tc, "enlist", e);
            throw re;

        }

        enlisted = true;

        if (isTracingEnabled && tc.isEntryEnabled())
            Tr.exit(this, tc, "enlist");
    }
1146652
@Override
    public final synchronized boolean enlist(ContainerTx tx) // d114677
    throws RemoteException
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "enlist: " + getStateName(state),
                     new Object[] { tx, currentTx }); //123293

        boolean result = false;

        switch (state)
        {
            case METHOD_READY:

                // The only way we could be enlisted in this state is at
                // activation; it is not possible for tx to be a global
                // transaction; we do not care about enlistments for
                // non-global transactions

                // LIDB1181.23.5.1
                // A new possibility exists now for the create case of a BMT bean.
                // The home of this BMT session bean will also be configured as
                // a BMT bean too.  This means that during the Home create method
                // the container will have put a local transaction context (LTC)
                // on the thread.  During postCreate the BMStatefulBeanO enlist
                // will be invoked and a containerTx will already exist
                // (ie. passed in ContainerTx is not null any more)

                if (currentTx != null) {
                    if (isTraceOn && tc.isEntryEnabled()) // d144064
                        Tr.exit(tc, "enlist: unexpected non-null currentTx"); //123293
                    throw new BeanNotReentrantException(getStateName(state) +
                                                        ": enlist: unexpected non-null currentTx"); //123293  //PQ99986
                }

                // Note, for BM stateful bean, the transaction may have
                // already been rolled back as a result of a prior business
                // method being called and an unchecked exception occurring.
                // when that happens, the next business method call will
                // eventually get to this code with tx set to null.
                // for that case, we simply skip doing the enlist and
                // return boolean false to caller so that the business
                // method gets dispatched.  Needed to pass CTS testcase
                // which is checking for the TransactionRolledBackException
                // occurring when client tries to commit a UserTransaction
                // that was already rolled back as a result of the
                // unchecked exception that previously occurred.
                if (tx != null) //123393
                {
                    result = tx.enlist(this);
                    currentTx = tx;
                    setState(TX_METHOD_READY);
                }

                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: " + result + ": " + getStateName(state));

                return result;

            case TX_METHOD_READY:

                // The only way we could be enlisted in this state is at
                // activation; tx must be the same as currentTx, since
                // TransactionControl should have resumed our transaction
                if (tx != currentTx)
                {
                    if (isTraceOn && tc.isEntryEnabled()) // d144064
                        Tr.exit(tc, "enlist: unexpected non-null currentTx"); // 123293
                    String expected = "METHOD_READY"; // 123293
                    if (currentTx == null) // 123293
                    {
                        // This should never happened. Resume did not occur?
                        expected = "MAYBE_RESUME_DID_NOT_OCCUR"; // 123293
                    }
                    throw new InvalidBeanOStateException(getStateName(state)
                                    , expected); // 123293
                }

                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: false");

                return false;

            case IN_METHOD:

                // We've got two possibilities: either the bean has just begun
                // a transaction or we're attempting to activate for a re-entrant
                // call from a different thread (which is an error); in the case of
                // a re-entrant call, we must catch it here (cannot defer to
                // preinvoke) since the other thread may change the state of the
                // bean before preInvoke would be called in this thread.

                // LIDB1181.23.5.1
                // A new possibility exists now for the create case of a BMT bean.
                // The home of this BMT session bean will also be configured as
                // a BMT bean too.  This means that during the Home create method
                // the container will have put a local transaction context (LTC)
                // on the thread.  During postCreate the BMStatefulBeanO enlist
                // will be invoked and a containerTx will already exist
                // (ie. passed in ContainerTx is not null any more)

                if (currentTx != null)
                {
                    if (isTraceOn && tc.isEntryEnabled()) // d144064
                        Tr.exit(tc, "enlist: unexpected non-null currentTx"); //123293
                    throw new InvalidBeanOStateException(getStateName(state)
                                    , "TX_METHOD_READY"); //123293
                }

                if (tx == null) // d149781
                {
                    // The only way for the bean to be in the IN_METHOD state with
                    // no transaction is if a different thread is already using it.
                    if (isTraceOn && tc.isEntryEnabled())
                        Tr.exit(tc, "enlist: reentrant call from different thread");
                    throw new BeanNotReentrantException(StateStrs[state] +
                                                        ": wrong thread");
                }

                result = tx.enlist(this);
                currentTx = tx;

                setState(TX_IN_METHOD);

                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: " + result + ": " + getStateName(state));

                return result;

            case CREATING: // PQ56091
            case ACTIVATING: // d159252
            case PASSIVATING: // d159152

                // For all of these states, the EJB Specification allows the use of
                // UserTransaction methods.  However, it is not appropriate to
                // enlist this bean at this time (enlist will be called later
                // for the CREATING and ACTIVATING scenarios).

                if (currentTx != null) {
                    if (isTraceOn && tc.isEntryEnabled()) // d144064
                        Tr.exit(tc, "enlist: unexpected non-null currentTx"); //1233293
                    throw new InvalidBeanOStateException(getStateName(state)
                                    , "TX_METHOD_READY"); //123293
                }
                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: false - unexpected state!");
                return false;

            case TX_IN_METHOD:
            case COMMITTING_IN_METHOD:
            case COMMITTING_OUTSIDE_METHOD:

                // This bean is already in a transaction - and any of these states
                // could be seen by a different transaction calling a method on it,
                // or they could also be due to a customer coded callback to the same
                // bean.
                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: not re-entrant");
                if (currentTx != tx)
                    throw new BeanNotReentrantException(StateStrs[state] +
                                                        ": wrong transaction");

                // This isn't a different thread/tran, but it is a reentrant call,
                // which must be caught here rather than preInvoke to insure the
                // extra cache pins are undone in the activation strategy.     d159152
                throw new BeanNotReentrantException(getStateName(state));

            case REMOVING:

                // Note: prior to the access timeout support added in EJB 3.1, there
                // were issues for the REMOVING state where multiple threads might
                // attempt to enter the bean concurrently, but now that the bean is
                // properly locked, it is safe to just not enlist the bean and thus
                // support UserTransaction methods in ejbRemove/PreDestroy per spec,
                // though if there is a transaction then verify this is the EJB 3.x
                // remove scenario.

                if (currentTx != null && currentTx.ivRemoveBeanO != this) {
                    if (isTraceOn && tc.isEntryEnabled())
                        Tr.exit(tc, "enlist: unexpected non-null currentTx");
                    throw new InvalidBeanOStateException(getStateName(state), "TX_METHOD_READY");
                }
                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: false - not enlisted for REMOVING state");
                return false;

            default:
                // Any other state is a programming error... there should be no
                // way to encounter these states even from another thread/transaction.
                if (isTraceOn && tc.isEntryEnabled()) // d144064
                    Tr.exit(tc, "enlist: invalid state: " + getStateName(state)); //123293
                throw new InvalidBeanOStateException(getStateName(state),
                                "METHOD_READY | " +
                                                "TX_METHOD_READY | " +
                                                "IN_METHOD");

        }

    }
502045
@Override
	public void ZWaveIncomingEvent(ZWaveEvent event) {
		if (event.getEventType() != ZWaveEvent.ZWaveEventType.TRANSACTION_COMPLETED_EVENT)
			return;
		
		SerialMessage serialMessage = (SerialMessage)event.getEventValue();
		
		if (serialMessage.getMessageClass() != SerialMessage.SerialMessageClass.SendData && serialMessage.getMessageType() != SerialMessage.SerialMessageType.Request)
			return;
		
		byte[] payload = serialMessage.getMessagePayload();
		
		if (payload.length < 4)
			return;
		if ((payload[0] & 0xFF) != this.getNode().getNodeId())
			return;
		if ((payload[2] & 0xFF) != this.getCommandClass().getKey())
			return;
		if ((payload[3] & 0xFF) != WAKE_UP_NO_MORE_INFORMATION)
			return;
		
		logger.debug("Node {} went to sleep", this.getNode().getNodeId());
		this.setAwake(false);
	}
431637
@Override
    public void unexportTransaction(String globalId) throws SystemException {

        // look up the tran or just get the one off the thread

        // blow up if there's no tran
        final UOWCoordinator uowCoord = _uowc.getUOWCoord();
        if (uowCoord == null || !uowCoord.isGlobal()) {
            throw new SystemException("No global transaction");
        }

        // Resume transaction association as we are coming back on server
        ((DistributableTransaction) uowCoord).resumeAssociation();
    }
508053
private void activateEndpointInternal(MessageEndpointFactoryImpl mef, boolean explicit) throws ResourceException {
        // Wait for the destination if specified by the MDB.  If it is instead
        // specified on the activationSpec, then the EndpointActivationService
        // won't be registered until the destination is available, so we
        // implicitly wait for the destination anyway.  If the destination isn't
        // specified at all, then the activation will fail.

        if (mef.adminObjectServiceInfo != null && mef.adminObjectServiceInfo.serviceRef == null) {
            if (explicit) {
                Tr.warning(tc, "MDB_DESTINATION_NOT_FOUND_CNTR4016W", mef.getJ2EEName().getComponent(), mef.adminObjectServiceInfo.id);
            }
            return;
        }

        if (mef.schemeJndiNameInfo != null && !mef.schemeJndiNameInfo.lookupSucceeded()) {
            if (explicit) {
                Tr.warning(tc, "MDB_DESTINATION_NOT_FOUND_CNTR4016W", mef.getJ2EEName().getComponent(), mef.schemeJndiNameInfo.getJndiName());
            }
        }

        EndpointActivationService eas = mef.endpointActivationServiceInfo.getService();
        if (eas == null) {
            if (explicit) {
                Tr.warning(tc, "MDB_ACTIVATION_SPEC_NOT_FOUND_CNTR4015W", mef.getJ2EEName().getComponent(), mef.endpointActivationServiceInfo.id);
            }
            return;
        }

        if (!isServerStarted) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "server is not started");
            }
            return;
        }

        mef.activateEndpointInternal(eas,
                                     mef.endpointActivationServiceInfo.getMaxEndpoints(),
                                     mef.adminObjectServiceInfo == null ? null :
                                                     (AdminObjectService) context.locateService("adminObjectServices", mef.adminObjectServiceInfo.serviceRef)
                        );
        mef.runtimeActivated = true;
    }
936174
public boolean enlist(UOWCoordinator coord, XAResource xaRes, int recoveryIndex, int branchCoupling)
    throws RollbackException, IllegalStateException, SystemException
    {
        final boolean traceOn = TraceComponent.isAnyTracingEnabled();

        if (traceOn && tc.isEntryEnabled()) Tr.entry(tc, "enlist", new Object[] {xaRes, recoveryIndex, branchCoupling});

        boolean result = false;

        if (coord instanceof TransactionImpl)
        {
            try
            {
                result = ((TransactionImpl)coord).enlistResource(xaRes, recoveryIndex, branchCoupling);
            }
            finally
            {
                if (traceOn && tc.isEntryEnabled()) Tr.exit(tc, "enlist", result);
            }
        }
        else
        {
            final SystemException se = new SystemException("Invalid UOWCoordinator");
            FFDCFilter.processException(se, "com.ibm.tx.jta.impl.EmbeddableTranManagerSet.enlist", "154", this);
            if (traceOn && tc.isEntryEnabled()) Tr.exit(tc, "enlist", se);
            throw se;
        }
        
        return result;
    }
76753
protected void markLocalTransactionWrapperInUse() throws ResourceException {

        final boolean isTracingEnabled = TraceComponent.isAnyTracingEnabled();

        if (isTracingEnabled && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "markLocalTransactionWrapperInUse");
        }

        if (state == STATE_ACTIVE_INUSE) {
            state = STATE_TRAN_WRAPPER_INUSE;
            tranWrapperInUse = LOCALTXWRAPPER;
            /*
             * If we are not in the shared pool we need to move the mcWrapper from
             * the unshared pool to the shared pool. Under normal conditions, this should not
             * be needed. The non-normal condition is when a user starts a user thread and
             * gets a connection then starts a transaction.
             */
            if (!(isInSharedPool() || this.getPoolState() == MCWrapper.ConnectionState_sharedTLSPool)) {
                if (cm.shareable()) {
                    pm.moveMCWrapperFromUnSharedToShared(this, uowCoord);
                }
            }
        } else { // state not STATE_ACTIVE_INUSE
            if (state != STATE_TRAN_WRAPPER_INUSE) {
                IllegalStateException e = new IllegalStateException("markLocalTransactionWrapperInUse: illegal state exception. State = " + getStateString() + " MCW = "
                                                                    + mcWrapperObject_hexString);
                Tr.error(tc, "ILLEGAL_STATE_EXCEPTION_J2CA0079", "markLocalTransactionWrapperInUse", e);
                throw e;
            } else { // state is STATE_TRAN_WRAPPER_INUSE
                if (tranWrapperInUse == NONE) {
                    tranWrapperInUse = LOCALTXWRAPPER;
                } else { //tranWrapperInUse is NOT NONE
                    if (tranWrapperInUse != LOCALTXWRAPPER) {
                        // Need RAS and Trace here.
                        IllegalStateException e = new IllegalStateException("markLocalTransactionWrapperInUse: illegal transaction state exception. State = "
                                                                            + getTranWrapperString());
                        Object[] parms = new Object[] { "markLocalTransactionWrapperInUse", e };
                        Tr.error(tc, "ILLEGAL_STATE_EXCEPTION_J2CA0079", parms);
                        throw e;
                    }
                }
            }
        }

        if (isTracingEnabled && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "markLocalTransactionWrapperInUse");
        }

        return;

    }
1325300
void closeTransactionalBranch(Xid xid) {

        if (this.transactionBinding.getTransactionBindingType() != TransactionBindingType.GlobalTransaction) {
            throw new IllegalStateException("XAConnection not associated to a global transaction");
        }

        GlobalTransactionProxy<C> globalTransactionProxy = this.transactionBinding.getEnlistedGlobalTransaction();
        globalTransactionProxy.close();

        delistTransaction();
    }
764474
public void enlistWithTransaction(SynchronizationRegistryUOWScope uowCoord,
                                      Synchronization sync)
                    throws CSIException
    {
        try
        {
            if (uowCoord.getUOWType() == UOWSynchronizationRegistry.UOW_TYPE_GLOBAL_TRANSACTION)
            {
                ((Transaction) uowCoord).registerSynchronization(sync);
            }
            else
            {
                ((LocalTransactionCoordinator) uowCoord).enlistSynchronization(sync);
            }
        } catch (Exception ex)
        {
            throw new CSIException("Failed to enlist with transaction", ex);
        }
    }
1081955
public final void beginTransaction(GlobalTransaction globalTransaction, boolean local) {
      if (local) {
         //Not overriding the InitialValue method leads me to have "null" at the first invocation of get()
         TransactionStatistics lts = createTransactionStatisticIfAbsent(globalTransaction, true);
         if (trace) {
            log.tracef("Local transaction statistic is already initialized: %s", lts);
         }
      } else {
         TransactionStatistics rts = createTransactionStatisticIfAbsent(globalTransaction, false);
         if (trace) {
            log.tracef("Using the remote transaction statistic %s for transaction %s", rts, globalTransaction);
         }
      }
   }