Search in sources :

Example 1 with ManagedExecutorService

use of org.glassfish.concurrent.config.ManagedExecutorService in project Payara by payara.

the class ManagedExecutorServiceBaseManager method delete.

public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
    if (jndiName == null) {
        String msg = localStrings.getLocalString("managed.executor.service.noJndiName", "No JNDI name defined for managed executor service.");
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("managed.scheduled.executor.service.noJndiName", "No JNDI name defined for managed scheduled executor service.");
        }
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    Resource resource = null;
    if (getResourceType().equals(ServerTags.MANAGED_EXECUTOR_SERVICE)) {
        resource = ConnectorsUtil.getResourceByName(resources, ManagedExecutorService.class, jndiName);
    } else if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
        resource = ConnectorsUtil.getResourceByName(resources, ManagedScheduledExecutorService.class, jndiName);
    }
    // ensure we already have this resource
    if (resource == null) {
        String msg = localStrings.getLocalString("delete.managed.executor.service.notfound", "A managed executor service named {0} does not exist.", jndiName);
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.notfound", "A managed scheduled executor service named {0} does not exist.", jndiName);
        }
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    if (SYSTEM_ALL_REQ.equals(resource.getObjectType())) {
        String msg = localStrings.getLocalString("delete.concurrent.resource.notAllowed", "The {0} resource cannot be deleted as it is required to be configured in the system.", jndiName);
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    if (environment.isDas()) {
        if ("domain".equals(target)) {
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
                String msg = localStrings.getLocalString("delete.managed.executor.service.resource-ref.exist", "This managed executor service [ {0} ] is referenced in an instance/cluster target, use delete-resource-ref on appropriate target", jndiName);
                if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                    msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.resource-ref.exist", "This managed scheduled executor service [ {0} ] is referenced in an instance/cluster target, use delete-resource-ref on appropriate target", jndiName);
                }
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
        } else {
            if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
                String msg = localStrings.getLocalString("delete.managed.executor.service.no.resource-ref", "This managed executor service [ {0} ] is not referenced in target [ {1} ]", jndiName, target);
                if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                    msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.no.resource-ref", "This managed scheduled executor service [ {0} ] is not referenced in target [ {1} ]", jndiName, target);
                }
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
                String msg = localStrings.getLocalString("delete.managed.executor.service.multiple.resource-refs", "This managed executor service [ {0} ] is referenced in multiple instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
                if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                    msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.multiple.resource-refs", "This managed scheduled executor service [ {0} ] is referenced in multiple instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
                }
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
        }
    }
    try {
        // delete resource-ref
        resourceUtil.deleteResourceRef(jndiName, target);
        // delete managed executor service
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                ManagedExecutorServiceBase resource = null;
                if (getResourceType().equals(ServerTags.MANAGED_EXECUTOR_SERVICE)) {
                    resource = (ManagedExecutorService) ConnectorsUtil.getResourceByName(resources, ManagedExecutorService.class, jndiName);
                } else {
                    resource = (ManagedScheduledExecutorService) ConnectorsUtil.getResourceByName(resources, ManagedScheduledExecutorService.class, jndiName);
                }
                return param.getResources().remove(resource);
            }
        }, resources) == null) {
            String msg = localStrings.getLocalString("delete.managed.executor.service.failed", "Managed executor service {0} deletion failed", jndiName);
            if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} deletion failed", jndiName);
            }
            return new ResourceStatus(ResourceStatus.FAILURE, msg);
        }
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("delete.managed.executor.service.failed", "Managed executor service {0} deletion failed ", jndiName);
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} deletion failed ", jndiName);
        }
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("delete.managed.executor.service.success", "Managed executor service {0} deleted successfully", jndiName);
    if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
        msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.success", "Managed scheduled executor service {0} deleted successfully", jndiName);
    }
    return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ManagedExecutorService(org.glassfish.concurrent.config.ManagedExecutorService) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Resource(com.sun.enterprise.config.serverbeans.Resource) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ManagedExecutorServiceBase(org.glassfish.concurrent.config.ManagedExecutorServiceBase) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 2 with ManagedExecutorService

use of org.glassfish.concurrent.config.ManagedExecutorService in project Payara by payara.

the class ManagedExecutorServiceDeployer method undeployResource.

@Override
public void undeployResource(Object resource) throws Exception {
    ManagedExecutorService managedExecutorServiceResource = (ManagedExecutorService) resource;
    ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(managedExecutorServiceResource);
    undeployResource(resource, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
Also used : ManagedExecutorService(org.glassfish.concurrent.config.ManagedExecutorService) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo)

Example 3 with ManagedExecutorService

use of org.glassfish.concurrent.config.ManagedExecutorService in project Payara by payara.

the class ListManagedExecutorServices method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        Collection<ManagedExecutorService> managedExecutorServices = domain.getResources().getResources(ManagedExecutorService.class);
        List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
        List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
        for (ManagedExecutorService managedExecutorService : managedExecutorServices) {
            String jndiName = managedExecutorService.getJndiName();
            if (bindableResourcesHelper.resourceExists(jndiName, target)) {
                ActionReport.MessagePart part = report.getTopMessagePart().addChild();
                part.setMessage(jndiName);
                Map<String, String> resourceNameMap = new HashMap<String, String>();
                String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
                if (logicalName != null) {
                    resourceNameMap.put("logical-jndi-name", logicalName);
                }
                resourceNameMap.put("name", jndiName);
                resourcesList.add(resourceNameMap);
            }
        }
        Properties extraProperties = new Properties();
        extraProperties.put("managedExecutorServices", resourcesList);
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.managed.executor.service.failed", "List managed executor services failed"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : DefaultResourceProxy(org.glassfish.api.naming.DefaultResourceProxy) ActionReport(org.glassfish.api.ActionReport) ManagedExecutorService(org.glassfish.concurrent.config.ManagedExecutorService) DefaultManagedExecutorService(org.glassfish.concurrent.runtime.deployer.DefaultManagedExecutorService)

Example 4 with ManagedExecutorService

use of org.glassfish.concurrent.config.ManagedExecutorService in project Payara by payara.

the class ManagedExecutorServiceManager method createConfigBean.

protected ManagedExecutorServiceBase createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
    ManagedExecutorService managedExecutorService = param.createChild(ManagedExecutorService.class);
    setAttributesOnConfigBean(managedExecutorService, properties);
    managedExecutorService.setMaximumPoolSize(maximumPoolSize);
    managedExecutorService.setTaskQueueCapacity(taskQueueCapacity);
    return managedExecutorService;
}
Also used : ManagedExecutorService(org.glassfish.concurrent.config.ManagedExecutorService)

Example 5 with ManagedExecutorService

use of org.glassfish.concurrent.config.ManagedExecutorService in project Payara by payara.

the class ManagedExecutorServiceDeployer method undeployResource.

@Override
public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
    ManagedExecutorService managedExecutorServiceRes = (ManagedExecutorService) resource;
    ResourceInfo resourceInfo = new ResourceInfo(managedExecutorServiceRes.getJndiName(), applicationName, moduleName);
    namingService.unpublishObject(resourceInfo, managedExecutorServiceRes.getJndiName());
    unregisterMonitorableComponent();
    // stop the runtime object
    concurrentRuntime.shutdownManagedExecutorService(managedExecutorServiceRes.getJndiName());
}
Also used : ManagedExecutorService(org.glassfish.concurrent.config.ManagedExecutorService) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo)

Aggregations

ManagedExecutorService (org.glassfish.concurrent.config.ManagedExecutorService)7 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)4 Resource (com.sun.enterprise.config.serverbeans.Resource)1 Resources (com.sun.enterprise.config.serverbeans.Resources)1 NamingException (javax.naming.NamingException)1 RefAddr (javax.naming.RefAddr)1 ActionReport (org.glassfish.api.ActionReport)1 DefaultResourceProxy (org.glassfish.api.naming.DefaultResourceProxy)1 ManagedExecutorServiceBase (org.glassfish.concurrent.config.ManagedExecutorServiceBase)1 DefaultManagedExecutorService (org.glassfish.concurrent.runtime.deployer.DefaultManagedExecutorService)1 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)1 SerializableObjectRefAddr (org.glassfish.resources.naming.SerializableObjectRefAddr)1 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1