use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AbstractSingletonContainer method createEjbInvocation.
@Override
protected EjbInvocation createEjbInvocation() {
EjbInvocation inv = super.createEjbInvocation();
setResourceHandler(inv);
return inv;
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AbstractSingletonContainer method createSingletonEJB.
private SingletonContextImpl createSingletonEJB() throws CreateException {
EjbInvocation ejbInv = null;
SingletonContextImpl context;
Object ejb;
// Track whether initialization got as far as preInvokeTx.
// Needed for adequate error handling in the face of an initialization
// exception.
boolean initGotToPreInvokeTx = false;
boolean doPostConstruct = true;
try {
String sessionKey = clusteredLookup.getClusteredSessionKey();
EjbSessionDescriptor sessDesc = (EjbSessionDescriptor) ejbDescriptor;
if (clusteredLookup.isClusteredEnabled()) {
IMap<String, Object> singletonMap = clusteredLookup.getClusteredSingletonMap();
if (!singletonMap.containsKey(sessionKey)) {
context = (SingletonContextImpl) createEjbInstanceAndContext();
ejb = singletonMap.putIfAbsent(sessionKey, context.getEJB());
if ((ejb != null) && (ejb != context.getEJB()) && sessDesc.dontCallPostConstructOnAttach()) {
doPostConstruct = false;
}
} else {
context = (SingletonContextImpl) _constructEJBContextImpl(singletonMap.get(sessionKey));
ejb = context.getEJB();
ejbInv = createInvocationAndPreInvoke(ejbInv, ejb, context);
createEmptyContextAndInterceptors(context);
if (isJCDIEnabled()) {
_createJCDIInjectionContext(context, ejb, context.getJCDIInjectionContext());
}
if (sessDesc.dontCallPostConstructOnAttach()) {
doPostConstruct = false;
}
}
clusteredLookup.getClusteredUsageCount().incrementAndGet();
} else {
if (sessDesc.isClustered() && !clusteredLookup.getHazelcastCore().isEnabled()) {
_logger.log(Level.WARNING, "Clustered Singleton {0} not available - Hazelcast is Disabled", sessionKey);
}
// a dummy invocation will be created by the BaseContainer to support
// possible AroundConstruct interceptors
context = (SingletonContextImpl) createEjbInstanceAndContext();
ejb = context.getEJB();
}
ejbInv = createInvocationAndPreInvoke(ejbInv, ejb, context);
// Perform injection right after where setSessionContext
// would be called. This is important since injection methods
// have the same "operations allowed" permissions as
// setSessionContext.
injectEjbInstance(context);
if (isRemote) {
if (hasRemoteBusinessView) {
context.setEJBRemoteBusinessObjectImpl(theRemoteBusinessObjectImpl);
}
}
if (isLocal) {
if (hasLocalBusinessView) {
context.setEJBLocalBusinessObjectImpl(theEJBLocalBusinessObjectImpl);
}
if (hasOptionalLocalBusinessView) {
context.setOptionalEJBLocalBusinessObjectImpl(theOptionalEJBLocalBusinessObjectImpl);
}
}
// Call preInvokeTx directly. InvocationInfo containing tx
// attribute must be set prior to calling preInvoke
ejbInv.transactionAttribute = postConstructInvInfo.txAttr;
ejbInv.invocationInfo = postConstructInvInfo;
initGotToPreInvokeTx = true;
preInvokeTx(ejbInv);
context.setInstanceKey(singletonInstanceKey);
if (doPostConstruct) {
intercept(CallbackType.POST_CONSTRUCT, context);
}
} catch (Throwable th) {
if (ejbInv != null) {
ejbInv.exception = th;
}
singletonInitializationFailed = true;
CreateException creEx = new CreateException("Initialization failed for Singleton " + ejbDescriptor.getName());
creEx.initCause(th);
throw creEx;
} finally {
initializationInProgress = false;
if (ejbInv != null) {
try {
invocationManager.postInvoke(ejbInv);
if (initGotToPreInvokeTx) {
postInvokeTx(ejbInv);
}
} catch (Exception pie) {
if (ejbInv.exception != null) {
_logger.log(Level.WARNING, "Exception during Singleton startup postInvoke ", pie);
} else {
ejbInv.exception = pie;
singletonInitializationFailed = true;
CreateException creEx = new CreateException("Initialization failed for Singleton " + ejbDescriptor.getName());
creEx.initCause(pie);
throw creEx;
}
}
}
}
// Set the state to POOLED after ejbCreate so that
// EJBContext methods not allowed will throw exceptions
context.setState(EJBContextImpl.BeanState.POOLED);
context.touch();
return context;
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class EJBHomeInvocationHandler method invoke.
/**
* Called by EJBHome proxy.
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
ClassLoader originalClassLoader = null;
// if method signature has 0 arguments.
try {
((BaseContainer) getContainer()).onEnteringContainer();
if (Thread.currentThread().getContextClassLoader() != getContainer().getClassLoader()) {
originalClassLoader = Utility.setContextClassLoader(getContainer().getClassLoader());
}
Class methodClass = method.getDeclaringClass();
if (methodClass == java.lang.Object.class) {
return InvocationHandlerUtil.invokeJavaObjectMethod(this, method, args);
} else if (invokeSpecialEJBHomeMethod(method, methodClass, args)) {
return null;
}
// Use optimized version of get that takes param count as an
// argument.
InvocationInfo invInfo = (InvocationInfo) invocationInfoMap_.get(method, ((args != null) ? args.length : 0));
if (invInfo == null) {
throw new RemoteException("Unknown Home interface method :" + method);
} else if ((methodClass == javax.ejb.EJBHome.class) || invInfo.ejbIntfOverride) {
return invokeEJBHomeMethod(method.getName(), args);
} else if (GenericEJBHome.class.isAssignableFrom(methodClass)) {
if (method.getName().equals("create")) {
// This is an internal creation request through the EJB 3.0
// client view, so just create an business object and return it
EJBObjectImpl busObjectImpl = createRemoteBusinessObjectImpl();
return busObjectImpl.getStub((String) args[0]);
} else {
EjbAsyncInvocationManager asyncManager = ((EjbContainerUtilImpl) ejbContainerUtil).getEjbAsyncInvocationManager();
Long asyncTaskID = (Long) args[0];
RemoteAsyncResult asyncResult = null;
if (method.getName().equals("cancel")) {
asyncResult = asyncManager.remoteCancel(asyncTaskID);
} else if (method.getName().equals("get")) {
asyncResult = asyncManager.remoteGet(asyncTaskID);
} else if (method.getName().equals("isDone")) {
asyncResult = asyncManager.remoteIsDone(asyncTaskID);
} else if (method.getName().equals("getWithTimeout")) {
Long timeout = (Long) args[1];
TimeUnit unit = TimeUnit.valueOf((String) args[2]);
asyncResult = asyncManager.remoteGetWithTimeout(asyncTaskID, timeout, unit);
}
return asyncResult;
}
}
// Process finder, create method, or home method.
EJBObjectImpl ejbObjectImpl = null;
Object returnValue = null;
if (invInfo.startsWithCreate) {
ejbObjectImpl = createEJBObjectImpl();
if (ejbObjectImpl != null) {
// Entity beans are created differently
returnValue = ejbObjectImpl.getStub();
}
}
if (!isStatelessSession_) {
if (invInfo.targetMethod1 == null) {
_logger.log(Level.SEVERE, "ejb.bean_class_method_not_found", new Object[] { invInfo.ejbName, "Home", invInfo.method.toString() });
// in exception use message without ID
String errorMsg = localStrings.getLocalString("ejb.bean_class_method_not_found", "", new Object[] { invInfo.ejbName, "Home", invInfo.method.toString() });
throw new RemoteException(errorMsg);
}
EjbInvocation inv = ((BaseContainer) getContainer()).createEjbInvocation();
inv.isRemote = true;
inv.method = method;
inv.isHome = true;
inv.clientInterface = homeIntfClass_;
// Set cached invocation params. This will save
// additional lookups in BaseContainer.
inv.transactionAttribute = invInfo.txAttr;
inv.invocationInfo = invInfo;
if (ejbObjectImpl != null && invInfo.startsWithCreate) {
inv.ejbObject = (EJBLocalRemoteObject) ejbObjectImpl;
}
BaseContainer container = (BaseContainer) getContainer();
try {
container.preInvoke(inv);
if (invInfo.startsWithCreate) {
Object ejbCreateReturnValue = invokeTargetBeanMethod(container, invInfo.targetMethod1, inv, inv.ejb, args);
postCreate(container, inv, invInfo, ejbCreateReturnValue, args);
if (inv.ejbObject != null) {
returnValue = ((EJBObjectImpl) inv.ejbObject).getStub();
}
} else if (invInfo.startsWithFindByPrimaryKey) {
returnValue = container.invokeFindByPrimaryKey(invInfo.targetMethod1, inv, args);
} else if (invInfo.startsWithFind) {
Object pKeys = invokeTargetBeanMethod(container, invInfo.targetMethod1, inv, inv.ejb, args);
returnValue = container.postFind(inv, pKeys, null);
} else {
returnValue = invokeTargetBeanMethod(container, invInfo.targetMethod1, inv, inv.ejb, args);
}
} catch (InvocationTargetException ite) {
inv.exception = ite.getCause();
} catch (Throwable c) {
inv.exception = c;
} finally {
container.postInvoke(inv);
}
if (inv.exception != null) {
InvocationHandlerUtil.throwRemoteException(inv.exception, method.getExceptionTypes());
}
}
return returnValue;
} finally {
if (originalClassLoader != null) {
Utility.setContextClassLoader(originalClassLoader);
}
((BaseContainer) getContainer()).onLeavingContainer();
}
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AsynchronousTask method passivateEJB.
// called asynchronously from the Recycler
public final boolean passivateEJB(ComponentContext context) {
SessionContextImpl sc = (SessionContextImpl) context;
boolean success = false;
try {
if (ejbDescriptor.getApplication().getKeepStateResolved() == false) {
if ((containerState != CONTAINER_STARTED) && (containerState != CONTAINER_STOPPED)) {
_logger.log(Level.WARNING, PASSIVATE_EJB_RETURNING_BECAUSE_CONTAINER_STATE, containerState);
return false;
}
}
if (sc.getState() == BeanState.DESTROYED)
return false;
if (_logger.isLoggable(TRACE_LEVEL)) {
_logger.log(TRACE_LEVEL, traceInfoPrefix + "Passivating context " + sc.getInstanceKey() + "; current-state = " + convertCtxStateToString(sc));
}
Object ejb = sc.getEJB();
long passStartTime = -1;
/* TODO
if (sfsbStoreMonitor.isMonitoringOn()) {
passStartTime = System.currentTimeMillis();
}
*/
EjbInvocation ejbInv = createEjbInvocation(ejb, sc);
invocationManager.preInvoke(ejbInv);
boolean failed = false;
success = false;
boolean needToDoPostInvokeTx = false;
boolean destroyBean = false;
synchronized (sc) {
try {
// for this instance.
if (!sc.canBePassivated()) {
return false;
}
Serializable instanceKey = (Serializable) sc.getInstanceKey();
if (sessionBeanCache.eligibleForRemovalFromCache(sc, instanceKey)) {
// remove the EJB since removal-timeout has elapsed
sc.setState(BeanState.DESTROYED);
needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, sc, preDestroyInvInfo, CallbackType.PRE_DESTROY);
sessionBeanCache.remove(instanceKey, sc.existsInStore());
} else {
// passivate the EJB
sc.setState(BeanState.PASSIVATED);
decrementMethodReadyStat();
needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, sc, prePassivateInvInfo, CallbackType.PRE_PASSIVATE);
sc.setLastPersistedAt(System.currentTimeMillis());
boolean saved = false;
try {
saved = sessionBeanCache.passivateEJB(sc, instanceKey);
} catch (EMNotSerializableException emNotSerEx) {
_logger.log(Level.WARNING, EXTENDED_EM_NOT_SERIALIZABLE, emNotSerEx);
_logger.log(Level.FINE, "Extended EM not serializable", emNotSerEx);
saved = false;
}
if (!saved) {
// TODO - add a flag to reactivate in the same tx
// Complete previous tx
completeLifecycleCallbackTxIfUsed(ejbInv, sc, needToDoPostInvokeTx);
needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, sc, postActivateInvInfo, CallbackType.POST_ACTIVATE);
sc.setState(BeanState.READY);
incrementMethodReadyStat();
return false;
}
}
// V2: sfsbStoreMonitor.incrementPassivationCount(true);
cacheProbeNotifier.ejbBeanPassivatedEvent(getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName, true);
transactionManager.componentDestroyed(sc);
decrementRefCountsForEEMs(sc);
if (isRemote) {
if (hasRemoteHomeView) {
// disconnect the EJBObject from the EJB
EJBObjectImpl ejbObjImpl = sc.getEJBObjectImpl();
ejbObjImpl.clearContext();
sc.setEJBObjectImpl(null);
// disconnect the EJBObject from ProtocolManager
// so that no state is held by ProtocolManager
remoteHomeRefFactory.destroyReference(ejbObjImpl.getStub(), ejbObjImpl.getEJBObject());
}
if (hasRemoteBusinessView) {
// disconnect the EJBObject from the EJB
EJBObjectImpl ejbBusinessObjImpl = sc.getEJBRemoteBusinessObjectImpl();
ejbBusinessObjImpl.clearContext();
sc.setEJBRemoteBusinessObjectImpl(null);
for (RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
next.referenceFactory.destroyReference(ejbBusinessObjImpl.getStub(), ejbBusinessObjImpl.getEJBObject(next.generatedRemoteIntf.getName()));
}
}
}
if (isLocal) {
long version = sc.getVersion();
if (hasLocalHomeView) {
// disconnect the EJBLocalObject from the EJB
EJBLocalObjectImpl localObjImpl = sc.getEJBLocalObjectImpl();
localObjImpl.setSfsbClientVersion(version);
localObjImpl.clearContext();
sc.setEJBLocalObjectImpl(null);
}
if (hasLocalBusinessView) {
EJBLocalObjectImpl localBusinessObjImpl = sc.getEJBLocalBusinessObjectImpl();
localBusinessObjImpl.setSfsbClientVersion(version);
localBusinessObjImpl.clearContext();
sc.setEJBLocalBusinessObjectImpl(null);
}
if (hasOptionalLocalBusinessView) {
EJBLocalObjectImpl optLocalBusObjImpl = sc.getOptionalEJBLocalBusinessObjectImpl();
optLocalBusObjImpl.setSfsbClientVersion(version);
optLocalBusObjImpl.clearContext();
sc.setOptionalEJBLocalBusinessObjectImpl(null);
}
}
if (_logger.isLoggable(TRACE_LEVEL)) {
logTraceInfo(sc, "Successfully passivated");
}
} catch (java.io.NotSerializableException nsEx) {
// V2: sfsbStoreMonitor.incrementPassivationCount(false);
cacheProbeNotifier.ejbBeanPassivatedEvent(getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName, false);
_logger.log(Level.WARNING, ERROR_DURING_PASSIVATION, new Object[] { sc, nsEx });
_logger.log(Level.FINE, "sfsb passivation error", nsEx);
// Error during passivate, so discard bean: EJB2.0 18.3.3
destroyBean = true;
} catch (Throwable ex) {
// V2: sfsbStoreMonitor.incrementPassivationCount(false);
cacheProbeNotifier.ejbBeanPassivatedEvent(getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName, false);
_logger.log(Level.WARNING, PASSIVATION_ERROR_1PARAM, new Object[] { ejbDescriptor.getName() + " <==> " + sc });
_logger.log(Level.WARNING, SFSB_PASSIVATION_ERROR_1PARAM, new Object[] { sc.getInstanceKey(), ex });
// Error during passivate, so discard bean: EJB2.0 18.3.3
destroyBean = true;
} finally {
invocationManager.postInvoke(ejbInv);
completeLifecycleCallbackTxIfUsed(ejbInv, sc, needToDoPostInvokeTx);
if (destroyBean) {
try {
forceDestroyBean(sc);
} catch (Exception e) {
_logger.log(Level.FINE, "error destroying bean", e);
}
}
if (passStartTime != -1) {
long timeSpent = System.currentTimeMillis() - passStartTime;
// V2: sfsbStoreMonitor.setPassivationTime(timeSpent);
}
}
}
// synchronized
} catch (Exception ex) {
_logger.log(Level.WARNING, PASSIVATION_ERROR_1PARAM, new Object[] { ejbDescriptor.getName(), ex });
}
return success;
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AsynchronousTask method afterInstanceCreation.
private void afterInstanceCreation(SessionContextImpl context) throws Exception {
context.setState(BeanState.READY);
EjbInvocation ejbInv = null;
boolean inTx = false;
try {
// Need to do preInvoke because setSessionContext can access JNDI
ejbInv = super.createEjbInvocation(context.getEJB(), context);
invocationManager.preInvoke(ejbInv);
// PostConstruct must be called after state set to something
// other than CREATED
inTx = callLifecycleCallbackInTxIfUsed(ejbInv, context, postConstructInvInfo, CallbackType.POST_CONSTRUCT);
} catch (Throwable t) {
EJBException ejbEx = new EJBException();
ejbEx.initCause(t);
throw ejbEx;
} finally {
if (ejbInv != null) {
try {
invocationManager.postInvoke(ejbInv);
if (inTx) {
// Call directly to report exception
postInvokeTx(ejbInv);
}
} catch (Exception pie) {
if (ejbInv.exception != null) {
_logger.log(Level.FINE, "Exception during SFSB startup postInvoke ", pie);
} else {
ejbInv.exception = pie;
CreateException creEx = new CreateException("Initialization failed for Stateful Session Bean " + ejbDescriptor.getName());
creEx.initCause(pie);
throw creEx;
}
} finally {
context.setInLifeCycleCallback(false);
}
}
}
ejbProbeNotifier.ejbBeanCreatedEvent(getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName);
incrementMethodReadyStat();
}
Aggregations