/** * 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; }
/** * 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; } }
private String getDefaultGlobalJndiName(EjbDescriptor<?> ejbDesc) { EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ((EjbDescriptorImpl<?>) ejbDesc).getEjbDescriptor(); String clientView = null; if( sessionDesc.isLocalBean() ) { clientView = sessionDesc.getEjbClassName(); } else if( sessionDesc.getLocalBusinessClassNames().size() >= 1) { clientView = sessionDesc.getLocalBusinessClassNames().iterator().next(); } else if( sessionDesc.getRemoteBusinessClassNames().size() >= 1) { clientView = sessionDesc.getRemoteBusinessClassNames().iterator().next(); } return (clientView != null) ? sessionDesc.getPortableJndiName(clientView) : null; }
public boolean isPassivationCapable() { if ( ejbDesc instanceof EjbSessionDescriptor ) { EjbSessionDescriptor ejbSessionDescriptor = ( EjbSessionDescriptor ) ejbDesc; if ( ejbSessionDescriptor.isStateful() && ejbSessionDescriptor.isPassivationCapable() ) { return true; } } return false; }
writeDisplayableComponentInfo(ejbNode, descriptor); writeCommonHeaderEjbDescriptor(ejbNode, ejbDesc); appendTextChild(ejbNode, EjbTagNames.SESSION_TYPE, ejbDesc.getSessionType()); if( ejbDesc.hasStatefulTimeout() ) { timeoutDesc.setValue(ejbDesc.getStatefulTimeoutValue()); timeoutDesc.setUnit(ejbDesc.getStatefulTimeoutUnit()); timeoutValueNode.writeDescriptor(ejbNode, EjbTagNames.STATEFUL_TIMEOUT, timeoutDesc); if( ejbDesc.isTimedObject() ) { if (ejbDesc.getEjbTimeoutMethod() != null) { 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()) {
EjbSessionDescriptor sd = (EjbSessionDescriptor) ejbDescriptor; if( !sd.isSessionTypeSet() ) { throw new RuntimeException("Invalid ejb Descriptor. Session type not set for " + " ejb " + sd.getName() + " : " + sd); if (sd.isSingleton()) { isSingleton = true; } else { isStatelessSession = sd.isStateless(); isStatefulSession = !isStatelessSession; if ( sd.getTransactionType().equals("Bean") ) { isBeanManagedTran = true; } else { hasAsynchronousInvocations = sd.hasAsynchronousMethods();
if( sessionDesc.hasDependsOn()) { if( !sessionDesc.isSingleton() ) { throw new RuntimeException("Illegal usage of DependsOn for EJB " + ejb.getName() + ". DependsOn is only supported for Singleton beans"); String[] dependsOn = sessionDesc.getDependsOn(); for(String next : dependsOn) { Application app = sessionDesc.getEjbBundleDescriptor().getApplication(); String relativeJarPath = next.substring(0, indexOfHash); BundleDescriptor bundle = app.getRelativeBundle(sessionDesc.getEjbBundleDescriptor(), relativeJarPath); " for Singleton " + sessionDesc.getName());
void doStartup(EjbApplication ejbApp) { Collection<EjbDescriptor> ejbs = ejbApp.getEjbBundleDescriptor().getEjbs(); int descSz = ejbs.size(); for (EjbDescriptor desc : ejbs) { if (desc instanceof EjbSessionDescriptor) { EjbSessionDescriptor sdesc = (EjbSessionDescriptor) desc; if ((sdesc.isSingleton())) { if (sdesc.getInitOnStartup()) { String normalizedSingletonName = normalizeSingletonName(sdesc.getName(), sdesc); initializeSingleton(name2Container.get(normalizedSingletonName)); } } } } }
void addSingletonContainer(EjbApplication ejbApp, AbstractSingletonContainer c) { c.setSingletonLifeCycleManager(this); EjbSessionDescriptor sdesc = (EjbSessionDescriptor) c.getEjbDescriptor(); String modName = sdesc.getEjbBundleDescriptor().getName(); //System.out.println("BundleName: " + modName); String src = normalizeSingletonName(sdesc.getName(), sdesc); String[] depends = sdesc.getDependsOn(); String[] newDepends = new String[depends.length]; StringBuilder sb = new StringBuilder("Partial order of dependent(s). " + src + " => {"); for(int i=0; i < depends.length; i++) { newDepends[i] = normalizeSingletonName(depends[i], sdesc); sb.append(newDepends[i] + " "); } sb.append("}"); if (_logger.isLoggable(Level.FINE)) { _logger.log(Level.FINE, sb.toString()); } this.addDependency(src, newDepends); name2Container.put(src, c); name2EjbApp.put(src, ejbApp); }
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; }
private String normalizeSingletonName(String origName, EjbSessionDescriptor sessionDesc) { String normalizedName = origName; boolean fullyQualified = origName.contains("#"); Application app = sessionDesc.getEjbBundleDescriptor().getApplication(); if (fullyQualified) { int indexOfHash = origName.indexOf("#"); String ejbName = origName.substring(indexOfHash + 1); String relativeJarPath = origName.substring(0, indexOfHash); BundleDescriptor bundle = app.getRelativeBundle(sessionDesc.getEjbBundleDescriptor(), relativeJarPath); if (bundle == null) { throw new IllegalStateException("Invalid @DependOn value = " + origName + " for Singleton " + sessionDesc.getName()); } normalizedName = bundle.getModuleDescriptor().getArchiveUri() + "#" + ejbName; } else { normalizedName = sessionDesc.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri() + "#" + origName; } return normalizedName; }
protected EJBHomeInvocationHandler(EjbDescriptor ejbDescriptor, Class homeIntfClass) throws Exception { if( ejbDescriptor instanceof EjbSessionDescriptor ) { isStatelessSession_ = ((EjbSessionDescriptor)ejbDescriptor).isStateless(); } else { isStatelessSession_ = false; } homeIntfClass_ = homeIntfClass; // NOTE : Container is not set on super-class until after // constructor is called. }
if ( sd.isStateless() ) { if ((ejbDescriptor.getLocalClassName() != null) && (ejbDescriptor.getLocalBusinessClassNames() container = new StatelessSessionContainer(ejbDescriptor, loader); } else if( sd.isStateful() ) { StatefulContainerBuilder sfsbBuilder = habitat.getComponent( StatefulContainerBuilder.class); } else { if (sd.hasContainerManagedConcurrency() ) { container = new CMCSingletonContainer(ejbDescriptor, loader); } else {
Set<String> localNames = sessionDesc.getLocalBusinessClassNames(); if( sessionDesc.isLocalBean() ) { localNames.add(sessionDesc.getEjbClassName()); try { Class<?> localClass = sessionDesc.getEjbBundleDescriptor().getClassLoader().loadClass(local); @SuppressWarnings({ "rawtypes", "unchecked" }) BusinessInterfaceDescriptor<?> busIntfDesc =
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(); }
/** * 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()); }
/** * Validates @StatefulTimeout or <stateful-timeout> values. Any value less than -1 * is invalid. */ private void validateStatefulTimeout(EjbDescriptor ejb) { if(ejb instanceof EjbSessionDescriptor) { EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejb; Long statefulTimeoutValue = sessionDesc.getStatefulTimeoutValue(); if(statefulTimeoutValue != null && statefulTimeoutValue < -1) { throw new IllegalArgumentException(localStrings.getLocalString( "enterprise.deployment.invalid_stateful_timeout_value", "Invalid value [{0}] for @StatefulTimeout or <stateful-timeout> element in EJB [{1}]. Values less than -1 are not valid.", new Object[] {statefulTimeoutValue, sessionDesc.getName()})); } } }
LockType lockType = lockAnn.value(); if( !singletonDesc.isSingleton() ) { throw new AnnotationProcessorException("@Lock is only permitted for " + "singleton session beans"); MethodDescriptor newMethodDesc = new MethodDescriptor(annMethod); if( lockAnn.value() == LockType.WRITE) { singletonDesc.addWriteLockMethod(newMethodDesc); } else { singletonDesc.addReadLockMethod(newMethodDesc);
public void addConcurrentMethodFromXml(ConcurrentMethodDescriptor concMethod) { // .xml must contain a method. However, both READ/WRITE lock metadata // and access timeout are optional. MethodDescriptor methodDesc = concMethod.getConcurrentMethod(); if( concMethod.hasLockMetadata()) { if( concMethod.isWriteLocked()) { addWriteLockMethod(methodDesc); } else { addReadLockMethod(methodDesc); } } if( concMethod.hasAccessTimeout() ) { this.addAccessTimeoutMethod(methodDesc, concMethod.getAccessTimeoutValue(), concMethod.getAccessTimeoutUnit()); } }
throws Exception { String homeIntfName = local ? descriptor.getLocalHomeClassName() : descriptor.getHomeClassName(); ClassLoader cl = descriptor.getEjbBundleDescriptor().getClassLoader(); initInfo.setCreateMethod(createMethodDescriptor); descriptor.addInitMethod(initInfo);