Search in sources :

Example 16 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class ConnectionDefinitionAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    PathAddress path = context.getCurrentAddress();
    final String jndiName = JNDINAME.resolveModelAttribute(context, operation).asString();
    final String raName = path.getParent().getLastElement().getValue();
    final String archiveOrModuleName;
    ModelNode raModel = context.readResourceFromRoot(path.getParent()).getModel();
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean();
    if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    ModelNode resourceModel = resource.getModel();
    final boolean elytronEnabled = ELYTRON_ENABLED.resolveModelAttribute(context, resourceModel).asBoolean();
    final boolean elytronRecoveryEnabled = RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, resourceModel).asBoolean();
    final ModelNode credentialReference = RECOVERY_CREDENTIAL_REFERENCE.resolveModelAttribute(context, resourceModel);
    // domains should only be defined when Elytron enabled is undefined or false (default value)
    if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT.getName()) && !elytronEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
    } else if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName()) && !elytronEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
    } else if (resourceModel.hasDefined(SECURITY_DOMAIN.getName()) && elytronEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
    } else if (resourceModel.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()) && elytronEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
    }
    if (resourceModel.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()) && !elytronRecoveryEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    } else if (resourceModel.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()) && elytronRecoveryEnabled) {
        throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    }
    if (raModel.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString();
    } else {
        archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString();
    }
    final String poolName = PathAddress.pathAddress(address).getLastElement().getValue();
    try {
        ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName, poolName);
        ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName);
        final ModifiableResourceAdapter ravalue = ((ModifiableResourceAdapter) context.getServiceRegistry(false).getService(raServiceName).getValue());
        boolean isXa = ravalue.getTransactionSupport() == TransactionSupportEnum.XATransaction;
        final ServiceTarget serviceTarget = context.getServiceTarget();
        final ConnectionDefinitionService service = new ConnectionDefinitionService();
        service.getConnectionDefinitionSupplierInjector().inject(() -> RaOperationUtil.buildConnectionDefinitionObject(context, resourceModel, poolName, isXa, service.getCredentialSourceSupplier().getOptionalValue()));
        final ServiceBuilder<ModifiableConnDef> cdServiceBuilder = serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector());
        // and this should be changed to use a proper capability in the future.
        if (elytronEnabled) {
            if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT.getName())) {
                cdServiceBuilder.addDependency(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, AUTHENTICATION_CONTEXT.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class));
            } else if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName())) {
                cdServiceBuilder.addDependency(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, AUTHENTICATION_CONTEXT_AND_APPLICATION.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class));
            }
        }
        if (elytronRecoveryEnabled) {
            if (resourceModel.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName())) {
                cdServiceBuilder.addDependency(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, RECOVERY_AUTHENTICATION_CONTEXT.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class));
            }
        }
        if (credentialReference.isDefined()) {
            service.getCredentialSourceSupplier().inject(CredentialReference.getCredentialSourceSupplier(context, RECOVERY_CREDENTIAL_REFERENCE, resourceModel, cdServiceBuilder));
        }
        // Install the ConnectionDefinitionService
        cdServiceBuilder.install();
        ServiceRegistry registry = context.getServiceRegistry(true);
        final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName));
        Activation raxml = (Activation) RaxmlController.getValue();
        ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, raName);
        String bootStrapCtxName = DEFAULT_NAME;
        if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
            bootStrapCtxName = raxml.getBootstrapContext();
        }
        ConnectionDefinitionStatisticsService connectionDefinitionStatisticsService = new ConnectionDefinitionStatisticsService(context.getResourceRegistrationForUpdate(), jndiName, poolName, statsEnabled);
        ServiceBuilder statsServiceBuilder = serviceTarget.addService(serviceName.append(ConnectorServices.STATISTICS_SUFFIX), connectionDefinitionStatisticsService);
        statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), connectionDefinitionStatisticsService.getBootstrapContextInjector()).addDependency(deploymentServiceName, connectionDefinitionStatisticsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
        PathElement peCD = PathElement.pathElement(Constants.STATISTICS_NAME, "pool");
        final Resource cdResource = new IronJacamarResource.IronJacamarRuntimeResource();
        resource.registerChild(peCD, cdResource);
        PathElement peExtended = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
        final Resource extendedResource = new IronJacamarResource.IronJacamarRuntimeResource();
        resource.registerChild(peExtended, extendedResource);
    } catch (Exception e) {
        throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("ConnectionDefinition", operation, e.getLocalizedMessage())));
    }
}
Also used : AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) ServiceTarget(org.jboss.msc.service.ServiceTarget) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ConnectionDefinitionStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.ConnectionDefinitionStatisticsService) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 17 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class RaAdd method performRuntime.

@Override
public void performRuntime(final OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode model = resource.getModel();
    // domains/application attributes should only be defined when Elytron enabled is undefined or false (default value)
    if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(SECURITY_DOMAIN.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(APPLICATION.getName(), ELYTRON_ENABLED.getName());
    } else {
        if (model.hasDefined(AUTHENTICATION_CONTEXT.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
    }
    // do the same for recovery security attributes
    if (RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    } else {
        if (model.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    }
    // Compensating is remove
    final String name = context.getCurrentAddressValue();
    final String archiveOrModuleName;
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (model.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
    } else {
        archiveOrModuleName = model.get(MODULE.getName()).asString();
    }
    ModifiableResourceAdapter resourceAdapter = RaOperationUtil.buildResourceAdaptersObject(name, context, operation, archiveOrModuleName);
    List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>();
    if (model.get(ARCHIVE.getName()).isDefined()) {
        RaOperationUtil.installRaServices(context, name, resourceAdapter, newControllers);
    } else {
        RaOperationUtil.installRaServicesAndDeployFromModule(context, name, resourceAdapter, archiveOrModuleName, newControllers);
        if (context.isBooting()) {
            context.addStep(new OperationStepHandler() {

                public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException {
                    //Next lines activate configuration on module deployed rar
                    //in case there is 2 different resource-adapter config using same module deployed rar
                    // a Deployment sercivice could be already present and need a restart to consider also this
                    //newly added configuration
                    ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, name);
                    if (restartedServiceName == null) {
                        RaOperationUtil.activate(context, name, archiveOrModuleName);
                    }
                    context.completeStep(new OperationContext.RollbackHandler() {

                        @Override
                        public void handleRollback(OperationContext context, ModelNode operation) {
                            try {
                                RaOperationUtil.removeIfActive(context, archiveOrModuleName, name);
                            } catch (OperationFailedException e) {
                            }
                        }
                    });
                }
            }, OperationContext.Stage.RUNTIME);
        }
    }
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, name));
    Activation raxml = (Activation) RaxmlController.getValue();
    ServiceName serviceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, name);
    String bootStrapCtxName = DEFAULT_NAME;
    if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
        bootStrapCtxName = raxml.getBootstrapContext();
    }
    ResourceAdapterStatisticsService raStatsService = new ResourceAdapterStatisticsService(context.getResourceRegistrationForUpdate(), name, statsEnabled);
    ServiceBuilder statsServiceBuilder = context.getServiceTarget().addService(ServiceName.of(ConnectorServices.RA_SERVICE, name).append(ConnectorServices.STATISTICS_SUFFIX), raStatsService);
    statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), raStatsService.getBootstrapContextInjector()).addDependency(serviceName, raStatsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
    final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource();
    resource.registerChild(peStats, statsResource);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ResourceAdapterStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.ResourceAdapterStatisticsService) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 18 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class WorkManagerAdd method performRuntime.

@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
    String name = JcaWorkManagerDefinition.WmParameters.NAME.getAttribute().resolveModelAttribute(context, resource.getModel()).asString();
    boolean elytronEnabled = JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().resolveModelAttribute(context, resource.getModel()).asBoolean();
    ServiceTarget serviceTarget = context.getServiceTarget();
    NamedWorkManager wm = new NamedWorkManager(name, elytronEnabled);
    WorkManagerService wmService = new WorkManagerService(wm);
    ServiceBuilder builder = serviceTarget.addService(ConnectorServices.WORKMANAGER_SERVICE.append(name), wmService);
    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.ON_DEMAND).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();
    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);
}
Also used : NamedWorkManager(org.jboss.as.connector.services.workmanager.NamedWorkManager) WorkManagerService(org.jboss.as.connector.services.workmanager.WorkManagerService) WorkManagerStatisticsService(org.jboss.as.connector.services.workmanager.statistics.WorkManagerStatisticsService) PathElement(org.jboss.as.controller.PathElement) ServiceTarget(org.jboss.msc.service.ServiceTarget) Resource(org.jboss.as.controller.registry.Resource) IronJacamarResource(org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 19 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class AdminObjectAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    PathAddress path = PathAddress.pathAddress(address);
    final String raName = context.getCurrentAddress().getParent().getLastElement().getValue();
    final String archiveOrModuleName;
    ModelNode raModel = context.readResourceFromRoot(path.subAddress(0, path.size() - 1)).getModel();
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean();
    if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (raModel.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString();
    } else {
        archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString();
    }
    final String poolName = PathAddress.pathAddress(address).getLastElement().getValue();
    final ModifiableAdminObject adminObjectValue;
    try {
        adminObjectValue = RaOperationUtil.buildAdminObjects(context, operation, poolName);
    } catch (ValidateException e) {
        throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("AdminObject", operation, e.getLocalizedMessage())));
    }
    ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName, poolName);
    ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName);
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final AdminObjectService service = new AdminObjectService(adminObjectValue);
    serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector()).install();
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName));
    Activation raxml = (Activation) RaxmlController.getValue();
    ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, raName);
    String bootStrapCtxName = DEFAULT_NAME;
    if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
        bootStrapCtxName = raxml.getBootstrapContext();
    }
    AdminObjectStatisticsService adminObjectStatisticsService = new AdminObjectStatisticsService(context.getResourceRegistrationForUpdate(), poolName, statsEnabled);
    ServiceBuilder statsServiceBuilder = serviceTarget.addService(serviceName.append(ConnectorServices.STATISTICS_SUFFIX), adminObjectStatisticsService);
    statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), adminObjectStatisticsService.getBootstrapContextInjector()).addDependency(deploymentServiceName, adminObjectStatisticsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peAO = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
    final Resource aoResource = new IronJacamarResource.IronJacamarRuntimeResource();
    resource.registerChild(peAO, aoResource);
}
Also used : ValidateException(org.jboss.jca.common.api.validator.ValidateException) AdminObjectStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.AdminObjectStatisticsService) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 20 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class DefaultComponentViewConfigurator method configure.

public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final ProxyMetadataSource proxyReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.PROXY_REFLECTION_INDEX);
    //views
    for (ViewDescription view : description.getViews()) {
        Class<?> viewClass;
        try {
            viewClass = module.getClassLoader().loadClass(view.getViewClassName());
        } catch (ClassNotFoundException e) {
            throw EeLogger.ROOT_LOGGER.cannotLoadViewClass(e, view.getViewClassName(), configuration);
        }
        final ViewConfiguration viewConfiguration;
        final ProxyConfiguration proxyConfiguration = new ProxyConfiguration();
        if (viewClass.getName().startsWith("java.")) {
            proxyConfiguration.setProxyName("org.jboss.proxy.java.lang." + viewClass.getSimpleName() + "$$$view" + PROXY_ID.incrementAndGet());
        } else {
            proxyConfiguration.setProxyName(viewClass.getName() + "$$$view" + PROXY_ID.incrementAndGet());
        }
        proxyConfiguration.setClassLoader(module.getClassLoader());
        proxyConfiguration.setProtectionDomain(viewClass.getProtectionDomain());
        proxyConfiguration.setMetadataSource(proxyReflectionIndex);
        if (view.isSerializable()) {
            proxyConfiguration.addAdditionalInterface(Serializable.class);
            if (view.isUseWriteReplace()) {
                proxyConfiguration.addAdditionalInterface(WriteReplaceInterface.class);
            }
        }
        //we define it in the modules class loader to prevent permgen leaks
        if (viewClass.isInterface()) {
            proxyConfiguration.setSuperClass(Object.class);
            proxyConfiguration.addAdditionalInterface(viewClass);
            viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration));
        } else {
            proxyConfiguration.setSuperClass(viewClass);
            viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration));
        }
        for (final ViewConfigurator configurator : view.getConfigurators()) {
            configurator.configure(context, configuration, view, viewConfiguration);
        }
        configuration.getViews().add(viewConfiguration);
    }
    configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

        @Override
        public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
            for (final Map.Entry<ServiceName, ServiceBuilder.DependencyType> entry : description.getDependencies().entrySet()) {
                serviceBuilder.addDependency(entry.getValue(), entry.getKey());
            }
        }
    });
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ProxyFactory(org.jboss.invocation.proxy.ProxyFactory) ProxyMetadataSource(org.jboss.as.server.deployment.reflect.ProxyMetadataSource) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ProxyConfiguration(org.jboss.invocation.proxy.ProxyConfiguration) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

ServiceBuilder (org.jboss.msc.service.ServiceBuilder)34 ServiceName (org.jboss.msc.service.ServiceName)17 ServiceTarget (org.jboss.msc.service.ServiceTarget)15 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)11 ModelNode (org.jboss.dmr.ModelNode)10 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)8 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)8 InjectedValue (org.jboss.msc.value.InjectedValue)8 OperationContext (org.jboss.as.controller.OperationContext)7 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)7 Module (org.jboss.modules.Module)7 OperationFailedException (org.jboss.as.controller.OperationFailedException)6 Resource (org.jboss.as.controller.registry.Resource)6 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)6 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)6 HashMap (java.util.HashMap)5 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)5 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)5 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)5 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)5