Search in sources :

Example 1 with PingTime

use of org.jboss.jca.core.workmanager.selector.PingTime in project wildfly by wildfly.

the class DistributedWorkManagerAdd method performRuntime.

@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
    ModelNode model = resource.getModel();
    String name = JcaDistributedWorkManagerDefinition.DWmParameters.NAME.getAttribute().resolveModelAttribute(context, model).asString();
    boolean elytronEnabled = JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().resolveModelAttribute(context, resource.getModel()).asBoolean();
    String policy = JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute().resolveModelAttribute(context, model).asString();
    String selector = JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR.getAttribute().resolveModelAttribute(context, model).asString();
    ServiceTarget serviceTarget = context.getServiceTarget();
    NamedDistributedWorkManager namedDistributedWorkManager = new NamedDistributedWorkManager(name, elytronEnabled);
    if (policy != null && !policy.trim().isEmpty()) {
        switch(JcaDistributedWorkManagerDefinition.PolicyValue.valueOf(policy)) {
            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(policy);
        }
        Injection injector = new Injection();
        for (Map.Entry<String, String> entry : ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute()).unwrap(context, model).entrySet()) {
            try {
                injector.inject(namedDistributedWorkManager.getPolicy(), entry.getKey(), entry.getValue());
            } catch (Exception e) {
                ROOT_LOGGER.unsupportedPolicyOption(entry.getKey());
            }
        }
    } else {
        namedDistributedWorkManager.setPolicy(new WaterMark());
    }
    if (selector != null && !selector.trim().isEmpty()) {
        switch(JcaDistributedWorkManagerDefinition.SelectorValue.valueOf(selector)) {
            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(selector);
        }
        Injection injector = new Injection();
        for (Map.Entry<String, String> entry : ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR_OPTIONS.getAttribute()).unwrap(context, model).entrySet()) {
            try {
                injector.inject(namedDistributedWorkManager.getSelector(), entry.getKey(), entry.getValue());
            } catch (Exception e) {
                ROOT_LOGGER.unsupportedSelectorOption(entry.getKey());
            }
        }
    } else {
        namedDistributedWorkManager.setSelector(new PingTime());
    }
    DistributedWorkManagerService wmService = new DistributedWorkManagerService(namedDistributedWorkManager);
    ServiceBuilder<NamedDistributedWorkManager> builder = serviceTarget.addService(ConnectorServices.WORKMANAGER_SERVICE.append(name), wmService);
    builder.addDependency(JGroupsDefaultRequirement.CHANNEL_FACTORY.getServiceName(context), ChannelFactory.class, wmService.getJGroupsChannelFactoryInjector());
    builder.addDependency(ServiceBuilder.DependencyType.OPTIONAL, ThreadsServices.EXECUTOR.append(WORKMANAGER_LONG_RUNNING).append(name), Executor.class, wmService.getExecutorLongInjector());
    builder.addDependency(ThreadsServices.EXECUTOR.append(WORKMANAGER_SHORT_RUNNING).append(name), Executor.class, wmService.getExecutorShortInjector());
    builder.addDependency(TxnServices.JBOSS_TXN_CONTEXT_XA_TERMINATOR, JBossContextXATerminator.class, wmService.getXaTerminatorInjector()).setInitialMode(ServiceController.Mode.ACTIVE).install();
    WorkManagerStatisticsService wmStatsService = new WorkManagerStatisticsService(context.getResourceRegistrationForUpdate(), name, true);
    serviceTarget.addService(ConnectorServices.WORKMANAGER_STATS_SERVICE.append(name), wmStatsService).addDependency(ConnectorServices.WORKMANAGER_SERVICE.append(name), WorkManager.class, wmStatsService.getWorkManagerInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    DistributedWorkManagerStatisticsService dwmStatsService = new DistributedWorkManagerStatisticsService(context.getResourceRegistrationForUpdate(), name, true);
    serviceTarget.addService(ConnectorServices.DISTRIBUTED_WORKMANAGER_STATS_SERVICE.append(name), dwmStatsService).addDependency(ConnectorServices.WORKMANAGER_SERVICE.append(name), DistributedWorkManager.class, dwmStatsService.getDistributedWorkManagerInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peDistributedWm = PathElement.pathElement(org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_NAME, "distributed");
    PathElement peLocaldWm = PathElement.pathElement(org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_NAME, "local");
    final Resource wmResource = new IronJacamarResource.IronJacamarRuntimeResource();
    if (!resource.hasChild(peLocaldWm))
        resource.registerChild(peLocaldWm, wmResource);
    final Resource dwmResource = new IronJacamarResource.IronJacamarRuntimeResource();
    if (!resource.hasChild(peDistributedWm))
        resource.registerChild(peDistributedWm, dwmResource);
}
Also used : DistributedWorkManagerService(org.jboss.as.connector.services.workmanager.DistributedWorkManagerService) DistributedWorkManagerStatisticsService(org.jboss.as.connector.services.workmanager.statistics.DistributedWorkManagerStatisticsService) WorkManagerStatisticsService(org.jboss.as.connector.services.workmanager.statistics.WorkManagerStatisticsService) ServiceTarget(org.jboss.msc.service.ServiceTarget) Resource(org.jboss.as.controller.registry.Resource) IronJacamarResource(org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource) 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) MaxFreeThreads(org.jboss.jca.core.workmanager.selector.MaxFreeThreads) PathElement(org.jboss.as.controller.PathElement) Never(org.jboss.jca.core.workmanager.policy.Never) Always(org.jboss.jca.core.workmanager.policy.Always) DistributedWorkManagerStatisticsService(org.jboss.as.connector.services.workmanager.statistics.DistributedWorkManagerStatisticsService) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Example 2 with PingTime

use of org.jboss.jca.core.workmanager.selector.PingTime 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)

Aggregations

Map (java.util.Map)2 NamedDistributedWorkManager (org.jboss.as.connector.services.workmanager.NamedDistributedWorkManager)2 Injection (org.jboss.as.connector.util.Injection)2 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 ModelNode (org.jboss.dmr.ModelNode)2 Always (org.jboss.jca.core.workmanager.policy.Always)2 Never (org.jboss.jca.core.workmanager.policy.Never)2 WaterMark (org.jboss.jca.core.workmanager.policy.WaterMark)2 FirstAvailable (org.jboss.jca.core.workmanager.selector.FirstAvailable)2 MaxFreeThreads (org.jboss.jca.core.workmanager.selector.MaxFreeThreads)2 PingTime (org.jboss.jca.core.workmanager.selector.PingTime)2 DistributedWorkManagerService (org.jboss.as.connector.services.workmanager.DistributedWorkManagerService)1 DistributedWorkManagerStatisticsService (org.jboss.as.connector.services.workmanager.statistics.DistributedWorkManagerStatisticsService)1 WorkManagerStatisticsService (org.jboss.as.connector.services.workmanager.statistics.WorkManagerStatisticsService)1 IronJacamarResource (org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource)1 PathElement (org.jboss.as.controller.PathElement)1 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)1 Resource (org.jboss.as.controller.registry.Resource)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1