Search in sources :

Example 6 with EjbInvocation

use of com.sun.ejb.EjbInvocation in project Payara by payara.

the class TimerServiceNamingProxy method getTimerServiceWrapper.

private Object getTimerServiceWrapper() {
    // Cannot store EjbContainerUtilImpl.getInstance() in an instance
    // variable because it shouldn't be accessed before EJB container
    // is initialized.
    // NamedNamingObjectProxy is initialized on the first lookup.
    ComponentInvocation currentInv = EjbContainerUtilImpl.getInstance().getCurrentInvocation();
    if (currentInv == null) {
        throw new IllegalStateException("no current invocation");
    } else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
        throw new IllegalStateException("Illegal invocation type for EJB Context : " + currentInv.getInvocationType());
    }
    EJBTimerService ejbTimerService = EJBTimerService.getEJBTimerService();
    if (ejbTimerService == null) {
        throw new IllegalStateException("EJB Timer Service not " + "available");
    }
    return new EJBTimerServiceWrapper(ejbTimerService, (EJBContextImpl) ((EjbInvocation) currentInv).context);
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

Example 7 with EjbInvocation

use of com.sun.ejb.EjbInvocation in project Payara by payara.

the class TimerWrapper method checkCallPermission.

/**
 * Verify that Timer method access is allowed from this context.
 * This method is static so that TimerHandle can call it even
 * before it has created a TimerWrapper instance.
 */
private static void checkCallPermission() throws IllegalStateException {
    // Can't store a static ref because in embedded container it can be
    // changed by server restart
    EjbContainerUtil ejbContainerUtil = EjbContainerUtilImpl.getInstance();
    EJBTimerService timerService = EJBTimerService.getEJBTimerService();
    if (timerService == null) {
        throw new IllegalStateException("EJBTimerService is not available");
    }
    ComponentInvocation inv = ejbContainerUtil.getCurrentInvocation();
    if (inv == null) {
        throw new IllegalStateException("Invocation cannot be null");
    }
    ComponentInvocation.ComponentInvocationType invType = inv.getInvocationType();
    if (invType == ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
        if (inv instanceof EjbInvocation) {
            ComponentContext context = ((EjbInvocation) inv).context;
            // Delegate check to EJB context.  Let any
            // IllegalStateException bubble up.
            context.checkTimerServiceMethodAccess();
        }
    }
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) ComponentContext(com.sun.ejb.ComponentContext) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

Example 8 with EjbInvocation

use of com.sun.ejb.EjbInvocation in project Payara by payara.

the class ActiveTxCache method passivateEJB.

// Called from AbstractCache
protected boolean passivateEJB(ComponentContext ctx) {
    if (containerState != CONTAINER_STARTED) {
        return false;
    }
    EntityContextImpl context = (EntityContextImpl) ctx;
    if (!context.isInState(BeanState.READY)) {
        return false;
    }
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.log(Level.FINEST, "EntityContainer.passivateEJB(): context = (" + ctx + ")");
    }
    EntityBean ejb = (EntityBean) context.getEJB();
    EjbInvocation inv = super.createEjbInvocation(ejb, context);
    inv.method = ejbPassivateMethod;
    Object pkey = context.getPrimaryKey();
    boolean wasPassivated = false;
    // check state after locking ctx
    if (!context.isInState(BeanState.READY))
        return false;
    try {
        invocationManager.preInvoke(inv);
        // remove EJB from readyStore
        removeContextFromReadyStore(pkey, context);
        // no Tx needed for ejbPassivate
        ejb.ejbPassivate();
        wasPassivated = true;
    } catch (Exception ex) {
        _logger.log(Level.FINE, "Exception in passivateEJB()", ex);
        // Error during ejbStore/Passivate, discard bean: EJB2.0 18.3.3
        forceDestroyBean(context);
        return false;
    } finally {
        invocationManager.postInvoke(inv);
    }
    // If a future EjbInvocation arrives for them, they'll get recreated.
    if (isRemote) {
        removeEJBObjectFromStore(pkey);
    }
    if (isLocal) {
        ejbLocalObjectStore.remove(pkey);
    }
    // after calling ejbStore and ejbPassivate.
    synchronized (context) {
        addPooledEJB(context);
    }
    return wasPassivated;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) EntityBean(javax.ejb.EntityBean) EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject) EJBLocalRemoteObject(com.sun.ejb.containers.EJBLocalRemoteObject) NoSuchEntityException(javax.ejb.NoSuchEntityException) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 9 with EjbInvocation

use of com.sun.ejb.EjbInvocation in project Payara by payara.

the class ActiveTxCache method activateEJBFromPool.

/**
 * Called from getContext and getEJBWithIncompleteTx
 * Get an EJB in the ready state (i.e. which is not doing any
 * invocations and doesnt have any incomplete Tx), for the
 * ejbObject provided in the EjbInvocation.
 * Concurrent invocations should get *different* instances.
 */
protected EntityContextImpl activateEJBFromPool(Object primaryKey, EjbInvocation inv) {
    EntityContextImpl context = null;
    // get a pooled EJB and activate it.
    context = getPooledEJB();
    // set EJBObject/LocalObject for the context
    if (inv.isLocal) {
        EJBLocalObjectImpl localObjImpl = internalGetEJBLocalObjectImpl(primaryKey, true);
        containerStateManager.attachObject(inv, context, null, localObjImpl);
    // No need to create/set EJBObject if this EJB isRemote too.
    // This saves remote object creation overhead.
    // The EJBObject and stub will get created lazily if needed
    // when EntityContext.getEJBObjectImpl is called.
    } else {
        // remote EjbInvocation
        EJBObjectImpl ejbObjImpl = internalGetEJBObjectImpl(primaryKey, null, true);
        containerStateManager.attachObject(inv, context, ejbObjImpl, null);
        if (isLocal) {
            // Create EJBLocalObject so EntityContext methods work
            containerStateManager.attachObject(inv, context, null, internalGetEJBLocalObjectImpl(primaryKey, true));
        }
    }
    context.setState(BeanState.READY);
    EntityBean ejb = (EntityBean) context.getEJB();
    EjbInvocation inv2 = super.createEjbInvocation(ejb, context);
    inv2.method = ejbActivateMethod;
    invocationManager.preInvoke(inv2);
    try {
        ejb.ejbActivate();
    // Note: ejbLoad will be called during preInvokeTx
    // since this EJB instance is being associated with
    // a Tx for the first time.
    } catch (Exception ex) {
        // Error during ejbActivate, discard bean: EJB2.0 18.3.3
        forceDestroyBean(context);
        throw new EJBException(ex);
    } finally {
        invocationManager.postInvoke(inv2);
    }
    context.setNewlyActivated(true);
    // recycler.initSoftRef(context);
    afterNewlyActivated(context);
    return context;
}
Also used : EJBLocalObjectImpl(com.sun.ejb.containers.EJBLocalObjectImpl) EjbInvocation(com.sun.ejb.EjbInvocation) EntityBean(javax.ejb.EntityBean) EJBObjectImpl(com.sun.ejb.containers.EJBObjectImpl) EJBException(javax.ejb.EJBException) NoSuchEntityException(javax.ejb.NoSuchEntityException) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 10 with EjbInvocation

use of com.sun.ejb.EjbInvocation in project Payara by payara.

the class EntityContextImpl method inFinder.

private boolean inFinder() {
    boolean inFinder = false;
    ComponentInvocation ci = _container.getCurrentInvocation();
    if (ci instanceof EjbInvocation) {
        EjbInvocation inv = (EjbInvocation) ci;
        Method currentMethod = inv.method;
        inFinder = ((currentMethod != null) && inv.isHome && currentMethod.getName().startsWith("find"));
    }
    return inFinder;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) Method(java.lang.reflect.Method)

Aggregations

EjbInvocation (com.sun.ejb.EjbInvocation)44 EJBException (javax.ejb.EJBException)22 RemoteException (java.rmi.RemoteException)18 CreateException (javax.ejb.CreateException)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)16 RemoveException (javax.ejb.RemoveException)16 SystemException (javax.transaction.SystemException)15 EJBObject (javax.ejb.EJBObject)11 IOException (java.io.IOException)9 NotSerializableException (java.io.NotSerializableException)9 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)9 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)9 IllegalLoopbackException (javax.ejb.IllegalLoopbackException)9 BackingStoreException (org.glassfish.ha.store.api.BackingStoreException)9 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)7 EJBLocalRemoteObject (com.sun.ejb.containers.EJBLocalRemoteObject)6 FinderException (javax.ejb.FinderException)6 NoSuchEntityException (javax.ejb.NoSuchEntityException)6 InvocationInfo (com.sun.ejb.InvocationInfo)4