<commit_before>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file 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.weld.bootstrap;

import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;

import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType;
import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.ejb.EjbDescriptors;
import org.jboss.weld.ejb.InternalEjbDescriptor;
import org.jboss.weld.executor.IterativeWorkerTaskFactory;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.manager.api.ExecutorServices;
import org.jboss.weld.util.collections.ConcurrentHashSetSupplier;
import org.jboss.weld.util.reflection.Reflections;

import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;

/**
 * BeanDeployer that processes some of the deployment tasks in parallel. A threadsafe instance of
 * {@link BeanDeployerEnvironment} is used.
 *
 * @author <NAME>
 *
 */
public class ConcurrentBeanDeployer extends BeanDeployer {

    private final ExecutorServices executor;
    private final ContainerLifecycleEventPreloader preloader;

    public ConcurrentBeanDeployer(BeanManagerImpl manager, EjbDescriptors ejbDescriptors, ServiceRegistry services) {
        super(manager, ejbDescriptors, services, BeanDeployerEnvironment.newConcurrentEnvironment(ejbDescriptors, manager));
        this.executor = services.get(ExecutorServices.class);
        this.preloader = services.get(ContainerLifecycleEventPreloader.class);
        if (this.preloader == null) {
            throw new IllegalArgumentException(ContainerLifecycleEventPreloader.class.getName() + " is null");
        }
    }

    @Override
    protected void preloadContainerLifecycleEvent(Class<?> eventRawType, Type... typeParameters) {
        preloader.preloadContainerLifecycleEvent(getManager(), eventRawType, typeParameters);
    }

    @Override
    public BeanDeployer addClasses(Iterable<String> c) {
        executor.invokeAllAndCheckForExceptions(new IterativeWorkerTaskFactory<String>(c) {
            protected void doWork(String className) {
                addClass(className);
            }
        });
        return this;
    }

//    @Override
//    public void processAnnotatedTypes() {
//        executor.invokeAllAndCheckForExceptions(new IterativeWorkerTaskFactory<AnnotatedType<?>>(getEnvironment().getAnnotatedTypes()) {
//            protected void doWork(AnnotatedType<?> annotatedType) {
//                // fire event
//                boolean synthetic = getEnvironment().getAnnotatedTypeSource(annotatedType) != null;
//                ProcessAnnotatedTypeImpl<?> event;
//                if (synthetic) {
//                    event = ProcessAnnotatedTypeFactory.create(getManager(), annotatedType, getEnvironment().getAnnotatedTypeSource(annotatedType));
//                } else {
//                    event = ProcessAnnotatedTypeFactory.create(getManager(), annotatedType);
//                }
//                event.fire();
//                // process the result
//                if (event.isVeto()) {
//                    getEnvironment().vetoAnnotatedType(annotatedType);
//                } else {
//                    boolean dirty = event.isDirty();
//                    if (dirty) {
//                        getEnvironment().removeAnnotatedType(annotatedType); // remove the original class
//                        AnnotatedType<?> modifiedType = event.getAnnotatedType();
//                        if (modifiedType instanceof SlimAnnotatedType<?>) {
//                            annotatedType = modifiedType;
//                        } else {
//                            annotatedType = classTransformer.getAnnotatedType(modifiedType);
//                        }
//                    }
//
//                    // vetoed due to @Veto or @Requires
//                    boolean vetoed = Beans.isVetoed(annotatedType);
//
//                    if (dirty && !vetoed) {
//                        getEnvironment().addAnnotatedType(annotatedType); // add a replacement for the removed class
//                    }
//                    if (!dirty && vetoed) {
//                        getEnvironment().vetoAnnotatedType(annotatedType);
//                    }
//                }
//            }
//        });
//    }
//
//    @Override
//    protected void processBeanAttributes(Collection<? extends AbstractBean<?, ?>> beans) {
//        executor.invokeAllAndCheckForExceptions(new IterativeWorkerTaskFactory<AbstractBean<?, ?>>(beans) {
//            protected void doWork(AbstractBean<?, ?> bean) {
//                // fire ProcessBeanAttributes for class beans
//                boolean vetoed = fireProcessBeanAttributes(bean);
//                if (vetoed) {
//                    if (bean.isSpecializing()) {
//                        BeansClosure.getClosure(getManager()).removeSpecialized(bean.getSpecializedBean());
//                        getQueue().add(bean.getSpecializedBean());
//                    }
//                    getEnvironment().vetoBean(bean);
//                } else {
//                    // now that we know that the bean won't be vetoed, it's the right time to register @New injection points
//                    getEnvironment().addNewBeansFromInjectionPoints(bean);
//                }
//            }
//        });
//    }

    @Override
    public void createClassBeans() {
        final Multimap<Class<?>, AnnotatedType<?>> otherWeldClasses = Multimaps.newSetMultimap(new ConcurrentHashMap<Class<?>, Collection<AnnotatedType<?>>>(),<commit_msg>Do not fire ContainerLifecycleEvents from multiple threads (Observer resolution is multithreaded already due to ContainerLifecycleEventPreloader)<commit_after>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file 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.weld.bootstrap;

import java.lang.reflect.Type;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;

import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType;
import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.ejb.EjbDescriptors;
import org.jboss.weld.ejb.InternalEjbDescriptor;
import org.jboss.weld.executor.IterativeWorkerTaskFactory;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.manager.api.ExecutorServices;
import org.jboss.weld.util.collections.ConcurrentHashSetSupplier;
import org.jboss.weld.util.reflection.Reflections;

import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;

/**
 * BeanDeployer that processes some of the deployment tasks in parallel. A threadsafe instance of
 * {@link BeanDeployerEnvironment} is used.
 *
 * @author <NAME>
 *
 */
public class ConcurrentBeanDeployer extends BeanDeployer {

    private final ExecutorServices executor;
    private final ContainerLifecycleEventPreloader preloader;

    public ConcurrentBeanDeployer(BeanManagerImpl manager, EjbDescriptors ejbDescriptors, ServiceRegistry services) {
        super(manager, ejbDescriptors, services, BeanDeployerEnvironment.newConcurrentEnvironment(ejbDescriptors, manager));
        this.executor = services.get(ExecutorServices.class);
        this.preloader = services.get(ContainerLifecycleEventPreloader.class);
        if (this.preloader == null) {
            throw new IllegalArgumentException(ContainerLifecycleEventPreloader.class.getName() + " is null");
        }
    }

    @Override
    protected void preloadContainerLifecycleEvent(Class<?> eventRawType, Type... typeParameters) {
        preloader.preloadContainerLifecycleEvent(getManager(), eventRawType, typeParameters);
    }

    @Override
    public BeanDeployer addClasses(Iterable<String> c) {
        executor.invokeAllAndCheckForExceptions(new IterativeWorkerTaskFactory<String>(c) {
            protected void doWork(String className) {
                addClass(className);
            }
        });
        return this;
    }

    @Override
    public void createClassBeans() {
        final Multimap<Class<?>, AnnotatedType<?>> otherWeldClasses = Multimaps.newSetMultimap(new ConcurrentHashMap<Class<?>, Collection<AnnotatedType<?>>>(),
{'fraction_non_alphanumeric': 0.0957426498663612, 'fraction_numerical': 0.0032455135547919053, 'mean_word_length': 2.9166355140186915, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6441453', 'n_tokens_mistral': 2858, 'n_tokens_neox': 2746, 'n_words': 721}