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;
 
 import  org.jboss.ejb3.timerservice.spi.TimerServiceFactory;
 import  org.jboss.invocation.proxy.MethodIdentifier;
 
 import java.util.List;
 import java.util.Map;


Deployment processor that sets up the timer service for singletons and stateless session beans

Author(s):
Stuart Douglas
 
 
     private static final Logger logger = Logger.getLogger(TimerServiceDeploymentProcessor.class);
 
     private final int coreThreads;
     private final int maxThreads;
 
     private final boolean enabled;
 
     public TimerServiceDeploymentProcessor(final int coreThreadsfinal int maxThreadsboolean enabled) {
         this. = coreThreads;
         this. = maxThreads;
         this. = enabled;
     }
 
     @Override
     public void deploy(final DeploymentPhaseContext phaseContextthrows DeploymentUnitProcessingException {
         if(!) {
             return;
         }
         final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
         final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(.);
         final Module module = deploymentUnit.getAttachment(......);
         boolean timerServiceRequired = false;
 
         for (final ComponentDescription component : moduleDescription.getComponentDescriptions()) {
 
             if (component instanceof SingletonComponentDescription || component instanceof StatelessComponentDescription) {
                 timerServiceRequired = true;
                 .debug("Installing timer service for component " + component.getComponentName());
 
                component.getConfigurators().add(new ComponentConfigurator() {
                    @Override
                    public void configure(final DeploymentPhaseContext contextfinal ComponentDescription descriptionfinal ComponentConfiguration configurationthrows DeploymentUnitProcessingException {
                        final SessionBeanComponentDescription ejbComponentDescription = (SessionBeanComponentDescriptiondescription;
                        final DeploymentReflectionIndex deploymentReflectionIndex = context.getDeploymentUnit().getAttachment(......);
                        //First resolve the timer method and auto timer
                        Class<?> c = configuration.getComponentClass();
                        while (c != null && c != Object.class) {
                            final ClassReflectionIndex<?> index = deploymentReflectionIndex.getClassIndex(c);
                            //TimedObject takes precedence
                            Method method = null;
                            if (TimedObject.class.isAssignableFrom(configuration.getComponentClass())) {
                                method = index.getMethod(."ejbTimeout"javax.ejb.Timer.class);
                            } else if (ejbComponentDescription.getTimeoutMethod() == null && ejbComponentDescription.getTimeoutMethodIdentifier() != null) {
                                method = index.getMethod(ejbComponentDescription.getTimeoutMethodIdentifier());
                            } else {
                                break;
                            }
                            if (method != null) {
                                ejbComponentDescription.setTimeoutMethod(method);
                                break;
                            }
                            c = c.getSuperclass();
                        }
                        //now for the schedule methods
                        for (Map.Entry<MethodIdentifier, List<AutoTimer>> entry : ejbComponentDescription.getScheduleMethodIdentifiers().entrySet()) {
                            c = configuration.getComponentClass();
                            while (c != null && c != Object.class) {
                                final ClassReflectionIndex<?> index = deploymentReflectionIndex.getClassIndex(c);
                                final Method method = index.getMethod(entry.getKey());
                                if (method != null) {
                                    for (AutoTimer timer : entry.getValue()) {
                                        ejbComponentDescription.addScheduleMethod(methodtimer);
                                    }
                                    break;
                                }
                                c = c.getSuperclass();
                            }
                        }
                        //install the timer create service
                        final TimerServiceService service = new TimerServiceService(ejbComponentDescription.getScheduleMethods(), module.getClassLoader());
                        final ServiceName serviceName = component.getServiceName().append(.);
                        final ServiceBuilder<javax.ejb.TimerServicecreateBuilder = context.getServiceTarget().addService(serviceNameservice);
                        createBuilder.addDependency(deploymentUnit.getServiceName().append(.), TimerServiceFactory.classservice.getTimerServiceFactoryInjectedValue());
                        createBuilder.addDependency(component.getCreateServiceName(), EJBComponent.classservice.getEjbComponentInjectedValue());
                        createBuilder.install();
                        ejbComponentDescription.setTimerService(service);
                        //inject the timer service directly into the start service
                        configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
                            @Override
                            public void configureDependency(final ServiceBuilder<?> serviceBuilderfinal ComponentStartService servicethrows DeploymentUnitProcessingException {
                                serviceBuilder.addDependency(serviceName);
                            }
                        });
                    }
                });
            }
        }
        if (timerServiceRequired) {
            addTimerService(phaseContext.getServiceTarget(), deploymentUnitmodule);
        }
    }


    
Adds a service that creates the entity manager factory used by the timer service, and the timer service factory service

Parameters:
serviceTarget The service target to add the service to
    private void addTimerService(final ServiceTarget serviceTargetfinal DeploymentUnit deploymentUnitfinal Module module) {
        final String name;
        if(deploymentUnit.getParent() == null) {
            name = deploymentUnit.getName();
        } else {
            name = deploymentUnit.getParent().getName() + "--" + deploymentUnit.getName();
        }
        final TimerServiceFactoryService factoryService = new TimerServiceFactoryService(namemodule);
        final ServiceBuilder<TimerServiceFactory> factoryBuilder = serviceTarget.addService(deploymentUnit.getServiceName().append(.), factoryService);
        factoryBuilder.addDependency(.TransactionManager.classfactoryService.getTransactionManagerInjectedValue());
        factoryBuilder.addDependency(...String.classfactoryService.getPath());
        factoryBuilder.install();
    }
    @Override
    public void undeploy(final DeploymentUnit context) {
    }
New to GrepCode? Check out our FAQ X