/** * Returns the string STATELESS or STATEFUL according as to whether * the bean is stateless or stateful. **/ public String getSessionType() { if (this.isStateless()) { return STATELESS; } else if( isStateful() ){ return STATEFUL; } else { return SINGLETON; } }
/** * Indicates if the EJB is stateful * * @return True if the bean is stateful, false otherwise */ public boolean isStateful() { return (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE) && ((EjbSessionDescriptor) ejbDesc).isStateful()); }
public boolean isPassivationCapable() { if ( ejbDesc instanceof EjbSessionDescriptor ) { EjbSessionDescriptor ejbSessionDescriptor = ( EjbSessionDescriptor ) ejbDesc; if ( ejbSessionDescriptor.isStateful() && ejbSessionDescriptor.isPassivationCapable() ) { return true; } } return false; }
/** * Check if the given EjbDescriptor matches the given Annotation. * @param ejbDesc * @param annotation * @return boolean check for validity of EjbDescriptor */ protected boolean isValidEjbDescriptor(EjbDescriptor ejbDesc, Annotation annotation) { boolean isValid = EjbSessionDescriptor.TYPE.equals(ejbDesc.getType()); if( isValid ) { EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc; // Only check specific session-bean type if it's set in the descriptor. // Otherwise it was probably populated with a sparse ejb-jar.xml and // we'll set the type later. if( sessionDesc.isSessionTypeSet() && !sessionDesc.isStateful() ) { isValid = false; } } return isValid; }
/** * Get the remove methods of the EJB * * @return An iterator over the remove methods */ public Collection<Method> getRemoveMethods() { Set<Method> removeMethods = new HashSet<Method>(); if( ejbDesc.getType().equals(EjbSessionDescriptor.TYPE) ) { EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc; if( sessionDesc.isStateful() && sessionDesc.hasRemoveMethods() ) { for(MethodDescriptor mDesc : sessionDesc.getRemoveMethodDescriptors()) { Method m = mDesc.getMethod(ejbDesc); if( m == null ) { throw new IllegalStateException("Can't resolve remove method " + mDesc + " For EJB " + sessionDesc.getName()); } removeMethods.add(m); } } } return removeMethods; }
SessionContextImpl(Object ejb, BaseContainer container) { super(ejb, container); EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) getContainer().getEjbDescriptor(); isStateless = sessionDesc.isStateless(); isStateful = sessionDesc.isStateful(); if( isStateful ) { initializeStatefulWriteLock(); } }
SessionContextImpl(Object ejb, BaseContainer container) { super(ejb, container); EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) getContainer().getEjbDescriptor(); isStateless = sessionDesc.isStateless(); isStateful = sessionDesc.isStateful(); if( isStateful ) { initializeStatefulWriteLock(); } }
public void remove(Object ejbRef) { EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef); if( localObjectImpl == null ) { throw new UnsupportedOperationException("Invalid ejb ref"); } Container container = localObjectImpl.getContainer(); EjbDescriptor ejbDesc = container.getEjbDescriptor(); boolean isStatefulBean = false; if( ejbDesc.getType().equals(EjbSessionDescriptor.TYPE) ) { EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc; isStatefulBean = sessionDesc.isStateful(); } if( !isStatefulBean ) { // TODO 299 impl may incorrectly call this for stateless/singleton // beans. Until it's fixed just treat it as a no-op. Otherwise, any app acquiring // stateless/singleton references via 299 could fail until bug is fixed. return; // TODO reenable this after bug is fixed //throw new UnsupportedOperationException("ejbRef for ejb " + // ejbDesc.getName() + " is not a stateful bean "); } try { localObjectImpl.remove(); } catch(EJBException e) { _logger.log(Level.FINE, "EJBException during remove. ", e); } catch(javax.ejb.RemoveException re) { throw new NoSuchEJBException(re.getMessage(), re); } }
public boolean isRemoved(Object ejbRef) { EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef); if( localObjectImpl == null ) { throw new UnsupportedOperationException("Invalid ejb ref"); } Container container = localObjectImpl.getContainer(); EjbDescriptor ejbDesc = container.getEjbDescriptor(); boolean isStatefulBean = false; if( ejbDesc.getType().equals(EjbSessionDescriptor.TYPE) ) { EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc; isStatefulBean = sessionDesc.isStateful(); } if( !isStatefulBean ) { // TODO 299 impl is incorrectly calling isRemoved for stateless/singleton // beans. Until it's fixed just return false. Otherwise, any app acquiring // stateless/singleton references via 299 will fail until bug is fixed. return false; // TODO reenable this per SessionObjectReference.isRemoved SPI //throw new UnsupportedOperationException("ejbRef for ejb " + // ejbDesc.getName() + " is not a stateful bean "); } boolean removed = false; try { ((BaseContainer)container).checkExists(localObjectImpl); } catch(Exception e) { removed = true; } return removed; }
public Vector getPossibleTransactionAttributes() { Vector txAttributes = super.getPossibleTransactionAttributes(); // Session beans that implement SessionSynchronization interface // have a limited set of possible transaction attributes. if( isStateful() ) { try { EjbBundleDescriptor ejbBundle = getEjbBundleDescriptor(); ClassLoader classLoader = ejbBundle.getClassLoader(); Class ejbClass = classLoader.loadClass(getEjbClassName()); AnnotationTypesProvider provider = Globals.getDefaultHabitat().getComponent(AnnotationTypesProvider.class, "EJB"); if (provider!=null) { Class sessionSynchClass = provider.getType("javax.ejb.SessionSynchronization"); if( sessionSynchClass.isAssignableFrom(ejbClass) ) { txAttributes = new Vector(); txAttributes.add(new ContainerTransaction (ContainerTransaction.REQUIRED, "")); txAttributes.add(new ContainerTransaction (ContainerTransaction.REQUIRES_NEW, "")); txAttributes.add(new ContainerTransaction (ContainerTransaction.MANDATORY, "")); } } } catch(Exception e) { // Don't treat this as a fatal error. Just return full // set of possible transaction attributes. } } return txAttributes; }
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException { StatefulTimeout stAn = (StatefulTimeout) ainfo.getAnnotation(); for (EjbContext ejbContext : ejbContexts) { EjbDescriptor ejbDesc = ejbContext.getDescriptor(); if( ejbDesc instanceof EjbSessionDescriptor ) { EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc; if( sessionDesc.isStateful() ) { // override by xml if (!sessionDesc.hasStatefulTimeout()) { sessionDesc.setStatefulTimeout(stAn.value(), stAn.unit()); } } } } return getDefaultProcessedResult(); }
if (ejbDescriptor instanceof EjbSessionDescriptor) { statefulSessionBean = ((EjbSessionDescriptor) ejbDescriptor).isStateful();
container = new StatelessSessionContainer(ejbDescriptor, loader); } else if( sd.isStateful() ) { StatefulContainerBuilder sfsbBuilder = habitat.getComponent( StatefulContainerBuilder.class);