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 dol cleanups #24129

Merged
merged 12 commits into from
Oct 17, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Concurrency resource base class
*/
@Configured
public interface ConcurrencyResource extends PropertyBag {
public interface ConcurrencyResource extends PropertyBag {

/**
* Gets the value of the contextInfoEnabled property.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -21,28 +22,35 @@
import com.sun.enterprise.config.serverbeans.Resources;
import com.sun.enterprise.config.serverbeans.ServerTags;
import com.sun.enterprise.util.LocalStringManagerImpl;

import jakarta.inject.Inject;
import jakarta.resource.ResourceException;

import java.beans.PropertyVetoException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.glassfish.api.I18n;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.concurrent.config.ContextService;
import org.glassfish.resources.admin.cli.ResourceManager;
import org.glassfish.resourcebase.resources.admin.cli.ResourceUtil;
import org.glassfish.resourcebase.resources.api.ResourceStatus;
import org.glassfish.resourcebase.resources.util.BindableResourcesHelper;
import org.glassfish.resources.admin.cli.ResourceManager;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.ConfiguredBy;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
import org.jvnet.hk2.config.types.Property;

import jakarta.inject.Inject;
import jakarta.resource.ResourceException;
import java.beans.PropertyVetoException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import static org.glassfish.resources.admin.cli.ResourceConstants.*;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.CONTEXT_INFO;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.CONTEXT_INFO_DEFAULT_VALUE;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.CONTEXT_INFO_ENABLED;
import static org.glassfish.resources.admin.cli.ResourceConstants.ENABLED;
import static org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME;
import static org.glassfish.resources.admin.cli.ResourceConstants.SYSTEM_ALL_REQ;

/**
*
Expand Down Expand Up @@ -74,10 +82,12 @@ public class ContextServiceManager implements ResourceManager {
@Inject
private BindableResourcesHelper resourcesHelper;

@Override
public String getResourceType () {
return ServerTags.CONTEXT_SERVICE;
}

@Override
public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties,
String target) throws Exception {

Expand All @@ -91,6 +101,7 @@ public ResourceStatus create(Resources resources, HashMap attributes, final Prop
try {
ConfigSupport.apply(new SingleConfigCode<Resources>() {

@Override
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
return createResource(param, properties);
}
Expand Down Expand Up @@ -162,19 +173,19 @@ private ContextService createConfigBean(Resources param, Properties properties)
return contextService;
}

@Override
public Resource createConfigBean(final Resources resources, HashMap attributes, final Properties properties, boolean validate) throws Exception{
setAttributes(attributes, null);
ResourceStatus status = null;
if(!validate){
status = new ResourceStatus(ResourceStatus.SUCCESS,"");
}else{
final ResourceStatus status;
if (validate) {
status = isValid(resources, false, null);
} else {
status = new ResourceStatus(ResourceStatus.SUCCESS, "");
}
if(status.getStatus() == ResourceStatus.SUCCESS){
if (status.getStatus() == ResourceStatus.SUCCESS) {
return createConfigBean(resources, properties);
}else{
throw new ResourceException(status.getMessage());
}
throw new ResourceException(status.getMessage());
}

public ResourceStatus delete (final Resources resources, final String jndiName, final String target)
Expand Down Expand Up @@ -224,8 +235,9 @@ public ResourceStatus delete (final Resources resources, final String jndiName,

// delete context-service
if (ConfigSupport.apply(new SingleConfigCode<Resources>() {
@Override
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
ContextService resource = (ContextService) ConnectorsUtil.getResourceByName(resources, ContextService.class, jndiName);
ContextService resource = ConnectorsUtil.getResourceByName(resources, ContextService.class, jndiName);
return param.getResources().remove(resource);
}
}, resources) == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -18,8 +19,15 @@

import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.ServerTags;
import com.sun.enterprise.deployment.xml.ConcurrencyTagNames;
import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.enterprise.util.SystemPropertyConstants;

import jakarta.inject.Inject;

import java.util.HashMap;
import java.util.Properties;

import org.glassfish.api.ActionReport;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
Expand All @@ -30,14 +38,10 @@
import org.glassfish.config.support.CommandTarget;
import org.glassfish.config.support.TargetType;
import org.glassfish.hk2.api.PerLookup;
import org.glassfish.resources.admin.cli.ResourceConstants;
import org.glassfish.resourcebase.resources.api.ResourceStatus;
import org.glassfish.resources.admin.cli.ResourceConstants;
import org.jvnet.hk2.annotations.Service;

import jakarta.inject.Inject;
import java.util.HashMap;
import java.util.Properties;


/**
* Create Context Service Command
Expand All @@ -61,7 +65,7 @@ public class CreateContextService implements AdminCommand {
@Param(name="contextinfoenabled", alias="contextInfoEnabled", defaultValue="true", optional=true)
private Boolean contextinfoenabled;

@Param(name="contextinfo", alias="contextInfo", defaultValue=ResourceConstants.CONTEXT_INFO_DEFAULT_VALUE, optional=true)
@Param(name="contextinfo", alias="contextInfo", defaultValue=ConcurrencyTagNames.CONTEXT_INFO_DEFAULT_VALUE, optional=true)
private String contextinfo;

@Param(optional=true)
Expand Down Expand Up @@ -91,8 +95,8 @@ public void execute(AdminCommandContext context) {

HashMap attrList = new HashMap();
attrList.put(ResourceConstants.JNDI_NAME, jndiName);
attrList.put(ResourceConstants.CONTEXT_INFO_ENABLED, contextinfoenabled.toString());
attrList.put(ResourceConstants.CONTEXT_INFO, contextinfo);
attrList.put(ConcurrencyTagNames.CONTEXT_INFO_ENABLED, contextinfoenabled.toString());
attrList.put(ConcurrencyTagNames.CONTEXT_INFO, contextinfo);
attrList.put(ServerTags.DESCRIPTION, description);
attrList.put(ResourceConstants.ENABLED, enabled.toString());
ResourceStatus rs;
Expand All @@ -112,8 +116,9 @@ public void execute(AdminCommandContext context) {
}
if (rs.getStatus() == ResourceStatus.FAILURE) {
ec = ActionReport.ExitCode.FAILURE;
if (rs.getException() != null)
if (rs.getException() != null) {
report.setFailureCause(rs.getException());
}
}
report.setActionExitCode(ec);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,6 +18,12 @@
package org.glassfish.concurrent.admin;

import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.deployment.xml.ConcurrencyTagNames;

import jakarta.inject.Inject;

import java.util.HashMap;

import org.glassfish.api.ActionReport;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
Expand All @@ -27,13 +34,9 @@
import org.glassfish.config.support.CommandTarget;
import org.glassfish.config.support.TargetType;
import org.glassfish.hk2.api.PerLookup;
import org.glassfish.resources.admin.cli.ResourceConstants;
import org.glassfish.resourcebase.resources.api.ResourceStatus;
import org.jvnet.hk2.annotations.Service;

import jakarta.inject.Inject;
import java.util.HashMap;


/**
* Create Managed Executor Service Command
Expand Down Expand Up @@ -61,11 +64,10 @@ public class CreateManagedExecutorService extends CreateManagedExecutorServiceBa
@Override
protected void setAttributeList(HashMap attrList) {
super.setAttributeList(attrList);
attrList.put(ResourceConstants.MAXIMUM_POOL_SIZE,
maximumpoolsize.toString());
attrList.put(ResourceConstants.TASK_QUEUE_CAPACITY,
taskqueuecapacity.toString());
attrList.put(ConcurrencyTagNames.MAXIMUM_POOL_SIZE, maximumpoolsize.toString());
attrList.put(ConcurrencyTagNames.TASK_QUEUE_CAPACITY, taskqueuecapacity.toString());
}

/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
Expand Down Expand Up @@ -95,8 +97,9 @@ public void execute(AdminCommandContext context) {
}
if (rs.getStatus() == ResourceStatus.FAILURE) {
ec = ActionReport.ExitCode.FAILURE;
if (rs.getException() != null)
if (rs.getException() != null) {
report.setFailureCause(rs.getException());
}
}
report.setActionExitCode(ec);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* 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 @@ -17,14 +17,30 @@

package org.glassfish.concurrent.admin;

import com.sun.enterprise.config.serverbeans.ServerTags;
import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.enterprise.util.SystemPropertyConstants;
import org.glassfish.api.Param;
import org.glassfish.resources.admin.cli.ResourceConstants;

import java.util.HashMap;
import java.util.Properties;

import org.glassfish.api.Param;

import static com.sun.enterprise.config.serverbeans.ServerTags.DESCRIPTION;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.CONTEXT_INFO;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.CONTEXT_INFO_DEFAULT_VALUE;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.CONTEXT_INFO_ENABLED;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.CORE_POOL_SIZE;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.HUNG_AFTER_SECONDS;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.HUNG_LOGGER_INITIAL_DELAY_SECONDS;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.HUNG_LOGGER_INTERVAL_SECONDS;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.HUNG_LOGGER_PRINT_ONCE;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.KEEP_ALIVE_SECONDS;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.LONG_RUNNING_TASKS;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.THREAD_LIFETIME_SECONDS;
import static com.sun.enterprise.deployment.xml.ConcurrencyTagNames.THREAD_PRIORITY;
import static org.glassfish.resources.admin.cli.ResourceConstants.ENABLED;
import static org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME;


/**
* Base command for creating managed executor service and managed
Expand All @@ -33,7 +49,7 @@
*/
public class CreateManagedExecutorServiceBase {

final protected static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(CreateManagedExecutorServiceBase.class);
protected static final LocalStringManagerImpl localStrings = new LocalStringManagerImpl(CreateManagedExecutorServiceBase.class);

@Param(name="jndi_name", primary=true)
protected String jndiName;
Expand All @@ -44,7 +60,7 @@ public class CreateManagedExecutorServiceBase {
@Param(name="contextinfoenabled", alias="contextInfoEnabled", defaultValue="true", optional=true)
private Boolean contextinfoenabled;

@Param(name="contextinfo", alias="contextInfo", defaultValue=ResourceConstants.CONTEXT_INFO_DEFAULT_VALUE, optional=true)
@Param(name="contextinfo", alias="contextInfo", defaultValue=CONTEXT_INFO_DEFAULT_VALUE, optional=true)
protected String contextinfo;

@Param(name="threadpriority", alias="threadPriority", defaultValue=""+Thread.NORM_PRIORITY, optional=true)
Expand Down Expand Up @@ -84,26 +100,19 @@ public class CreateManagedExecutorServiceBase {
protected String target = SystemPropertyConstants.DAS_SERVER_NAME;

protected void setAttributeList(HashMap attrList) {
attrList.put(ResourceConstants.JNDI_NAME, jndiName);
attrList.put(ResourceConstants.CONTEXT_INFO_ENABLED, contextinfoenabled.toString());
attrList.put(ResourceConstants.CONTEXT_INFO, contextinfo);
attrList.put(ResourceConstants.THREAD_PRIORITY,
threadpriority.toString());
attrList.put(ResourceConstants.LONG_RUNNING_TASKS,
longrunningtasks.toString());
attrList.put(ResourceConstants.HUNG_AFTER_SECONDS,
hungafterseconds.toString());
attrList.put(ResourceConstants.HUNG_LOGGER_PRINT_ONCE,
hungloggerprintonce.toString());
attrList.put(ResourceConstants.HUNG_LOGGER_INITIAL_DELAY_SECONDS, hungloggerinitialdelayseconds.toString());
attrList.put(ResourceConstants.HUNG_LOGGER_INTERVAL_SECONDS, hungloggerintervalseconds.toString());
attrList.put(ResourceConstants.CORE_POOL_SIZE,
corepoolsize.toString());
attrList.put(ResourceConstants.KEEP_ALIVE_SECONDS,
keepaliveseconds.toString());
attrList.put(ResourceConstants.THREAD_LIFETIME_SECONDS,
threadlifetimeseconds.toString());
attrList.put(ServerTags.DESCRIPTION, description);
attrList.put(ResourceConstants.ENABLED, enabled.toString());
attrList.put(JNDI_NAME, jndiName);
attrList.put(CONTEXT_INFO_ENABLED, contextinfoenabled.toString());
attrList.put(CONTEXT_INFO, contextinfo);
attrList.put(THREAD_PRIORITY, threadpriority.toString());
attrList.put(LONG_RUNNING_TASKS, longrunningtasks.toString());
attrList.put(HUNG_AFTER_SECONDS, hungafterseconds.toString());
attrList.put(HUNG_LOGGER_PRINT_ONCE, hungloggerprintonce.toString());
attrList.put(HUNG_LOGGER_INITIAL_DELAY_SECONDS, hungloggerinitialdelayseconds.toString());
attrList.put(HUNG_LOGGER_INTERVAL_SECONDS, hungloggerintervalseconds.toString());
attrList.put(CORE_POOL_SIZE, corepoolsize.toString());
attrList.put(KEEP_ALIVE_SECONDS, keepaliveseconds.toString());
attrList.put(THREAD_LIFETIME_SECONDS, threadlifetimeseconds.toString());
attrList.put(DESCRIPTION, description);
attrList.put(ENABLED, enabled.toString());
}
}
Loading