Skip to content

Commit

Permalink
Descriptor generics
Browse files Browse the repository at this point in the history
- more concrete API

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Oct 15, 2022
1 parent 144c42c commit 555d177
Show file tree
Hide file tree
Showing 32 changed files with 1,016 additions and 1,865 deletions.
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
Expand Up @@ -17,21 +17,15 @@

package org.glassfish.concurrent.admin;

import static org.glassfish.resources.admin.cli.ResourceConstants.CONTEXT_INFO;
import static org.glassfish.resources.admin.cli.ResourceConstants.CONTEXT_INFO_DEFAULT_VALUE;
import static org.glassfish.resources.admin.cli.ResourceConstants.CONTEXT_INFO_ENABLED;
import static org.glassfish.resources.admin.cli.ResourceConstants.CORE_POOL_SIZE;
import static org.glassfish.resources.admin.cli.ResourceConstants.ENABLED;
import static org.glassfish.resources.admin.cli.ResourceConstants.HUNG_AFTER_SECONDS;
import static org.glassfish.resources.admin.cli.ResourceConstants.HUNG_LOGGER_INITIAL_DELAY_SECONDS;
import static org.glassfish.resources.admin.cli.ResourceConstants.HUNG_LOGGER_INTERVAL_SECONDS;
import static org.glassfish.resources.admin.cli.ResourceConstants.HUNG_LOGGER_PRINT_ONCE;
import static org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME;
import static org.glassfish.resources.admin.cli.ResourceConstants.KEEP_ALIVE_SECONDS;
import static org.glassfish.resources.admin.cli.ResourceConstants.LONG_RUNNING_TASKS;
import static org.glassfish.resources.admin.cli.ResourceConstants.SYSTEM_ALL_REQ;
import static org.glassfish.resources.admin.cli.ResourceConstants.THREAD_LIFETIME_SECONDS;
import static org.glassfish.resources.admin.cli.ResourceConstants.THREAD_PRIORITY;
import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
import com.sun.enterprise.config.serverbeans.BindableResource;
import com.sun.enterprise.config.serverbeans.Resource;
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;
Expand All @@ -51,15 +45,21 @@
import org.jvnet.hk2.config.TransactionFailure;
import org.jvnet.hk2.config.types.Property;

import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
import com.sun.enterprise.config.serverbeans.BindableResource;
import com.sun.enterprise.config.serverbeans.Resource;
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 static org.glassfish.resources.admin.cli.ResourceConstants.CONTEXT_INFO;
import static org.glassfish.resources.admin.cli.ResourceConstants.CONTEXT_INFO_DEFAULT_VALUE;
import static org.glassfish.resources.admin.cli.ResourceConstants.CONTEXT_INFO_ENABLED;
import static org.glassfish.resources.admin.cli.ResourceConstants.CORE_POOL_SIZE;
import static org.glassfish.resources.admin.cli.ResourceConstants.ENABLED;
import static org.glassfish.resources.admin.cli.ResourceConstants.HUNG_AFTER_SECONDS;
import static org.glassfish.resources.admin.cli.ResourceConstants.HUNG_LOGGER_INITIAL_DELAY_SECONDS;
import static org.glassfish.resources.admin.cli.ResourceConstants.HUNG_LOGGER_INTERVAL_SECONDS;
import static org.glassfish.resources.admin.cli.ResourceConstants.HUNG_LOGGER_PRINT_ONCE;
import static org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME;
import static org.glassfish.resources.admin.cli.ResourceConstants.KEEP_ALIVE_SECONDS;
import static org.glassfish.resources.admin.cli.ResourceConstants.LONG_RUNNING_TASKS;
import static org.glassfish.resources.admin.cli.ResourceConstants.SYSTEM_ALL_REQ;
import static org.glassfish.resources.admin.cli.ResourceConstants.THREAD_LIFETIME_SECONDS;
import static org.glassfish.resources.admin.cli.ResourceConstants.THREAD_PRIORITY;

/**
*
Expand Down Expand Up @@ -153,26 +153,26 @@ protected ResourceStatus isValid(Resources resources, boolean validateResourceRe
return resourcesHelper.validateBindableResourceForDuplicates(resources, jndiName, validateResourceRef, target, clazz);
}

protected void setAttributes(HashMap attributes, String target) {
jndiName = (String) attributes.get(JNDI_NAME);
description = (String) attributes.get(DESCRIPTION);
contextInfo = (String) attributes.get(CONTEXT_INFO);
contextInfoEnabled = (String) attributes.get(CONTEXT_INFO_ENABLED);
threadPriority = (String) attributes.get(THREAD_PRIORITY);
longRunningTasks = (String) attributes.get(LONG_RUNNING_TASKS);
hungAfterSeconds = (String) attributes.get(HUNG_AFTER_SECONDS);
hungLoggerPrintOnce = (String) attributes.get(HUNG_LOGGER_PRINT_ONCE);
hungLoggerInitialDelaySeconds = (String) attributes.get(HUNG_LOGGER_INITIAL_DELAY_SECONDS);
hungLoggerIntervalSeconds = (String) attributes.get(HUNG_LOGGER_INTERVAL_SECONDS);
corePoolSize = (String) attributes.get(CORE_POOL_SIZE);
keepAliveSeconds = (String) attributes.get(KEEP_ALIVE_SECONDS);
threadLifetimeSeconds = (String) attributes.get(THREAD_LIFETIME_SECONDS);
protected void setAttributes(Map<String, String> attributes, String target) {
jndiName = attributes.get(JNDI_NAME);
description = attributes.get(DESCRIPTION);
contextInfo = attributes.get(CONTEXT_INFO);
contextInfoEnabled = attributes.get(CONTEXT_INFO_ENABLED);
threadPriority = attributes.get(THREAD_PRIORITY);
longRunningTasks = attributes.get(LONG_RUNNING_TASKS);
hungAfterSeconds = attributes.get(HUNG_AFTER_SECONDS);
hungLoggerPrintOnce = attributes.get(HUNG_LOGGER_PRINT_ONCE);
hungLoggerInitialDelaySeconds = attributes.get(HUNG_LOGGER_INITIAL_DELAY_SECONDS);
hungLoggerIntervalSeconds = attributes.get(HUNG_LOGGER_INTERVAL_SECONDS);
corePoolSize = attributes.get(CORE_POOL_SIZE);
keepAliveSeconds = attributes.get(KEEP_ALIVE_SECONDS);
threadLifetimeSeconds = attributes.get(THREAD_LIFETIME_SECONDS);
if (target == null) {
enabled = (String) attributes.get(ENABLED);
enabled = attributes.get(ENABLED);
} else {
enabled = resourceUtil.computeEnabledValueForResourceBasedOnTarget((String)attributes.get(ENABLED), target);
enabled = resourceUtil.computeEnabledValueForResourceBasedOnTarget(attributes.get(ENABLED), target);
}
enabledValueForTarget = (String) attributes.get(ENABLED);
enabledValueForTarget = attributes.get(ENABLED);
}

protected ManagedExecutorServiceBase createResource(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
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 @@ -18,19 +19,21 @@

import com.sun.enterprise.config.serverbeans.Resources;
import com.sun.enterprise.config.serverbeans.ServerTags;

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

import org.glassfish.api.I18n;
import org.glassfish.concurrent.config.ManagedExecutorService;
import org.glassfish.concurrent.config.ManagedExecutorServiceBase;
import org.glassfish.resourcebase.resources.api.ResourceStatus;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.config.ConfiguredBy;
import org.jvnet.hk2.config.TransactionFailure;
import org.glassfish.resourcebase.resources.api.ResourceStatus;
import org.glassfish.concurrent.config.ManagedExecutorServiceBase;
import org.glassfish.concurrent.config.ManagedExecutorService;

import static org.glassfish.resources.admin.cli.ResourceConstants.*;

import java.util.HashMap;
import java.util.Properties;
import java.beans.PropertyVetoException;
import static org.glassfish.resources.admin.cli.ResourceConstants.MAXIMUM_POOL_SIZE;
import static org.glassfish.resources.admin.cli.ResourceConstants.TASK_QUEUE_CAPACITY;

/**
*
Expand All @@ -46,10 +49,10 @@ public class ManagedExecutorServiceManager extends ManagedExecutorServiceBaseMan
private String taskQueueCapacity = ""+Integer.MAX_VALUE;

@Override
protected void setAttributes(HashMap attributes, String target) {
protected void setAttributes(Map<String, String> attributes, String target) {
super.setAttributes(attributes, target);
maximumPoolSize = (String) attributes.get(MAXIMUM_POOL_SIZE);
taskQueueCapacity = (String) attributes.get(TASK_QUEUE_CAPACITY);
maximumPoolSize = attributes.get(MAXIMUM_POOL_SIZE);
taskQueueCapacity = attributes.get(TASK_QUEUE_CAPACITY);
}

@Override
Expand All @@ -69,6 +72,7 @@ protected ResourceStatus isValid(Resources resources, boolean validateResourceRe
return super.isValid(resources, validateResourceRef, target);
}

@Override
protected ManagedExecutorServiceBase createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
ManagedExecutorService managedExecutorService = param.createChild(ManagedExecutorService.class);
setAttributesOnConfigBean(managedExecutorService, properties);
Expand All @@ -77,6 +81,7 @@ protected ManagedExecutorServiceBase createConfigBean(Resources param, Propertie
return managedExecutorService;
}

@Override
public String getResourceType () {
return ServerTags.MANAGED_EXECUTOR_SERVICE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2022 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
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.concurrent.runtime.deployer;

import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
import com.sun.enterprise.config.serverbeans.Application;
import com.sun.enterprise.config.serverbeans.Resource;
import com.sun.enterprise.config.serverbeans.Resources;
import com.sun.enterprise.deployment.ResourceDescriptor;

import jakarta.inject.Inject;

import java.util.Collection;

import org.glassfish.api.invocation.ComponentInvocation;
import org.glassfish.api.invocation.InvocationManager;
import org.glassfish.deployment.common.JavaEEResourceType;
import org.glassfish.resourcebase.resources.api.ResourceConflictException;
import org.glassfish.resourcebase.resources.api.ResourceDeployer;
import org.glassfish.resourcebase.resources.api.ResourceInfo;

import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.deriveResourceName;

/**
* @param <D> {@link ResourceDescriptor} managed by this class.
*
* @author David Matejcek
*/
public abstract class ConcurrencyDeployer<D extends ResourceDescriptor> implements ResourceDeployer<D> {

@Inject
private InvocationManager invocationManager;

/**
* Returns false - cannot be deployed before application.
*/
@Override
public final boolean canDeploy(boolean postApplicationDeployment, Collection<Resource> allResources, Resource resource) {
return false;
}


/**
* Does nothing
*/
@Override
public final void validatePreservedResource(Application oldApp, Application newApp, Resource resource,
Resources allResources) throws ResourceConflictException {
// FIXME: remove finals
}


/**
* Same as {@link #deployResource(Object)}
*/
@Override
public final void enableResource(D resource) throws Exception {
deployResource(resource);
}


/**
* Same as {@link #undeployResource(Object)}
*/
@Override
public final void disableResource(D resource) throws Exception {
undeployResource(resource);
}


/**
* Create {@link ResourceInfo} instance.
* Resource name is resolved by {@link ConnectorsUtil#deriveResourceName(String, String, JavaEEResourceType)}
*
* @param descriptor
* @param applicatioName
* @param moduleName
* @return {@link ResourceInfo}
*/
protected ResourceInfo toResourceInfo(final D descriptor, String applicatioName, String moduleName) {
return new ResourceInfo(toResourceName(descriptor), applicatioName, moduleName);
}


/**
* Create {@link ResourceInfo} instance.
* Resource name is resolved by {@link ConnectorsUtil#deriveResourceName(String, String, JavaEEResourceType)}
*
* @param descriptor
* @return {@link ResourceInfo}
*/
protected ResourceInfo toResourceInfo(final D descriptor) {
ComponentInvocation invocation = invocationManager.getCurrentInvocation();
return new ResourceInfo(toResourceName(descriptor), invocation.getAppName(), invocation.getModuleName());
}


protected String toResourceName(D descriptor) {
return deriveResourceName(descriptor.getResourceId(), descriptor.getJndiName(), descriptor.getResourceType());
}
}

0 comments on commit 555d177

Please sign in to comment.