Enlist the given <code>BeanO</code> in this container transaction.
761264
protected boolean enlist(BeanO beanO)
                    throws TransactionRolledbackException
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled(); // d532639.2

        if (isTraceOn && tc.isEntryEnabled()) // d144064
            Tr.entry(tc, "enlist"
                     , new Object[] { Boolean.valueOf(globalTransaction), this, beanO }
                            ); //123293

        ensureActive();

        if (ivBeanOsEnlistedInTx == false) // d532639.2
        {
            initialize_beanO_vectors(); // d111555
        }

        boolean wasEnlisted = false;//d132828 avoid multiple returns

        //synchronized (beanOs) {  //d173022.2

        BeanO oldBeanO = beanOs.put(beanO.beanId, beanO);

        //d115597 begins

        if (oldBeanO == null) {

            // d140003.22 -- If CMP 2.0 bean, add bean to CMP 2.0 list for later use
            // Except, don't add ReadOnly/Interval beans to CMP 2.0 list; they
            // never need to be included in pre-find flush.               LI3408
            BeanMetaData bmd = beanO.home.beanMetaData;
            if (bmd.cmpVersion == InternalConstants.CMP_VERSION_2_X &&
                bmd.ivCacheReloadType == BeanMetaData.CACHE_RELOAD_NONE)
            {
                ArrayList<BeanO> bundle = homesForPMManagedBeans.get(beanO.home);

                if (bundle == null) { // here, value of null indicates no bundle in map
                    bundle = new ArrayList<BeanO>();
                    homesForPMManagedBeans.put(beanO.home, bundle);
                }

                bundle.add(beanO);
                if (isTraceOn && tc.isDebugEnabled())
                    Tr.debug(tc, "Added this BeanO to CMP20 structure");
            }

            afterList.add(beanO);//d115597 if new BeanO add to afterList
            if (origLock == false) {
                beanOList.add(beanO);//d115597 have not started beforeCompletion

            } else {
                setupTempLists();//d132828
                if (isTraceOn && tc.isDebugEnabled())
                    Tr.debug(tc, "sec enlist new : " + beanO);

                currentBeanOs.put(beanO.beanId, beanO);//d115597 new bean added once beforeCompletion called
                tempList.add(beanO); //d115597 add to the tempList
            }

            wasEnlisted = true;//d132828 avoid multiple returns

        }//new beanO
        else {
            // d115597 this bean is already in the tran, need to determine if this is a reenlistment
            if (origLock == true) {
                // d115597 this path is that beforeCompletion has started
                setupTempLists(); //d132828

                if (isTraceOn && tc.isDebugEnabled())
                    Tr.debug(tc, "enlist in beforeCompletion: putting in list");

                BeanO obO = currentBeanOs.put(beanO.beanId, beanO);

                if (obO == null) {
                    if (isTraceOn && tc.isDebugEnabled())
                        Tr.debug(tc, "Secondary enlist old : " + beanO);

                    // d115597 is this in the current list if not add?
                    tempList.add(beanO);
                }// d115597 not in current tran list

                // d115597 should return false
            }// d115597 not in original list of beanos (2nd or greater run through

        }// old beanO
         //d115597 end
         //}//synch end

        if (isTraceOn && tc.isEntryEnabled()) // d144064
            Tr.exit(tc, "enlist : " + wasEnlisted); // d144064

        return wasEnlisted;// d132828 avoid multiple returns
    }
287169
@Override
    public void enlist() throws ResourceException {

        if (tc.isEntryEnabled()) {
            Tr.entry(this, tc, "enlist", mcWrapper.getUOWCoordinator());
        }

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

            if (tc.isEntryEnabled()) {
                Tr.exit(this, tc, "enlist", "already enlisted");
            }
            return; // Already enlisted, no-op.

        } // end enlisted == true

        UOWCoordinator uowCoord = mcWrapper.getUOWCoordinator();
        if (uowCoord != null) {
            if (uowCoord.isGlobal()) {
                // Global Transaction
                EmbeddableWebSphereTransactionManager tranMgr = mcWrapper.pm.connectorSvc.transactionManager;
                try {
                    if (_rrsTransactional) {
                        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");
                        }

                        mcWrapper.enlistRRSXAResource(mcWrapper.getRecoveryToken(), startFlag);
                    }

                    // Use the following enlist call since this is a One Phase resource.
                    boolean rc = false;
                    rc = tranMgr.enlistOnePhase(uowCoord, this);
                    if (rc != true) {
                        Tr.error(tc, "BAD_RETURN_VALUE_FROM_ENLIST_J2CA0087", this, mcWrapper.gConfigProps.cfName);
                        ResourceException x = new ResourceException("Error on enlistOnePhase");
                        if (tc.isEntryEnabled())
                            Tr.exit(this, tc, "enlist", x);
                        throw x;
                    }
                    mcWrapper.markLocalTransactionWrapperInUse();
                    enlisted = true;
                } catch (ResourceException e) {
                    com.ibm.ws.ffdc.FFDCFilter.processException(
                                                                e,
                                                                "com.ibm.ejs.j2c.LocalTransactionWrapper.enlist",
                                                                "344",
                                                                this);
                    Tr.error(tc, "ENLIST_RESOURCE_EXCP_J2CA0030", "enlist", e, "Exception", mcWrapper.gConfigProps.cfName);

                    // Error recovery from enlist has been moved here.  The transaction team has
                    //  asked us to setRollbackOnly() for all the failed enlist() calls.  Doing
                    //  this causes them (for release 5.0. They may change it next release) to
                    //  flow the rollback sequence to all the other resources in the tran.  This
                    //  connection failed to enlist and so won't be called to roll back.  This
                    //  connection is, however registered for afterCompletion calls which they will
                    //  also drive.  Its important that we mark this connection stale prior to
                    //  calling setRollbackOnly() because our afterCompletion code will return it
                    //  to the freePool if we don't.  We want the connection destroyed since it
                    //  is potentially corrupt.
                    mcWrapper.markTransactionError();
                    try {
                        tranMgr.getTransaction().setRollbackOnly();
                    } catch (Exception ex) {
                        com.ibm.ws.ffdc.FFDCFilter.processException(ex, "com.ibm.ejs.j2c.LocalTransactionWrapper.enlist",
                                                                    "445", this);
                        if (tc.isEventEnabled()) {
                            Tr.event(this, tc,
                                     "Caught Exception while trying to mark transaction RollbackOnly - Exception:"
                                               + ex);
                        }
                    }

                    if (tc.isEntryEnabled())
                        Tr.exit(this, tc, "enlist", e);
                    throw e;
                } catch (Exception e) {
                    com.ibm.ws.ffdc.FFDCFilter.processException(
                                                                e,
                                                                "com.ibm.ejs.j2c.LocalTransactionWrapper.enlist",
                                                                "459",
                                                                this,
                                                                new Object[] { mcWrapper }); //LI3162-5
                    Tr.error(tc, "ENLIST_RESOURCE_EXCP_J2CA0030", "enlist", e, "Exception", mcWrapper.gConfigProps.cfName);

                    // Error recovery from enlist has been moved here.  The transaction team has
                    //  asked us to setRollbackOnly() for all the failed enlist() calls.  Doing
                    //  this causes them (for release 5.0. They may change it next release) to
                    //  flow the rollback sequence to all the other resources in the tran.  This
                    //  connection failed to enlist and so won't be called to roll back.  This
                    //  connection is, however registered for afterCompletion calls which they will
                    //  also drive.  Its important that we mark this connection stale prior to
                    //  calling setRollbackOnly() because our afterCompletion code will return it
                    //  to the freePool if we don't.  We want the connection destroyed since it
                    //  is potentially corrupt.
                    mcWrapper.markTransactionError();
                    try {
                        tranMgr.getTransaction().setRollbackOnly();
                    } catch (Exception ex) {
                        com.ibm.ws.ffdc.FFDCFilter.processException(ex, "com.ibm.ejs.j2c.LocalTransactionWrapper.enlist",
                                                                    "477", this);
                        if (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 (tc.isEntryEnabled())
                        Tr.exit(this, tc, "enlist", re);
                    throw re;
                }
                if (tc.isEntryEnabled()) {
                    Tr.exit(this, tc, "enlist");
                }
                return;
            } // end Global Transaction
            else {
                // Local Transaction
                try {
                    if (_rrsTransactional) {
                        int dummyInt = -1;
                        rrsXAResource = mcWrapper.enlistRRSXAResource(dummyInt, dummyInt);
                    }

                    // If the resolution is CONTAINER_AT_BOUNDARY then do a straight enlist.
                    // The transaction service will manage begin/end of this transaction.
                    if (((LocalTransactionCoordinator) uowCoord).isContainerResolved()) {
                        ((LocalTransactionCoordinator) uowCoord).enlist(this);
                    } else {
                        // If resolution is NOT CONTAINER_AT_BOUNDARY, we assume it is APPLICATION,
                        //  (which is the only other choice and also the default) then do an
                        //  enistForCleanup.  Here the application is expected to commit/rollback
                        //  the local transaction.  If it does, we will get an event in our
                        //  connectionEventListener and it will drive delist() on this object,
                        //  which in turn will call delistFromCleanup. If the user doesn't
                        //  commit/rollback the transaction service will clean things up.
                        ((LocalTransactionCoordinator) uowCoord).enlistForCleanup(this);
                    }
                    mcWrapper.markLocalTransactionWrapperInUse();
                    enlisted = true;
                } catch (Exception e) {
                    com.ibm.ws.ffdc.FFDCFilter.processException(
                                                                e,
                                                                "com.ibm.ejs.j2c.LocalTransactionWrapper.enlist",
                                                                "405",
                                                                this);
                    mcWrapper.markTransactionError();
                    mcWrapper.releaseToPoolManager();
                    Tr.error(tc, "ENLIST_RESOURCE_EXCP_J2CA0030", "enlist", e, "Exception", mcWrapper.gConfigProps.cfName);
                    ResourceException re = new ResourceException("enlist: caught Exception");
                    re.initCause(e);
                    if (tc.isEntryEnabled())
                        Tr.exit(this, tc, "enlist", e);
                    throw re;
                }
                if (tc.isEntryEnabled()) {
                    Tr.exit(this, tc, "enlist", "Local Tran");
                }
                return;
            } // end Local Transaction
        } else {
            // No transaction context.  Should never happen.
            Tr.error(tc, "NO_VALID_TRANSACTION_CONTEXT_J2CA0040", "enlist", null, mcWrapper.gConfigProps.cfName);
            ResourceException x = new ResourceException("INTERNAL ERROR: No valid transaction context present");
            if (tc.isEntryEnabled())
                Tr.exit(this, tc, "enlist", x);
            throw x;
        }

    }
885441
@Override
    public BeanO createBeanO(EJBThreadData threadData, ContainerTx tx, BeanId id)
                    throws RemoteException
    {
        homeEnabled();
        BeanO result = createBeanO(threadData, tx, true, null); // d630940
        result.setId(id);
        return result;
    }
1145264
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
        if (thisMethod == null) {
            BeanLogger.LOG.methodHandlerProcessingReturningBeanInstance(self.getClass());
            if (beanInstance == null) {
                throw BeanLogger.LOG.beanInstanceNotSetOnProxy(getBean());
            }
            return beanInstance.getInstance();
        }
        BeanLogger.LOG.methodHandlerProcessingCall(thisMethod, self.getClass());
        if (thisMethod.getDeclaringClass().equals(TargetInstanceProxy.class)) {
            if (beanInstance == null) {
                throw BeanLogger.LOG.beanInstanceNotSetOnProxy(getBean());
            }
            if (thisMethod.getName().equals("weld_getTargetInstance")) {
                return beanInstance.getInstance();
            } else if (thisMethod.getName().equals("weld_getTargetClass")) {
                return beanInstance.getInstanceType();
            } else {
                return null;
            }
        } else if (thisMethod.getName().equals("_initMH")) {
            BeanLogger.LOG.settingNewMethodHandler(args[0], self.getClass());
            return new ProxyMethodHandler(contextId, new TargetBeanInstance(args[0]), getBean());
        } else {
            if (beanInstance == null) {
                throw BeanLogger.LOG.beanInstanceNotSetOnProxy(getBean());
            }
            Object instance = beanInstance.getInstance();
            Object result = beanInstance.invoke(instance, thisMethod, args);
            // if the method returns this and the return type matches the proxy type, return the proxy instead
            // to prevent the bean instance escaping
            if (result != null && result == instance && (thisMethod.getReturnType().isAssignableFrom(self.getClass()))) {
                return self;
            }
            return result;
        }
    }
1337139
public EJBObject postCreate(BeanO beanO)
                    throws CreateException,
                    RemoteException
    {
        homeEnabled();
        return postCreate(beanO, beanO.getId(), false); // d142250
    }
1100582
@Trivial
    protected void activate(ComponentContext context) throws Exception {
        Dictionary<String, ?> props = context.getProperties();
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(this, tc, "activate", props);

        resourceAdapterID = (String) props.get("id");
        contextProviders.activate(context);
        bvalRef.activate(context);
        tranInflowManagerRef.activate(context);
        tranSyncRegistryRef.activate(context);
        jcaSecurityContextRef.activate(context);
        componentContext = context;
        properties = props;
        raMetaData = resourceAdapterSvc.getResourceAdapterMetaData();
        myAppName = raMetaData != null ? raMetaData.getJ2EEName().getApplication() : null;

        Object svc = bvalRef.getService();
        if (svc != null) {
            // Isolate and dynamic load BeanValidationHelpImpl class to avoid javax.validation bundle dependency
            //  when beanValidation feature is not deployed.
            if (System.getSecurityManager() == null)
                bvalHelper = (BeanValidationHelper) componentContext.getBundleContext().getBundle().loadClass("com.ibm.ws.jca.internal.BeanValidationHelperImpl").newInstance();
            else
                bvalHelper = AccessController.doPrivileged(new PrivilegedExceptionAction<BeanValidationHelper>() {
                    @Override
                    public BeanValidationHelper run() throws IllegalAccessException, ClassNotFoundException, InstantiationException {
                        return (BeanValidationHelper) componentContext.getBundleContext().getBundle().loadClass("com.ibm.ws.jca.internal.BeanValidationHelperImpl").newInstance();
                    }
                });
            bvalHelper.setBeanValidationSvc(svc);
        }

        resourceAdapter = configureResourceAdapter();
        if (resourceAdapter != null) {
            propagateThreadContext = !"(service.pid=com.ibm.ws.context.manager)".equals(properties.get("contextService.target"));
            workManager = new WorkManagerImpl(this);

            // Normally it's a bad practice to do this in activate. But here we have a requirement to keep the
            // reference count until some subsequent processing occurs after deactivate.
            contextSvc = Utils.priv.getService(componentContext, contextSvcRef);

            jcasu = new JcaServiceUtilities();
            raThreadContextDescriptor = captureRaThreadContext(contextSvc);
            raClassLoader = resourceAdapterSvc.getClassLoader();
            raClassLoader = raClassLoader == null ? null : classLoadingSvc.createThreadContextClassLoader(raClassLoader);

            ArrayList<ThreadContext> threadContext = startTask(raThreadContextDescriptor);
            try {
                beginContext(raMetaData);
                try {
                    ClassLoader previousClassLoader = jcasu.beginContextClassLoader(raClassLoader);
                    try {
                        resourceAdapter.start(this);
                    } finally {
                        jcasu.endContextClassLoader(raClassLoader, previousClassLoader);
                    }
                } finally {
                    endContext(raMetaData);
                }
            } finally {
                stopTask(raThreadContextDescriptor, threadContext);
            }
        }

        latches.put(resourceAdapterID, latch); // only add latch if activate is successful
    }
217450
public void join() {
        try {
            UnicastRemoteObject.unexportObject(registry, true);
            /*
             * NOTE: javaRunner.waitForExit() works for Equinox and Felix, but not for Knopflerfish,
             * need to investigate why. OTOH, it may be better to kill the process as we're doing
             * now, just to be on the safe side.
             */
            javaRunner.shutdown();
        }
        catch (NoSuchObjectException exc) {
            throw new TestContainerException(exc);
        }
    }
903838
public void acquire() 
    { 
        if (_hasAcquired)
            return;

        // Deliver the onAcquire event to registered listeners
        for (ResourceEvents resourceListener : _listeners)
            resourceListener.onAcquire();

        // Register this ResourceContext with associated container context
        _containerContext.addResourceContext(this, _bean);

        // Set the flag to indicate resources have been acquired.
        _hasAcquired = true;
    }
1247130
public void createFailure(BeanO beanO)
    {
        //-----------------------------------------------------------
        // If beanO is null then it was never added to the container
        // so we don't need to do anything.
        //-----------------------------------------------------------

        if (beanO != null) {
            EJSContainer.getThreadData().popCallbackBeanO();

            beanO.destroy();
            try {
                container.removeBean(beanO);
            } catch (CSITransactionRolledbackException ex) {
                //---------------------------------------------------
                // If transaction rolled back beanO has already been
                // successfully removed from container.
                //---------------------------------------------------
                FFDCFilter.processException(ex, CLASS_NAME + ".createFailure",
                                            "1732", this);
            }
        }
    }
278175
public void processClassBeanAttributes() {
        preInitializeBeans(getEnvironment().getClassBeans());
        preInitializeBeans(getEnvironment().getDecorators());
        preInitializeBeans(getEnvironment().getInterceptors());

        processBeans(getEnvironment().getClassBeans());
        processBeans(getEnvironment().getDecorators());
        processBeans(getEnvironment().getInterceptors());

        // now that we know that the bean won't be vetoed, it's the right time to register @New injection points
        searchForNewBeanDeclarations(getEnvironment().getClassBeans());
        searchForNewBeanDeclarations(getEnvironment().getDecorators());
        searchForNewBeanDeclarations(getEnvironment().getInterceptors());
    }
1361279
@SuppressWarnings("unchecked")
	public void contextInitialized(ServletContextEvent sce) {
		synchronized (Jaguar.class) {
			if (!running()) {
				bootstrap();
			}
		}
		
		assemble(this);
		WebContext<ServletContext> context = (WebContext<ServletContext>) container.component(container.contexts().get(Application.class));
		context.associate(sce.getServletContext());
		Class<?> deployment = deployment(sce.getServletContext());
		
		if (deployment != null) {
			Jaguar.deployment(deployment);
		}
		
		install(components(sce.getServletContext()));
	}
574273
public void pushContexts(BeanO beanO) throws CSIException {
        // Push the callback BeanO first since this is fallible.
        pushCallbackBeanO(beanO);

        // Pushing ComponentMetaData and ClassLoader are infallible.
        BeanMetaData bmd = beanO.home.beanMetaData;
        pushMetaDataContexts(bmd);
    }
497209
public void add(StatefulBeanO beanO) {
        BeanId id = beanO.beanId;
        TimeoutElement elt = beanO.ivTimeoutElement;

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "add " + beanO.beanId + ", " + elt.timeout);

        // LIDB2775-23.4 Begins
        Object obj = ivStatefulBeanList.put(id, elt);
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, (obj != null) ? "Stateful bean information replaced" : "Stateful bean information added");
        // LIDB2775-23.4 Ends

        synchronized (this) {
            if (numObjects == 0 && !ivIsCanceled) // F743-33394
            {
                startAlarm();
            }

            numObjects++;
            numAdds++;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "add");
    }
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);
        }
    }
603428
public static <T> BeanObservablesDecorator<T> decorate(Observable<T> observable)
	{
		return new BeanObservablesDecorator<T>(observable);
	}
1031437
public void removeBean(ContainerTx tx, BeanO bean)
    {
        bean.getActivationStrategy().atRemove(tx, bean);
    }
959609
public void removeBean(BeanO beanO) throws CSITransactionRolledbackException {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled(); // d532639.2

        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "removeBean with BeanO");

        //------------------------------------------------------------------------
        // If bean id is null then beanO could not have been added to this
        // container. Also, if beanO is not enlisted in the tran, then it either
        // was never added to this container, or it was added, but already
        // removed.  This may occur for example in the case of a
        // DuplicateKeyException.                                 dPQ51806 d145697
        //------------------------------------------------------------------------

        BeanId id = beanO.getId();

        if (id != null) {
            try {
                // If this particular BeanO was enlisted, then it needs to be
                // removed from the tran and the ejb cache.                  d145697
                ContainerTx currentTx = getCurrentTx(false); //d171654 // d139352-2
                if (currentTx.delist(beanO)) {
                    activator.removeBean(currentTx, beanO);
                } else {
                    // This is normal, it just means the failure occurred early in
                    // the create proccess, before the bean was ever enlisted or
                    // added to the EJB Cache.                                d145697
                    if (isTraceOn && tc.isDebugEnabled())
                        Tr.debug(tc, "BeanO not enlisted - not removed from tx or cache");
                }
            } catch (Throwable th) {
                // The transaction may have already rolled back.             d145697
                FFDCFilter.processException(th, CLASS_NAME + ".removeBean(BeanO)",
                                            "1949", this);
                if (isTraceOn && tc.isEventEnabled())
                    Tr.event(tc, "Exception thrown in removeBean()",
                             new Object[] { beanO, th });
            }
        } else {
            // This is normal, it just means the failure occurred early in
            // the create proccess, before the bean was ever enlisted or
            // added to the EJB Cache.                                      d145697
            if (isTraceOn && tc.isDebugEnabled())
                Tr.debug(tc, "BeanId is null");
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "removeBean");
    }