Skip to content

Commit

Permalink
Merge pull request #5369 from jGauravGupta/FISH-81
Browse files Browse the repository at this point in the history
FISH-81 Fix Incorrect error "No valid EE environment for injection" for CDI reported for events
  • Loading branch information
jGauravGupta authored Aug 10, 2021
2 parents 30d8556 + 9aa3254 commit 13f8348
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
11 changes: 10 additions & 1 deletion appserver/web/weld-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
holder.
-->
<!-- Portions Copyright [2018-2019] [Payara Foundation and/or its affiliates] -->
<!-- Portions Copyright [2018-2021] [Payara Foundation and/or its affiliates] -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -106,6 +106,10 @@
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise.concurrent</groupId>
<artifactId>jakarta.enterprise.concurrent-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
Expand Down Expand Up @@ -207,5 +211,10 @@
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
</dependency>
<dependency>
<groupId>fish.payara.server.internal.concurrent</groupId>
<artifactId>concurrent-connector</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016-2020] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2021] [Payara Foundation and/or its affiliates]

package org.glassfish.weld;

Expand Down Expand Up @@ -141,7 +141,7 @@
import com.sun.enterprise.deployment.WebBundleDescriptor;
import com.sun.enterprise.deployment.web.ContextParameter;
import com.sun.enterprise.deployment.web.ServletFilterMapping;
import fish.payara.nucleus.executorservice.PayaraExecutorService;
import javax.naming.NamingException;
import org.jboss.weld.manager.api.ExecutorServices;

@Service
Expand Down Expand Up @@ -204,9 +204,6 @@ public class WeldDeployer extends SimpleDeployer<WeldContainer, WeldApplicationC
@Inject
private Deployment deployment;

@Inject
private PayaraExecutorService executorService;

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

private Map<BundleDescriptor, BeanDeploymentArchive> bundleToBeanDeploymentArchive = new HashMap<>();
Expand Down Expand Up @@ -308,8 +305,12 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext
ProxyServices proxyServices = new ProxyServicesImpl(services);
deploymentImpl.getServices().add(ProxyServices.class, proxyServices);

ExecutorServices executorServices = new ExecutorServicesImpl(executorService);
deploymentImpl.getServices().add(ExecutorServices.class, executorServices);
try {
ExecutorServices executorServices = new ExecutorServicesImpl();
deploymentImpl.getServices().add(ExecutorServices.class, executorServices);
} catch (NamingException ex) {
throw new RuntimeException(ex);
}

addWeldListenerToAllWars(context);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2016-2019] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2016-2021] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -40,7 +40,6 @@
package org.glassfish.weld.services;

import com.sun.enterprise.util.Utility;
import fish.payara.nucleus.executorservice.PayaraExecutorService;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
Expand All @@ -52,6 +51,12 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.enterprise.concurrent.ManagedExecutorService;
import javax.enterprise.concurrent.ManagedScheduledExecutorService;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.Globals;

import org.jboss.weld.executor.AbstractExecutorServices;
import org.jboss.weld.manager.api.ExecutorServices;
Expand All @@ -65,12 +70,19 @@ public class ExecutorServicesImpl extends AbstractExecutorServices implements Ex

private final ExecutorService taskExecutor;
private final ContextualTimerExecutor timerExecutor;
private PayaraExecutorService executor;

public ExecutorServicesImpl(PayaraExecutorService service) {
executor = service;
private final ManagedExecutorService executor;
private final org.glassfish.concurrent.config.ManagedExecutorService config;

private static final String DEFAULT_MANAGED_SCHEDULED_EXECUTOR_SERVICE = "java:comp/DefaultManagedScheduledExecutorService";
private static final String DEFAULT_MANAGED_EXECUTOR_SERVICE = "java:comp/DefaultManagedExecutorService";
private static final String DEFAULT_MANAGED_EXECUTOR_SERVICE_PHYS = "concurrent/__defaultManagedExecutorService";

public ExecutorServicesImpl() throws NamingException {
InitialContext ctx = new InitialContext();
executor = (ManagedExecutorService) ctx.lookup(DEFAULT_MANAGED_EXECUTOR_SERVICE);
taskExecutor = new ContextualTaskExecutor();
timerExecutor = new ContextualTimerExecutor();
this.config = getManagedExecutorServiceConfig(DEFAULT_MANAGED_EXECUTOR_SERVICE_PHYS);
}

@Override
Expand All @@ -89,7 +101,7 @@ public void cleanup() {

@Override
protected int getThreadPoolSize() {
return executor.getExecutorThreadPoolSize();
return Integer.parseInt(this.config.getMaximumPoolSize());
}

@Override
Expand Down Expand Up @@ -135,10 +147,10 @@ private static Runnable inCurrentContextClassloader(Runnable task) {
}

class ContextualTaskExecutor implements ExecutorService {
private ExecutorService delegate;
private final ExecutorService delegate;

ContextualTaskExecutor() {
this.delegate = executor.getUnderlyingExecutorService();
this.delegate = executor;
}

@Override
Expand Down Expand Up @@ -214,10 +226,12 @@ protected ExecutorService delegate() {
class ContextualTimerExecutor extends ContextualTaskExecutor implements ScheduledExecutorService {
private final ScheduledExecutorService delegate;

ContextualTimerExecutor() {
this.delegate = executor.getUnderlyingScheduledExecutorService();
ContextualTimerExecutor() throws NamingException {
InitialContext ctx = new InitialContext();
this.delegate = (ManagedScheduledExecutorService) ctx.lookup(DEFAULT_MANAGED_SCHEDULED_EXECUTOR_SERVICE);
}

@Override
protected ScheduledExecutorService delegate() {
return this.delegate;
}
Expand All @@ -242,4 +256,15 @@ public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialD
return delegate().scheduleWithFixedDelay(inCurrentContextClassloader(command), initialDelay, delay, unit);
}
}

private org.glassfish.concurrent.config.ManagedExecutorService getManagedExecutorServiceConfig(String jndiName) {
for (org.glassfish.concurrent.config.ManagedExecutorService service : Globals.getDefaultHabitat()
.getAllServices(org.glassfish.concurrent.config.ManagedExecutorService.class)) {
if(service.getJndiName().equals(jndiName)) {
return service;
}
}
throw new IllegalStateException(jndiName + " executor service config not found.");
}

}

0 comments on commit 13f8348

Please sign in to comment.