Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrency for GlassFish 8 #24954

Merged
merged 23 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7839a8e
Added descriptors for JEE 11
dmatej May 15, 2024
a3384d8
Updated dependency on concurrency TCK
dmatej May 15, 2024
3047217
Added qualifiers annotation attribute processing
dmatej May 15, 2024
d3f8bbf
Dependency on Concurro snapshot version
dmatej May 15, 2024
3effb6b
Added the attribute 'virtual', new in Concurrency 3.1
dmatej May 17, 2024
1efa897
Fixed NPE
dmatej May 18, 2024
566d4bf
integrate concurro and concurrency 3.1
dmatej Jun 2, 2024
8469962
temporarily disable concurro dependency due to osgi problems
aubi May 19, 2024
30083a3
More robust work with qualifiers in descriptors and annotations
dmatej May 20, 2024
04bef7d
Fixed classloader issues - qualifiers must be processed as strings in…
dmatej May 20, 2024
b62f472
never override qualifiers by annotation in concurrency definitions
aubi May 21, 2024
064b290
Revert "never override qualifiers by annotation in concurrency defini…
dmatej May 22, 2024
15a21e9
The ContextServiceDefinitionConverter improved
dmatej May 22, 2024
4e5d5fc
ContextServiceDefinitionDescriptor adapted to ContextualResourceDefin…
dmatej May 22, 2024
9a8d90d
Added more detailed toStrings for concurrency data objects
dmatej May 22, 2024
0f876b1
Added log to ComponentEnvManagerImpl
dmatej May 22, 2024
cabc0cc
Correct merging qualifiers respecting a special empty element
dmatej May 23, 2024
d3ca3f9
Removing an empty String which may occur in XML as a special value
dmatej May 23, 2024
1a95fb8
ApplicationNode can contain empty qualifier element
dmatej May 23, 2024
05f9598
Cleanups around deployments and JNDI, using module name in ComponentI…
dmatej Jun 2, 2024
a964a06
Fixed lookup for java:app/ contexts
dmatej Jun 2, 2024
2cb1ce5
Update pom.xml
arjantijms Jun 2, 2024
da67edb
Referring to custom built Concurrency TCK 3.1.1-SNAPSHOT
dmatej Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion appserver/common/container-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!--

Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation.
Copyright (c) 2024 Payara Foundation and/or its affiliates
Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.

This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -114,7 +115,11 @@
<groupId>org.glassfish.ha</groupId>
<artifactId>ha-api</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>org.glassfish.concurro</groupId>
<artifactId>concurro</artifactId>
</dependency>
</dependencies>

<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024 Payara Foundation and/or its affiliates
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -25,6 +26,7 @@
import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.ApplicationClientDescriptor;
import com.sun.enterprise.deployment.ConnectionFactoryDefinitionDescriptor;
import com.sun.enterprise.deployment.ContextServiceDefinitionDescriptor;
import com.sun.enterprise.deployment.DataSourceDefinitionDescriptor;
import com.sun.enterprise.deployment.EjbReferenceDescriptor;
import com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor;
Expand All @@ -34,11 +36,15 @@
import com.sun.enterprise.deployment.JndiNameEnvironment;
import com.sun.enterprise.deployment.MailSessionDescriptor;
import com.sun.enterprise.deployment.ManagedBeanDescriptor;
import com.sun.enterprise.deployment.ManagedExecutorDefinitionDescriptor;
import com.sun.enterprise.deployment.ManagedScheduledExecutorDefinitionDescriptor;
import com.sun.enterprise.deployment.ManagedThreadFactoryDefinitionDescriptor;
import com.sun.enterprise.deployment.MessageDestinationReferenceDescriptor;
import com.sun.enterprise.deployment.ResourceDescriptor;
import com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor;
import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
import com.sun.enterprise.deployment.annotation.handlers.ConcurrencyResourceDefinition;
import com.sun.enterprise.deployment.util.DOLUtils;
import com.sun.enterprise.naming.spi.NamingObjectFactory;
import com.sun.enterprise.naming.spi.NamingUtils;
Expand Down Expand Up @@ -76,12 +82,14 @@
import org.glassfish.api.naming.JNDIBinding;
import org.glassfish.api.naming.NamingObjectProxy;
import org.glassfish.api.naming.SimpleJndiName;
import org.glassfish.concurro.cdi.ConcurrencyManagedCDIBeans;
import org.glassfish.deployment.common.Descriptor;
import org.glassfish.deployment.common.JavaEEResourceType;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.javaee.services.CommonResourceProxy;
import org.glassfish.javaee.services.JMSCFResourcePMProxy;
import org.glassfish.resourcebase.resources.api.ResourceDeployer;
import org.glassfish.resourcebase.resources.naming.ApplicationScopedResourceBinding;
import org.glassfish.resourcebase.resources.util.ResourceManagerFactory;
import org.jvnet.hk2.annotations.Service;

Expand All @@ -95,6 +103,10 @@
import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA;
import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA_COMPONENT;
import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA_COMPONENT_ENV;
import static org.glassfish.concurro.cdi.ConcurrencyManagedCDIBeans.Type.CONTEXT_SERVICE;
import static org.glassfish.concurro.cdi.ConcurrencyManagedCDIBeans.Type.MANAGED_EXECUTOR_SERVICE;
import static org.glassfish.concurro.cdi.ConcurrencyManagedCDIBeans.Type.MANAGED_SCHEDULED_EXECUTOR_SERVICE;
import static org.glassfish.concurro.cdi.ConcurrencyManagedCDIBeans.Type.MANAGED_THREAD_FACTORY;
import static org.glassfish.deployment.common.JavaEEResourceType.AODD;
import static org.glassfish.deployment.common.JavaEEResourceType.CFD;
import static org.glassfish.deployment.common.JavaEEResourceType.CSDD;
Expand Down Expand Up @@ -372,6 +384,46 @@ private void addAllDescriptorBindings(JndiNameEnvironment jndiEnv, ScopeType sco
jndiBindings.add(jmscfEnvBinding);
}
}

if (scope == ScopeType.APP) {
Set<ResourceDescriptor> concurrencyDescs = new HashSet<>();
concurrencyDescs.addAll(managedExecutorDefinitions);
concurrencyDescs.addAll(managedThreadfactoryDefintions);
concurrencyDescs.addAll(managedScheduledDefinitions);
concurrencyDescs.addAll(contextServiceDefinitions);
if (!concurrencyDescs.isEmpty()) {
registerConcurrencyCDIQualifiers(jndiBindings, concurrencyDescs);
}
}
}

private void registerConcurrencyCDIQualifiers(Collection<JNDIBinding> jndiBindings, Set<ResourceDescriptor> concurrencyDescs) {
ConcurrencyManagedCDIBeans setup = new ConcurrencyManagedCDIBeans();
for (ResourceDescriptor desc : concurrencyDescs) {
LOG.log(FINE, () -> "Registering concurrency CDI qualifiers for descriptor: " + desc);
String jndiName = toLogicalJndiName(desc).toString();
ConcurrencyResourceDefinition descriptor = (ConcurrencyResourceDefinition) desc;
Set<String> qualifiers = new HashSet<>(descriptor.getQualifiers());
// A special value which might occur in XML
// We don't need it any more.
qualifiers.remove("");
if (descriptor instanceof ContextServiceDefinitionDescriptor) {
setup.addDefinition(CONTEXT_SERVICE, qualifiers, jndiName);
} else if (descriptor instanceof ManagedExecutorDefinitionDescriptor) {
setup.addDefinition(MANAGED_EXECUTOR_SERVICE, qualifiers, jndiName);
} else if (descriptor instanceof ManagedScheduledExecutorDefinitionDescriptor) {
setup.addDefinition(MANAGED_SCHEDULED_EXECUTOR_SERVICE, qualifiers, jndiName);
} else if (descriptor instanceof ManagedThreadFactoryDefinitionDescriptor) {
setup.addDefinition(MANAGED_THREAD_FACTORY, qualifiers, jndiName);
} else {
throw new IllegalArgumentException("Unexpected Concurrency type!"
+ " Expected ContextServiceDefinitionDescriptor, ManagedExecutorDefinitionDescriptor,"
+ " ManagedScheduledExecutorDefinitionDescriptor, or ManagedThreadFactoryDefinitionDescriptor,"
+ " got " + descriptor);
}
}
SimpleJndiName jndiName = new SimpleJndiName(ConcurrencyManagedCDIBeans.JDNI_NAME);
jndiBindings.add(new ApplicationScopedResourceBinding(jndiName, setup));
}

private ResourceDeployer getResourceDeployer(Object resource) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2024 Payara Foundation and/or its affiliates
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -355,6 +356,19 @@ private JavaNamespace getAppNamespace(String appName) throws NamingException {
}


private JavaNamespace getNamespace(SimpleJndiName logicalJndiName) throws NamingException {
LOG.log(TRACE, "getNamespace(info, logicalJndiName={0})", logicalJndiName);
final ComponentInvocation invocation = getComponentInvocation();
if (logicalJndiName.isJavaModule()) {
return getModuleNamespace(new AppModuleKey(invocation.getAppName(), invocation.getModuleName()));
} else if (logicalJndiName.isJavaApp()) {
return getAppNamespace(invocation.getAppName());
} else {
return getComponentNamespace(invocation.getComponentId());
}
}


private JavaNamespace getNamespace(ComponentIdInfo info, SimpleJndiName logicalJndiName) throws NamingException {
LOG.log(TRACE, "getNamespace(info, logicalJndiName={0})", logicalJndiName);
if (logicalJndiName.isJavaModule()) {
Expand Down Expand Up @@ -583,20 +597,24 @@ public <T> T lookup(String componentId, SimpleJndiName name) throws NamingExcept

private <T> T lookup(String componentId, SimpleJndiName name, Context ctx) throws NamingException {
LOG.log(DEBUG, "lookup(componentId={0}, name={1}, ctx={2})", componentId, name, ctx);
// FIXME: added and commented out dmatej
// if (!name.hasJavaPrefix() && name.contains(":")) {
// // generic jndi names
// return (T) initialContext.lookup(name.toName());
// }
final ComponentIdInfo info = componentIdInfo.get(componentId);
LOG.log(TRACE, "Found componentIdInfo={0}", info);
final boolean replaceName = info != null && info.treatComponentAsModule && name.isJavaComponent();
final SimpleJndiName replacedName = replaceName ? name.changePrefix(JNDI_CTX_JAVA_MODULE) : name;
JavaNamespace namespace = info == null ? getComponentNamespace(componentId) : getNamespace(info, replacedName);
Object obj = namespace.get(replacedName);
LOG.log(TRACE, "For {0} found object={1} in namespace.name={2}", replacedName, obj, namespace.name);
final boolean replaceName;
final SimpleJndiName lookupName;
final JavaNamespace namespace;
if (info == null) {
replaceName = false;
lookupName = name;
namespace = getNamespace(lookupName);
} else {
replaceName = info.treatComponentAsModule && name.isJavaComponent();
lookupName = replaceName ? name.changePrefix(JNDI_CTX_JAVA_MODULE) : name;
namespace = getNamespace(info, lookupName);
}
Object obj = namespace.get(lookupName);
LOG.log(TRACE, "For {0} found object={1} in namespace.name={2}", lookupName, obj, namespace.name);
if (obj == null) {
throw new NameNotFoundException("No object bound to name " + replacedName + " in namespace " + namespace);
throw new NameNotFoundException("No object bound to name " + lookupName + " in namespace " + namespace);
}
if (obj instanceof NamingObjectProxy) {
NamingObjectProxy namingProxy = (NamingObjectProxy) obj;
Expand Down Expand Up @@ -682,6 +700,16 @@ private ArrayList<SimpleJndiName> listNames(SimpleJndiName name) throws NamingEx
* @return the component id as a string.
*/
private String getComponentId() throws NamingException {
final ComponentInvocation invocation = getComponentInvocation();
final String id = invocation.getComponentId();
if (id == null) {
throw new NamingException("Invocation exception: ComponentId is null");
}
return id;
}


private ComponentInvocation getComponentInvocation() throws NamingException {
final ComponentInvocation invocation;
if (invMgr == null) {
invocation = serviceLocator.<InvocationManager> getService(InvocationManager.class).getCurrentInvocation();
Expand All @@ -692,12 +720,7 @@ private String getComponentId() throws NamingException {
if (invocation == null) {
throw new NamingException("Invocation exception: Got null ComponentInvocation!");
}

String id = invocation.getComponentId();
if (id == null) {
throw new NamingException("Invocation exception: Got null ComponentId!");
}
return id;
return invocation;
}


Expand Down Expand Up @@ -727,18 +750,18 @@ private static class AppModuleKey implements Serializable {
private final String app;
private final String module;

public AppModuleKey(String appName, String moduleName) {
private AppModuleKey(String appName, String moduleName) {
app = appName;
module = moduleName;
}


public String getAppName() {
private String getAppName() {
return app;
}


public String getModuleName() {
private String getModuleName() {
return module;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Eclipse Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024 Eclipse Foundation and/or its affiliates.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -38,7 +38,7 @@ public class ContextServiceCfg implements Serializable {
private final Set<ConcurrencyContextType> unchangedContexts;

public ContextServiceCfg(ContextServiceDefinitionData data) {
this.serviceConfig = new ConcurrentServiceCfg(data.getName());
this.serviceConfig = new ConcurrentServiceCfg(data.getJndiName());
this.propagatedContexts = CfgParser.standardize(data.getPropagated());
this.clearedContexts = CfgParser.standardize(data.getCleared());
this.unchangedContexts = CfgParser.standardize(data.getUnchanged());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2022, 2023 Eclipse Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024 Eclipse Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2024 Payara Foundation and/or its affiliates
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -16,20 +17,21 @@

package com.sun.enterprise.deployment;

import com.sun.enterprise.deployment.annotation.handlers.ConcurrencyResourceDefinition;
import com.sun.enterprise.deployment.annotation.handlers.ContextServiceDefinitionData;

import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;

import org.glassfish.api.naming.SimpleJndiName;
import org.glassfish.deployment.common.JavaEEResourceType;


/**
* @author David Matejcek
*/
public class ContextServiceDefinitionDescriptor extends ResourceDescriptor {
public class ContextServiceDefinitionDescriptor extends ResourceDescriptor implements ConcurrencyResourceDefinition {

private static final long serialVersionUID = 2537143519647534821L;

Expand All @@ -49,13 +51,31 @@ public ContextServiceDefinitionDescriptor(ContextServiceDefinitionData data, Met

@Override
public String getName() {
return this.data.getName().toString();
return this.data.getName();
}


@Override
public void setName(String name) {
this.data.setName(new SimpleJndiName(name));
this.data.setName(name);
}


@Override
public List<String> getQualifiers() {
return data.getQualifiers();
}


@Override
public void addQualifier(String qualifier) {
data.addQualifier(qualifier);
}


@Override
public void setQualifiers(List<String> qualifiers) {
data.setQualifiers(qualifiers);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Eclipse Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024 Eclipse Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -16,9 +16,10 @@

package com.sun.enterprise.deployment;

import com.sun.enterprise.deployment.annotation.factory.ManagedExecutorDefinitionData;
import com.sun.enterprise.deployment.annotation.handlers.ContextualResourceDefinition;
import com.sun.enterprise.deployment.annotation.handlers.ManagedExecutorDefinitionData;

import java.util.List;
import java.util.Objects;
import java.util.Properties;

Expand Down Expand Up @@ -70,6 +71,36 @@ public void setContext(String context) {
}


@Override
public List<String> getQualifiers() {
return data.getQualifiers();
}


@Override
public void addQualifier(String qualifier) {
data.addQualifier(qualifier);
}


@Override
public void setQualifiers(List<String> qualifiers) {
data.setQualifiers(qualifiers);
}


@Override
public boolean isVirtual() {
return data.isVirtual();
}


@Override
public void setVirtual(boolean virtual) {
data.setVirtual(virtual);
}


public int getMaximumPoolSize() {
return data.getMaximumPoolSize();
}
Expand Down
Loading