Search in sources :

Example 1 with PropertiesAttributeDefinition

use of org.jboss.as.controller.PropertiesAttributeDefinition in project wildfly by wildfly.

the class JcaDistributedWorkManagerWriteHandler method applyUpdateToRuntime.

@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<JcaSubsystemConfiguration> jcaSubsystemConfigurationHandbackHolder) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    final String name = PathAddress.pathAddress(address).getLastElement().getValue();
    Object wm = context.getServiceRegistry(true).getService(ConnectorServices.WORKMANAGER_SERVICE.append(name)).getValue();
    if (wm == null || !(wm instanceof NamedDistributedWorkManager)) {
        throw ConnectorLogger.ROOT_LOGGER.failedToFindDistributedWorkManager(name);
    }
    NamedDistributedWorkManager namedDistributedWorkManager = (NamedDistributedWorkManager) wm;
    Injection injector = new Injection();
    if (attributeName.equals(JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute().getName())) {
        switch(JcaDistributedWorkManagerDefinition.PolicyValue.valueOf(resolvedValue.asString())) {
            case NEVER:
                {
                    namedDistributedWorkManager.setPolicy(new Never());
                    break;
                }
            case ALWAYS:
                {
                    namedDistributedWorkManager.setPolicy(new Always());
                    break;
                }
            case WATERMARK:
                {
                    namedDistributedWorkManager.setPolicy(new WaterMark());
                    break;
                }
            default:
                {
                    throw ROOT_LOGGER.unsupportedPolicy(resolvedValue.asString());
                }
        }
    } else if (attributeName.equals(JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR.getAttribute().getName())) {
        switch(JcaDistributedWorkManagerDefinition.SelectorValue.valueOf(resolvedValue.asString())) {
            case FIRST_AVAILABLE:
                {
                    namedDistributedWorkManager.setSelector(new FirstAvailable());
                    break;
                }
            case MAX_FREE_THREADS:
                {
                    namedDistributedWorkManager.setSelector(new MaxFreeThreads());
                    break;
                }
            case PING_TIME:
                {
                    namedDistributedWorkManager.setSelector(new PingTime());
                    break;
                }
            default:
                {
                    throw ROOT_LOGGER.unsupportedSelector(resolvedValue.asString());
                }
        }
    } else if (attributeName.equals(JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute().getName()) && namedDistributedWorkManager.getPolicy() != null) {
        for (Map.Entry<String, String> entry : ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute()).unwrap(context, operation).entrySet()) {
            try {
                injector.inject(namedDistributedWorkManager.getPolicy(), entry.getKey(), entry.getValue());
            } catch (Exception e) {
                ROOT_LOGGER.unsupportedPolicyOption(entry.getKey());
            }
        }
    } else if (attributeName.equals(JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR_OPTIONS.getAttribute().getName())) {
        for (Map.Entry<String, String> entry : ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR_OPTIONS.getAttribute()).unwrap(context, operation).entrySet()) {
            try {
                injector.inject(namedDistributedWorkManager.getSelector(), entry.getKey(), entry.getValue());
            } catch (Exception e) {
                ROOT_LOGGER.unsupportedSelectorOption(entry.getKey());
            }
        }
    }
    return false;
}
Also used : Injection(org.jboss.as.connector.util.Injection) PingTime(org.jboss.jca.core.workmanager.selector.PingTime) FirstAvailable(org.jboss.jca.core.workmanager.selector.FirstAvailable) WaterMark(org.jboss.jca.core.workmanager.policy.WaterMark) OperationFailedException(org.jboss.as.controller.OperationFailedException) NamedDistributedWorkManager(org.jboss.as.connector.services.workmanager.NamedDistributedWorkManager) PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) MaxFreeThreads(org.jboss.jca.core.workmanager.selector.MaxFreeThreads) Never(org.jboss.jca.core.workmanager.policy.Never) Always(org.jboss.jca.core.workmanager.policy.Always) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Example 2 with PropertiesAttributeDefinition

use of org.jboss.as.controller.PropertiesAttributeDefinition in project wildfly by wildfly.

the class XaDataSourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    if (deployed) {
        for (final SimpleAttributeDefinition attribute : XA_DATASOURCE_ATTRIBUTE) {
            SimpleAttributeDefinition runtimeAttribute = new SimpleAttributeDefinitionBuilder(attribute).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build();
            resourceRegistration.registerReadOnlyAttribute(runtimeAttribute, XMLXaDataSourceRuntimeHandler.INSTANCE);
        }
        for (final PropertiesAttributeDefinition attribute : XA_DATASOURCE_PROPERTIES_ATTRIBUTES) {
            PropertiesAttributeDefinition runtimeAttribute = new PropertiesAttributeDefinition.Builder(attribute).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build();
            resourceRegistration.registerReadOnlyAttribute(runtimeAttribute, XMLXaDataSourceRuntimeHandler.INSTANCE);
        }
    } else {
        ReloadRequiredWriteAttributeHandler reloadRequiredWriteHandler = new ReloadRequiredWriteAttributeHandler(XA_DATASOURCE_ATTRIBUTE);
        for (final SimpleAttributeDefinition attribute : XA_DATASOURCE_ATTRIBUTE) {
            if (PoolConfigurationRWHandler.ATTRIBUTES.contains(attribute.getName())) {
                resourceRegistration.registerReadWriteAttribute(attribute, PoolConfigurationRWHandler.PoolConfigurationReadHandler.INSTANCE, PoolConfigurationRWHandler.LocalAndXaDataSourcePoolConfigurationWriteHandler.INSTANCE);
            } else if (attribute.getName().equals(ENLISTMENT_TRACE.getName())) {
                resourceRegistration.registerReadWriteAttribute(attribute, null, new EnlistmentTraceAttributeWriteHandler());
            } else {
                resourceRegistration.registerReadWriteAttribute(attribute, null, reloadRequiredWriteHandler);
            }
        }
        ReloadRequiredWriteAttributeHandler reloadRequiredPropertiesWriteHandler = new ReloadRequiredWriteAttributeHandler(XA_DATASOURCE_PROPERTIES_ATTRIBUTES);
        for (final PropertiesAttributeDefinition attribute : XA_DATASOURCE_PROPERTIES_ATTRIBUTES) {
            if (PoolConfigurationRWHandler.ATTRIBUTES.contains(attribute.getName())) {
                resourceRegistration.registerReadWriteAttribute(attribute, PoolConfigurationRWHandler.PoolConfigurationReadHandler.INSTANCE, PoolConfigurationRWHandler.LocalAndXaDataSourcePoolConfigurationWriteHandler.INSTANCE);
            } else {
                resourceRegistration.registerReadWriteAttribute(attribute, null, reloadRequiredPropertiesWriteHandler);
            }
        }
    }
}
Also used : PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

Example 3 with PropertiesAttributeDefinition

use of org.jboss.as.controller.PropertiesAttributeDefinition in project wildfly by wildfly.

the class DataSourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    if (deployed) {
        for (final SimpleAttributeDefinition attribute : DATASOURCE_ATTRIBUTE) {
            SimpleAttributeDefinition runtimeAttribute = new SimpleAttributeDefinitionBuilder(attribute).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build();
            resourceRegistration.registerReadOnlyAttribute(runtimeAttribute, XMLDataSourceRuntimeHandler.INSTANCE);
        }
        for (final PropertiesAttributeDefinition attribute : DATASOURCE_PROPERTIES_ATTRIBUTES) {
            PropertiesAttributeDefinition runtimeAttribute = new PropertiesAttributeDefinition.Builder(attribute).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build();
            resourceRegistration.registerReadOnlyAttribute(runtimeAttribute, XMLDataSourceRuntimeHandler.INSTANCE);
        }
    } else {
        ReloadRequiredWriteAttributeHandler reloadRequiredWriteAttributeHandler = new ReloadRequiredWriteAttributeHandler(DATASOURCE_ATTRIBUTE);
        for (final SimpleAttributeDefinition attribute : DATASOURCE_ATTRIBUTE) {
            if (PoolConfigurationRWHandler.ATTRIBUTES.contains(attribute.getName())) {
                resourceRegistration.registerReadWriteAttribute(attribute, PoolConfigurationRWHandler.PoolConfigurationReadHandler.INSTANCE, PoolConfigurationRWHandler.LocalAndXaDataSourcePoolConfigurationWriteHandler.INSTANCE);
            } else if (attribute.getName().equals(ENLISTMENT_TRACE.getName())) {
                resourceRegistration.registerReadWriteAttribute(attribute, null, new EnlistmentTraceAttributeWriteHandler());
            } else {
                resourceRegistration.registerReadWriteAttribute(attribute, null, reloadRequiredWriteAttributeHandler);
            }
        }
        ReloadRequiredWriteAttributeHandler reloadRequiredPropertiesWriteHandler = new ReloadRequiredWriteAttributeHandler(DATASOURCE_PROPERTIES_ATTRIBUTES);
        for (final PropertiesAttributeDefinition attribute : DATASOURCE_PROPERTIES_ATTRIBUTES) {
            if (PoolConfigurationRWHandler.ATTRIBUTES.contains(attribute.getName())) {
                resourceRegistration.registerReadWriteAttribute(attribute, PoolConfigurationRWHandler.PoolConfigurationReadHandler.INSTANCE, PoolConfigurationRWHandler.LocalAndXaDataSourcePoolConfigurationWriteHandler.INSTANCE);
            } else {
                resourceRegistration.registerReadWriteAttribute(attribute, null, reloadRequiredPropertiesWriteHandler);
            }
        }
    }
}
Also used : PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

Example 4 with PropertiesAttributeDefinition

use of org.jboss.as.controller.PropertiesAttributeDefinition in project wildfly by wildfly.

the class IIOPSubsystemAdd method getResourceProperties.

private void getResourceProperties(final Properties properties, PersistentResourceDefinition resource, OperationContext context, ModelNode model) throws OperationFailedException {
    for (AttributeDefinition attrDefinition : resource.getAttributes()) {
        if (attrDefinition instanceof PropertiesAttributeDefinition) {
            PropertiesAttributeDefinition pad = (PropertiesAttributeDefinition) attrDefinition;
            ModelNode resolvedModelAttribute = attrDefinition.resolveModelAttribute(context, model);
            if (resolvedModelAttribute.isDefined()) {
                for (final Property prop : resolvedModelAttribute.asPropertyList()) {
                    properties.setProperty(prop.getName(), prop.getValue().asString());
                }
            }
            continue;
        }
        ModelNode resolvedModelAttribute = attrDefinition.resolveModelAttribute(context, model);
        //FIXME
        if (resolvedModelAttribute.isDefined()) {
            String name = attrDefinition.getName();
            String value = resolvedModelAttribute.asString();
            String openjdkProperty = PropertiesMap.PROPS_MAP.get(name);
            if (openjdkProperty != null) {
                name = openjdkProperty;
            }
            properties.setProperty(name, value);
        }
    }
}
Also used : PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Aggregations

PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)4 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)2 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)2 SimpleAttributeDefinitionBuilder (org.jboss.as.controller.SimpleAttributeDefinitionBuilder)2 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)2 ModelNode (org.jboss.dmr.ModelNode)2 Map (java.util.Map)1 NamedDistributedWorkManager (org.jboss.as.connector.services.workmanager.NamedDistributedWorkManager)1 Injection (org.jboss.as.connector.util.Injection)1 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 Property (org.jboss.dmr.Property)1 Always (org.jboss.jca.core.workmanager.policy.Always)1 Never (org.jboss.jca.core.workmanager.policy.Never)1 WaterMark (org.jboss.jca.core.workmanager.policy.WaterMark)1 FirstAvailable (org.jboss.jca.core.workmanager.selector.FirstAvailable)1 MaxFreeThreads (org.jboss.jca.core.workmanager.selector.MaxFreeThreads)1 PingTime (org.jboss.jca.core.workmanager.selector.PingTime)1