use of org.glassfish.ejb.deployment.descriptor.EjbRemovalInfo in project Payara by payara.
the class AsynchronousTask method releaseContext.
/**
* Called from preInvoke which is called from the EJBObject for local and
* remote invocations.
*/
@Override
public void releaseContext(EjbInvocation inv) {
SessionContextImpl sc = (SessionContextImpl) inv.context;
// any instance lock is released in the finally block.
try {
// check if the bean was destroyed
if (sc.getState() == BeanState.DESTROYED) {
return;
}
// we're sure that no concurrent thread can be using this
// context, so no need to synchronize.
Transaction tx = sc.getTransaction();
// If this was an invocation of a remove-method
if (inv.invocationInfo.removalInfo != null) {
InvocationInfo invInfo = inv.invocationInfo;
EjbRemovalInfo removeInfo = invInfo.removalInfo;
if (retainAfterRemoveMethod(inv, removeInfo)) {
_logger.log(Level.FINE, () -> //
"Skipping destruction of SFSB " + invInfo.ejbName + " after @Remove method " + //
invInfo.method + " due to (retainIfException == true) and exception " + inv.exception);
} else {
try {
destroyBean(inv, sc);
} catch (Throwable t) {
_logger.log(Level.FINE, "@Remove.preDestroy exception", t);
}
// Explicitly null out transaction association in bean's context.
// Otherwise, forceDestroyBean() will mark that tx for rollback,
// which could incorrectly rollback a client-propagated transaction.
sc.setTransaction(null);
forceDestroyBean(sc);
// The bean has been detroyed so just skip any remaining processing.
return;
}
}
if (tx == null || tx.getStatus() == Status.STATUS_NO_TRANSACTION) {
// container.afterCompletion() was already called.
if (sc.getState() != BeanState.READY) {
if (sc.isAfterCompletionDelayed()) {
// ejb.afterCompletion was not called yet
// because of container.afterCompletion may have
// been called concurrently with this invocation.
logTraceInfo(inv, sc, "Calling delayed afterCompletion");
callEjbAfterCompletion(sc, sc.getCompletedTxStatus());
}
if (sc.getState() != BeanState.DESTROYED) {
// callEjbAfterCompletion could make state as DESTROYED
sc.setState(BeanState.READY);
handleEndOfMethodCheckpoint(sc, inv);
}
}
if ((sc.getState() != BeanState.DESTROYED) && isHAEnabled) {
syncClientVersion(inv, sc);
}
} else {
if ((sc.getState() != BeanState.DESTROYED) && isHAEnabled) {
syncClientVersion(inv, sc);
}
sc.setState(BeanState.INCOMPLETE_TX);
logTraceInfo(inv, sc, "Marking state == INCOMPLETE_TX");
}
} catch (SystemException ex) {
throw new EJBException(ex);
} finally {
releaseSFSBSerializedLock(inv, sc);
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbRemovalInfo in project Payara by payara.
the class EjbSessionNode method writeDescriptor.
@Override
public Node writeDescriptor(Node parent, String nodeName, EjbSessionDescriptor ejbDesc) {
Node ejbNode = super.writeDescriptor(parent, nodeName, ejbDesc);
writeDisplayableComponentInfo(ejbNode, ejbDesc);
writeCommonHeaderEjbDescriptor(ejbNode, ejbDesc);
appendTextChild(ejbNode, EjbTagNames.SESSION_TYPE, ejbDesc.getSessionType());
if (ejbDesc.hasStatefulTimeout()) {
TimeoutValueNode timeoutValueNode = new TimeoutValueNode();
TimeoutValueDescriptor timeoutDesc = new TimeoutValueDescriptor();
timeoutDesc.setValue(ejbDesc.getStatefulTimeoutValue());
timeoutDesc.setUnit(ejbDesc.getStatefulTimeoutUnit());
timeoutValueNode.writeDescriptor(ejbNode, EjbTagNames.STATEFUL_TIMEOUT, timeoutDesc);
}
MethodNode methodNode = new MethodNode();
if (ejbDesc.isTimedObject()) {
if (ejbDesc.getEjbTimeoutMethod() != null) {
methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.TIMEOUT_METHOD, ejbDesc.getEjbTimeoutMethod());
}
for (ScheduledTimerDescriptor timerDesc : ejbDesc.getScheduledTimerDescriptors()) {
ScheduledTimerNode timerNode = new ScheduledTimerNode();
timerNode.writeDescriptor(ejbNode, EjbTagNames.TIMER, timerDesc);
}
}
if (ejbDesc.isSingleton()) {
appendTextChild(ejbNode, EjbTagNames.INIT_ON_STARTUP, Boolean.toString(ejbDesc.getInitOnStartup()));
}
if (!ejbDesc.isStateless()) {
appendTextChild(ejbNode, EjbTagNames.CONCURRENCY_MANAGEMENT_TYPE, ejbDesc.getConcurrencyManagementType().toString());
}
for (EjbSessionDescriptor.AccessTimeoutHolder next : ejbDesc.getAccessTimeoutInfo()) {
ConcurrentMethodDescriptor cDesc = new ConcurrentMethodDescriptor();
cDesc.setConcurrentMethod(next.method);
TimeoutValueDescriptor timeoutDesc = new TimeoutValueDescriptor();
timeoutDesc.setValue(next.value);
timeoutDesc.setUnit(next.unit);
cDesc.setAccessTimeout(timeoutDesc);
ConcurrentMethodNode cNode = new ConcurrentMethodNode();
cNode.writeDescriptor(ejbNode, EjbTagNames.CONCURRENT_METHOD, cDesc);
}
for (MethodDescriptor nextReadLock : ejbDesc.getReadLockMethods()) {
ConcurrentMethodDescriptor cDesc = new ConcurrentMethodDescriptor();
cDesc.setConcurrentMethod(nextReadLock);
cDesc.setWriteLock(false);
ConcurrentMethodNode cNode = new ConcurrentMethodNode();
cNode.writeDescriptor(ejbNode, EjbTagNames.CONCURRENT_METHOD, cDesc);
}
if (ejbDesc.hasDependsOn()) {
Node dependsOnNode = appendChild(ejbNode, EjbTagNames.DEPENDS_ON);
for (String depend : ejbDesc.getDependsOn()) {
appendTextChild(dependsOnNode, EjbTagNames.EJB_NAME, depend);
}
}
if (ejbDesc.hasInitMethods()) {
EjbInitNode initNode = new EjbInitNode();
for (EjbInitInfo next : ejbDesc.getInitMethods()) {
initNode.writeDescriptor(ejbNode, EjbTagNames.INIT_METHOD, next);
}
}
if (ejbDesc.hasRemoveMethods()) {
EjbRemoveNode removeNode = new EjbRemoveNode();
for (EjbRemovalInfo next : ejbDesc.getAllRemovalInfo()) {
removeNode.writeDescriptor(ejbNode, EjbTagNames.REMOVE_METHOD, next);
}
}
for (MethodDescriptor nextDesc : ejbDesc.getAsynchronousMethods()) {
methodNode.writeDescriptor(ejbNode, EjbTagNames.ASYNC_METHOD, nextDesc, ejbDesc.getName());
}
appendTextChild(ejbNode, EjbTagNames.TRANSACTION_TYPE, ejbDesc.getTransactionType());
MethodDescriptor afterBeginMethod = ejbDesc.getAfterBeginMethod();
if (afterBeginMethod != null) {
methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.AFTER_BEGIN_METHOD, afterBeginMethod);
}
MethodDescriptor beforeCompletionMethod = ejbDesc.getBeforeCompletionMethod();
if (beforeCompletionMethod != null) {
methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.BEFORE_COMPLETION_METHOD, beforeCompletionMethod);
}
MethodDescriptor afterCompletionMethod = ejbDesc.getAfterCompletionMethod();
if (afterCompletionMethod != null) {
methodNode.writeJavaMethodDescriptor(ejbNode, EjbTagNames.AFTER_COMPLETION_METHOD, afterCompletionMethod);
}
// around-invoke-method
writeAroundInvokeDescriptors(ejbNode, ejbDesc.getAroundInvokeDescriptors().iterator());
// around-timeout-method
writeAroundTimeoutDescriptors(ejbNode, ejbDesc.getAroundTimeoutDescriptors().iterator());
// env-entry*
writeEnvEntryDescriptors(ejbNode, ejbDesc.getEnvironmentProperties().iterator());
// ejb-ref * and ejb-local-ref*
writeEjbReferenceDescriptors(ejbNode, ejbDesc.getEjbReferenceDescriptors().iterator());
// service-ref*
writeServiceReferenceDescriptors(ejbNode, ejbDesc.getServiceReferenceDescriptors().iterator());
// resource-ref*
writeResourceRefDescriptors(ejbNode, ejbDesc.getResourceReferenceDescriptors().iterator());
// resource-env-ref*
writeResourceEnvRefDescriptors(ejbNode, ejbDesc.getResourceEnvReferenceDescriptors().iterator());
// message-destination-ref*
writeMessageDestinationRefDescriptors(ejbNode, ejbDesc.getMessageDestinationReferenceDescriptors().iterator());
// persistence-context-ref*
writeEntityManagerReferenceDescriptors(ejbNode, ejbDesc.getEntityManagerReferenceDescriptors().iterator());
// persistence-unit-ref*
writeEntityManagerFactoryReferenceDescriptors(ejbNode, ejbDesc.getEntityManagerFactoryReferenceDescriptors().iterator());
// post-construct
writeLifeCycleCallbackDescriptors(ejbNode, TagNames.POST_CONSTRUCT, ejbDesc.getPostConstructDescriptors());
// pre-destroy
writeLifeCycleCallbackDescriptors(ejbNode, TagNames.PRE_DESTROY, ejbDesc.getPreDestroyDescriptors());
// all descriptors (includes DSD, MSD, JMSCFD, JMSDD,AOD, CFD)*
writeResourceDescriptors(ejbNode, ejbDesc.getAllResourcesDescriptors().iterator());
// post-activate-method
writeLifeCycleCallbackDescriptors(ejbNode, EjbTagNames.POST_ACTIVATE_METHOD, ejbDesc.getPostActivateDescriptors());
// pre-passivate-method
writeLifeCycleCallbackDescriptors(ejbNode, EjbTagNames.PRE_PASSIVATE_METHOD, ejbDesc.getPrePassivateDescriptors());
// security-role-ref*
writeRoleReferenceDescriptors(ejbNode, ejbDesc.getRoleReferences().iterator());
// security-identity
writeSecurityIdentityDescriptor(ejbNode, ejbDesc);
// passivation-capable
if (ejbDesc.isStateful()) {
appendTextChild(ejbNode, EjbTagNames.PASSIVATION_CAPABLE, Boolean.toString(ejbDesc.isPassivationCapable()));
}
return ejbNode;
}
use of org.glassfish.ejb.deployment.descriptor.EjbRemovalInfo in project Payara by payara.
the class AsynchronousTask method postInvokeTx.
@Override
protected void postInvokeTx(EjbInvocation inv) throws Exception {
// If this was an invocation of a remove-method
if (inv.invocationInfo.removalInfo != null) {
InvocationInfo invInfo = inv.invocationInfo;
EjbRemovalInfo removeInfo = invInfo.removalInfo;
if (retainAfterRemoveMethod(inv, removeInfo)) {
// Do nothing
} else {
// If there is a tx, remove bean from ContainerSynch so it
// won't receive any SessionSynchronization callbacks.
// We delay the PreDestroy callback and instance destruction
// until releaseContext so that PreDestroy won't run within
// the business method's tx.
SessionContextImpl sc = (SessionContextImpl) inv.context;
Transaction tx = sc.getTransaction();
if (tx != null) {
ejbContainerUtilImpl.getContainerSync(tx).removeBean(sc);
}
}
}
super.postInvokeTx(inv);
}
use of org.glassfish.ejb.deployment.descriptor.EjbRemovalInfo in project Payara by payara.
the class RemoveHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
Remove remove = (Remove) ainfo.getAnnotation();
for (EjbContext next : ejbContexts) {
EjbSessionDescriptor sessionDescriptor = (EjbSessionDescriptor) next.getDescriptor();
Method m = (Method) ainfo.getAnnotatedElement();
MethodDescriptor removeMethod = new MethodDescriptor(m, MethodDescriptor.EJB_BEAN);
EjbRemovalInfo removalInfo = sessionDescriptor.getRemovalInfo(removeMethod);
if (removalInfo == null) {
// if this element is not defined in xml
// use all information from annotation
removalInfo = new EjbRemovalInfo();
removalInfo.setRemoveMethod(removeMethod);
removalInfo.setRetainIfException(remove.retainIfException());
sessionDescriptor.addRemoveMethod(removalInfo);
} else {
// is not defined in xml
if (!removalInfo.isRetainIfExceptionSet()) {
removalInfo.setRetainIfException(remove.retainIfException());
}
}
}
return getDefaultProcessedResult();
}
Aggregations