Skip to content

Commit

Permalink
Merge pull request #3371 from smillidge/PAYARA-3216
Browse files Browse the repository at this point in the history
PAYARA-3216 Make Weld concurrent bean loading configurable
  • Loading branch information
Pandrex247 committed Nov 19, 2018
2 parents 5d266b2 + 1c57c59 commit 9a750f6
Show file tree
Hide file tree
Showing 16 changed files with 281 additions and 131 deletions.
6 changes: 6 additions & 0 deletions appserver/deployment/dol/pom.xml
Expand Up @@ -206,5 +206,11 @@
<artifactId>nucleus-resources</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fish.payara.payara-modules</groupId>
<artifactId>payara-executor-service</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
Expand Up @@ -44,6 +44,7 @@
import com.sun.enterprise.deployment.annotation.introspection.DefaultAnnotationScanner;
import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.deployment.util.DOLUtils;
import fish.payara.nucleus.executorservice.PayaraExecutorService;
import java.util.zip.ZipException;
import org.glassfish.apf.Scanner;
import org.glassfish.apf.impl.JavaEEScanner;
Expand All @@ -61,7 +62,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.LogRecord;
import java.util.concurrent.*;

import org.glassfish.logging.annotation.LogMessageInfo;

Expand All @@ -85,7 +85,8 @@ public abstract class ModuleScanner<T> extends JavaEEScanner implements Scanner<

private boolean needScanAnnotation = false;

private static ExecutorService executorService = null;
@Inject
PayaraExecutorService executorService;

private Set<String> entries = new HashSet<String>();

Expand Down Expand Up @@ -345,37 +346,12 @@ public Types getTypes() {
return classParser.getContext().getTypes();
}

protected synchronized ExecutorService getExecutorService() {
if (executorService != null) {
return executorService;
}

Runtime runtime = Runtime.getRuntime();
int nrOfProcessors = runtime.availableProcessors();

executorService = new ThreadPoolExecutor(0, nrOfProcessors,
30L, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(),
new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("dol-jar-scanner");
t.setDaemon(true);
t.setContextClassLoader(getClass().getClassLoader());
return t;
}
});

return executorService;
}

protected void setParser(Parser parser) {
if (parser == null) {
// if the passed in parser is null, it means no annotation scanning
// has been done yet, we need to construct a new parser
// and do the annotation scanning here
ParsingContext pc = new ParsingContext.Builder().logger(deplLogger).executorService(getExecutorService()).build();
ParsingContext pc = new ParsingContext.Builder().logger(deplLogger).executorService(executorService.getUnderlyingExecutorService()).build();
parser = new Parser(pc);
needScanAnnotation = true;
}
Expand Down
Expand Up @@ -73,6 +73,7 @@ Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates]
<configs>
<config name="server-config">
<payara-executor-service-configuration/>
<cdi-service enable-concurrent-deployment="true" pre-loader-thread-pool-size="2"></cdi-service>
<hazelcast-config-specific-configuration enabled="true"></hazelcast-config-specific-configuration>
<health-check-service-configuration enabled="false">
<log-notifier enabled="true"/>
Expand Down
1 change: 1 addition & 0 deletions appserver/pom.xml
Expand Up @@ -123,6 +123,7 @@
<javax.inject.version>1</javax.inject.version>
<cdi-api.version>2.0.SP1</cdi-api.version>
<weld.version>3.0.5.Final.payara-p1</weld.version>
<weld-bundle.version>3.0.5.Final_payara-p1</weld-bundle.version>
<weld-api.version>3.0.SP4</weld-api.version>
<jboss.classfilewriter.version>1.2.3.Final</jboss.classfilewriter.version>
<apache.bcel.version>6.2</apache.bcel.version>
Expand Down
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2017] [Payara Foundation and/or its affiliates]
// Portions Copyright [2017-2018] [Payara Foundation and/or its affiliates]

package org.glassfish.weld.connector;

Expand Down Expand Up @@ -83,5 +83,36 @@ public interface CDIService extends ConfigExtension {
* {@link String }
*/
void setEnableCdiDevMode(String value) throws PropertyVetoException;

/**
* Gets the value of the enableConcurrentDeployment property.
*
* @return The value of the enableImplicitCdi property.
*/
@Attribute (defaultValue="false", dataType=Boolean.class)
String getEnableConcurrentDeployment();

/**
* Sets the value of the enableConcurrentDeployment property.
*
* @param value allowed object is {@link String }
*/
void setEnableConcurrentDeployment(String value);

/**
* Gets the value of the preloader threads property.
*
* @return The value of the enableImplicitCdi property.
*/
@Attribute (defaultValue="0", dataType=Integer.class)
String getPreLoaderThreadPoolSize();

/**
* Sets the value of the enableConcurrentDeployment property.
*
* @param value allowed object is {@link String }
*/
void setPreLoaderThreadPoolSize(String value);


}
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates]

package org.glassfish.weld.connector;

Expand Down Expand Up @@ -477,6 +477,36 @@ private static Types getTypes(DeploymentContext context) {

return types;
}

public static int getPreLoaderThreads() {
int result = 0;
// Check the "global" configuration
ServiceLocator serviceLocator = Globals.getDefaultHabitat();
if (serviceLocator != null) {
Config config = serviceLocator.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
if (config != null) {
result = Integer.valueOf(config.getExtensionByType(CDIService.class).getPreLoaderThreadPoolSize());
}
}

return result;

}

public static boolean isConcurrentDeploymentEnabled() {
boolean result = false;
// Check the "global" configuration
ServiceLocator serviceLocator = Globals.getDefaultHabitat();
if (serviceLocator != null) {
Config config = serviceLocator.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
if (config != null) {
result = Boolean.valueOf(config.getExtensionByType(CDIService.class).getEnableConcurrentDeployment());
}
}

return result;

}


public static boolean isImplicitBeanDiscoveryEnabled() {
Expand Down
8 changes: 5 additions & 3 deletions appserver/web/weld-integration-fragment/pom.xml
Expand Up @@ -78,7 +78,7 @@
<manifestEntries>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-ManifestVersion>2</Bundle-ManifestVersion>
<Fragment-Host>org.jboss.weld.osgi-bundle</Fragment-Host>
<Fragment-Host>org.jboss.weld.osgi-bundle;bundle-version=${weld-bundle.version}</Fragment-Host>
<!-- The export of javassist.util.proxy is done to ensure that the weld-generated proxy has access to the ProxyFactory class
in that package. This "partial" export of the javassist package would not cause the problem described in IT 12368, because
javassist has fixed the issue in JASSIST-104, and as part of WELD-570, the new javassist version is integrated in Weld 1.1.Beta2
Expand Down Expand Up @@ -115,10 +115,12 @@
org.jboss.weld.resources,
org.jboss.weld.bean.attributes,
org.jboss.weld.contexts,
org.jboss.weld.util.reflection
org.jboss.weld.util.reflection,
org.jboss.weld.executor,
org.jboss.weld.exceptions
</Export-Package>
<Import-Package>org.glassfish.weld,
javax.ejb</Import-Package>
javax.ejb,org.glassfish.weld.services</Import-Package>
<Bundle-Description>${project.description}</Bundle-Description>
</manifestEntries>
</archive>
Expand Down
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
* Portions Copyright [2017-2018] Payara Foundation and/or affiliates
*/

package org.glassfish.weld;
Expand All @@ -50,9 +50,9 @@
import org.glassfish.internal.api.ClassLoaderHierarchy;

import java.util.Map;
import java.util.Hashtable;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.ConcurrentHashMap;

/**
* Singleton provider that uses Application ClassLoader to differentiate
Expand Down Expand Up @@ -86,8 +86,8 @@ public <T> ACLSingleton<T> create(Class<? extends T> expectedType) {

private static class ACLSingleton<T> implements Singleton<T> {

// use Hashtable for concurrent access
private final Map<ClassLoader, T> store = new Hashtable<ClassLoader, T>();
private final Map<ClassLoader, T> store = new ConcurrentHashMap<>();
private final Map<String, T> storeById = new ConcurrentHashMap<>();
private ClassLoader ccl = Globals.get(ClassLoaderHierarchy.class).getCommonClassLoader();

// Can't assume bootstrap loader as null. That's more of a convention.
Expand All @@ -113,7 +113,10 @@ public T get( String id )
T instance = store.get(acl);
if (instance == null)
{
throw new IllegalStateException("Singleton not set for " + acl);
instance = storeById.get(id);
if (instance == null) {
throw new IllegalStateException("Singleton not set for " + acl);
}
}
return instance;
}
Expand Down Expand Up @@ -191,17 +194,19 @@ public ClassLoader run()

@Override
public boolean isSet(String id) {
return store.containsKey(getClassLoader());
return store.containsKey(getClassLoader()) || storeById.containsKey(id);
}

@Override
public void set(String id, T object) {
store.put(getClassLoader(), object);
storeById.put(id, object);
}

@Override
public void clear(String id) {
store.remove(getClassLoader());
storeById.remove(id);
}
}
}
Expand Up @@ -110,7 +110,6 @@
import org.glassfish.web.deployment.descriptor.ServletFilterDescriptor;
import org.glassfish.web.deployment.descriptor.ServletFilterMappingDescriptor;
import org.glassfish.weld.connector.WeldUtils;
import org.glassfish.weld.services.BootstrapConfigurationImpl;
import org.glassfish.weld.services.EjbServicesImpl;
import org.glassfish.weld.services.ExternalConfigurationImpl;
import org.glassfish.weld.services.InjectionServicesImpl;
Expand All @@ -120,7 +119,6 @@
import org.glassfish.weld.services.TransactionServicesImpl;
import org.jboss.weld.bootstrap.WeldBootstrap;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.bootstrap.spi.BootstrapConfiguration;
import org.jboss.weld.bootstrap.spi.EEModuleDescriptor;
import org.jboss.weld.bootstrap.spi.Metadata;
import org.jboss.weld.bootstrap.spi.helpers.EEModuleDescriptorImpl;
Expand All @@ -147,7 +145,9 @@
import com.sun.enterprise.deployment.WebBundleDescriptor;
import com.sun.enterprise.deployment.web.ContextParameter;
import com.sun.enterprise.deployment.web.ServletFilterMapping;
import java.util.logging.Level;
import fish.payara.nucleus.executorservice.PayaraExecutorService;
import org.glassfish.weld.services.ExecutorServicesImpl;
import org.jboss.weld.manager.api.ExecutorServices;

@Service
public class WeldDeployer extends SimpleDeployer<WeldContainer, WeldApplicationContainer> implements PostConstruct, EventListener {
Expand Down Expand Up @@ -207,6 +207,9 @@ public class WeldDeployer extends SimpleDeployer<WeldContainer, WeldApplicationC

@Inject
private Deployment deployment;

@Inject
private PayaraExecutorService executorService;

private Map<Application, WeldBootstrap> appToBootstrap = new HashMap<>();

Expand Down Expand Up @@ -301,9 +304,9 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext

ProxyServices proxyServices = new ProxyServicesImpl(services);
deploymentImpl.getServices().add(ProxyServices.class, proxyServices);

BootstrapConfigurationImpl bootstrapConfiguration = new BootstrapConfigurationImpl();
deploymentImpl.getServices().add(BootstrapConfiguration.class, bootstrapConfiguration);
ExecutorServices executorServices = new ExecutorServicesImpl(executorService);
deploymentImpl.getServices().add(ExecutorServices.class, executorServices);

addWeldListenerToAllWars(context);
} else {
Expand All @@ -320,6 +323,9 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext
ExternalConfigurationImpl externalConfiguration = new ExternalConfigurationImpl();
externalConfiguration.setRollingUpgradesDelimiter(System.getProperty("fish.payara.rollingUpgradesDelimiter", ":"));
externalConfiguration.setBeanIndexOptimization(dc != null ? !dc.isAvailabilityEnabled() : true);
externalConfiguration.setNonPortableMode(false);
configureConcurrentDeployment(context, externalConfiguration);

deploymentImpl.getServices().add(ExternalConfiguration.class, externalConfiguration);

BeanDeploymentArchive beanDeploymentArchive = deploymentImpl.getBeanDeploymentArchiveForArchive(archiveName);
Expand Down Expand Up @@ -862,6 +868,11 @@ private void registerProbeExtension(ExternalConfigurationImpl externalConfigurat
externalConfiguration.setProbeAllowRemoteAddress(PROBE_ALLOW_REMOTE_ADDRESS);
deploymentImpl.addDynamicExtension(createProbeExtension());
}

private void configureConcurrentDeployment(DeploymentContext context, ExternalConfigurationImpl configuration) {
configuration.setConcurrentDeployment(WeldUtils.isConcurrentDeploymentEnabled());
configuration.setPreLoaderThreadPoolSize(WeldUtils.getPreLoaderThreads());
}

private Metadata<Extension> createProbeExtension() {
ProbeExtension probeExtension;
Expand Down

0 comments on commit 9a750f6

Please sign in to comment.