Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, Red Hat Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.as.ejb3.deployment.processors.merging;
 
 import java.util.List;
 import java.util.Map;
 
 
 import  org.jboss.invocation.proxy.MethodIdentifier;
 import  org.jboss.metadata.ejb.spec.AsyncMethodMetaData;
 import  org.jboss.metadata.ejb.spec.AsyncMethodsMetaData;
 import  org.jboss.metadata.ejb.spec.SessionBean31MetaData;
 import  org.jboss.metadata.ejb.spec.SessionBeanMetaData;
 
 import static org.jboss.as.ejb3.EjbMessages.MESSAGES;
Merging processor that handles EJB async methods, and adds a configurator to configure any that are found.

Author(s):
Stuart Douglas
 
 
 
     public AsynchronousMergingProcessor(final ServiceName asynchronousThreadPoolService) {
         super(SessionBeanComponentDescription.class);
         this. = asynchronousThreadPoolService;
     }
 
     @Override
     protected void handleAnnotations(final DeploymentUnit deploymentUnitfinal EEApplicationClasses applicationClassesfinal DeploymentReflectionIndex deploymentReflectionIndexfinal Class<?> componentClassfinal SessionBeanComponentDescription descriptionthrows DeploymentUnitProcessingException {
         final RuntimeAnnotationInformation<Booleandata = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClassapplicationClassesdeploymentReflectionIndexAsynchronous.class);
         for (final Map.Entry<StringList<Boolean>> entry : data.getClassAnnotations().entrySet()) {
             if (!entry.getValue().isEmpty()) {
                 description.addAsynchronousClass(entry.getKey());
             }
         }
 
         for (final Map.Entry<MethodList<Boolean>> entry : data.getMethodAnnotations().entrySet()) {
             if (!entry.getValue().isEmpty()) {
                 description.addAsynchronousMethod(MethodIdentifier.getIdentifierForMethod(entry.getKey()));
             }
         }
 
     }
 
     @Override
     protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnitfinal DeploymentReflectionIndex deploymentReflectionIndexfinal Class<?> componentClassfinal SessionBeanComponentDescription descriptionthrows DeploymentUnitProcessingException {
         final SessionBeanMetaData data = description.getDescriptorData();
         if (data != null) {
             if (data instanceof SessionBean31MetaData) {
                 final SessionBean31MetaData sessionBeanData = (SessionBean31MetaData) data;
                final AsyncMethodsMetaData async = sessionBeanData.getAsyncMethods();
                if (async != null) {
                    for (AsyncMethodMetaData method : async) {
                        final Collection<Methodmethods = MethodResolutionUtils.resolveMethods(method.getMethodName(), method.getMethodParams(), componentClassdeploymentReflectionIndex);
                        for(final Method m : methods ) {
                            description.addAsynchronousMethod(MethodIdentifier.getIdentifierForMethod(m));
                        }
                    }
                }
            }
        }
        if (!description.getAsynchronousClasses().isEmpty() ||
                !description.getAsynchronousMethods().isEmpty()) {
            //setup a dependency on the executor service
            description.getConfigurators().add(new ComponentConfigurator() {
                @Override
                public void configure(final DeploymentPhaseContext contextfinal ComponentDescription descriptionfinal ComponentConfiguration configurationthrows DeploymentUnitProcessingException {
                    configuration.getCreateDependencies().add(new DependencyConfigurator<SessionBeanComponentCreateService>() {
                        @Override
                        public void configureDependency(final ServiceBuilder<?> serviceBuilderfinal SessionBeanComponentCreateService servicethrows DeploymentUnitProcessingException {
                            serviceBuilder.addDependency(ExecutorService.classservice.getAsyncExecutorService());
                        }
                    });
                }
            });
            for (final ViewDescription view : description.getViews()) {
                final EJBViewDescription ejbView = (EJBViewDescriptionview;
                ejbView.getConfigurators().add(new ViewConfigurator() {
                    @Override
                    public void configure(final DeploymentPhaseContext contextfinal ComponentConfiguration componentConfigurationfinal ViewDescription descriptionfinal ViewConfiguration configurationthrows DeploymentUnitProcessingException {
                        final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescriptioncomponentConfiguration.getComponentDescription();
                        for (final Method method : configuration.getProxyFactory().getCachedMethods()) {
                            //we need the component method to get the correct declaring class
                            final Method componentMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndexcomponentClassmethod);
                            if (componentMethod != null) {
                                if (componentDescription.getAsynchronousClasses().contains(componentMethod.getDeclaringClass().getName())) {
                                    addAsyncInterceptor(configurationmethod);
                                    configuration.addAsyncMethod(method);
                                } else {
                                    MethodIdentifier id = MethodIdentifier.getIdentifierForMethod(method);
                                    if (componentDescription.getAsynchronousMethods().contains(id)) {
                                        addAsyncInterceptor(configurationmethod);
                                        configuration.addAsyncMethod(method);
                                    }
                                }
                            }
                        }
                    }
                });
            }
        }
    }
    private static void addAsyncInterceptor(final ViewConfiguration configurationfinal Method methodthrows DeploymentUnitProcessingException {
        if (method.getReturnType().equals(void.class) || method.getReturnType().equals(Future.class)) {
        } else {
            throw .wrongReturnTypeForAsyncMethod(method);
        }
    }
New to GrepCode? Check out our FAQ X