use of org.glassfish.concurrent.config.ManagedThreadFactory in project Payara by payara.
the class ListManagedThreadFactories 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<ManagedThreadFactory> managedThreadFactories = domain.getResources().getResources(ManagedThreadFactory.class);
List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
for (ManagedThreadFactory managedThreadFactory : managedThreadFactories) {
String jndiName = managedThreadFactory.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("managedThreadFactories", resourcesList);
report.setExtraProperties(extraProperties);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("list.managed.thread.factory.failed", "List managed thread factories failed"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.concurrent.config.ManagedThreadFactory in project Payara by payara.
the class ManagedThreadFactoryManager method createResource.
private ManagedThreadFactory createResource(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
ManagedThreadFactory newResource = createConfigBean(param, properties);
param.getResources().add(newResource);
return newResource;
}
use of org.glassfish.concurrent.config.ManagedThreadFactory in project Payara by payara.
the class ManagedThreadFactoryDeployer method deployResource.
@Override
public void deployResource(Object resource) throws Exception {
ManagedThreadFactory ManagedThreadFactoryResource = (ManagedThreadFactory) resource;
ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(ManagedThreadFactoryResource);
deployResource(resource, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
use of org.glassfish.concurrent.config.ManagedThreadFactory in project Payara by payara.
the class ManagedThreadFactoryDeployer method undeployResource.
@Override
public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
ManagedThreadFactory managedThreadFactoryRes = (ManagedThreadFactory) resource;
ResourceInfo resourceInfo = new ResourceInfo(managedThreadFactoryRes.getJndiName(), applicationName, moduleName);
namingService.unpublishObject(resourceInfo, managedThreadFactoryRes.getJndiName());
// stop the runtime object
concurrentRuntime.shutdownManagedThreadFactory(managedThreadFactoryRes.getJndiName());
}
use of org.glassfish.concurrent.config.ManagedThreadFactory in project Payara by payara.
the class ManagedThreadFactoryManager method delete.
public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
if (jndiName == null) {
String msg = localStrings.getLocalString("managed.thread.factory.noJndiName", "No JNDI name defined for managed thread factory.");
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
Resource resource = ConnectorsUtil.getResourceByName(resources, ManagedThreadFactory.class, jndiName);
// ensure we already have this resource
if (resource == null) {
String msg = localStrings.getLocalString("delete.managed.thread.factory.notfound", "A managed thread factory 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.thread.factory.resource-ref.exist", "This managed thread factory [ {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.thread.factory.no.resource-ref", "This managed thread factory [ {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.thread.factory.multiple.resource-refs", "This managed thread factory [ {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-thread-factory
if (ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
ManagedThreadFactory resource = (ManagedThreadFactory) ConnectorsUtil.getResourceByName(resources, ManagedThreadFactory.class, jndiName);
return param.getResources().remove(resource);
}
}, resources) == null) {
String msg = localStrings.getLocalString("delete.managed.thread.factory.failed", "Managed thread factory {0} deletion failed", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("delete.managed.thread.factory.failed", "Managed thread factory {0} deletion failed ", jndiName);
ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
status.setException(tfe);
return status;
}
String msg = localStrings.getLocalString("delete.managed.thread.factory.success", "Managed thread factory {0} deleted successfully", jndiName);
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Aggregations