Search in sources :

Example 1 with Value

use of org.jboss.msc.value.Value in project wildfly by wildfly.

the class ParsedServiceDeploymentProcessor method addAttributes.

private void addAttributes(final JBossServiceAttributeConfig[] attributeConfigs, final List<ClassReflectionIndex> mBeanClassHierarchy, final MBeanServices mBeanServices, final ClassLoader classLoader) throws DeploymentUnitProcessingException {
    if (attributeConfigs != null) {
        final Service<Object> createDestroyService = mBeanServices.getCreateDestroyService();
        for (final JBossServiceAttributeConfig attributeConfig : attributeConfigs) {
            final String propertyName = attributeConfig.getName();
            final Inject injectConfig = attributeConfig.getInject();
            final ValueFactory valueFactoryConfig = attributeConfig.getValueFactory();
            if (injectConfig != null) {
                final Value<?> value = getValue(injectConfig);
                final Injector<Object> injector = getPropertyInjector(propertyName, mBeanClassHierarchy, createDestroyService, value);
                mBeanServices.addAttribute(injectConfig.getBeanName(), injector);
            } else if (valueFactoryConfig != null) {
                final Value<?> value = getValue(valueFactoryConfig, classLoader);
                final Injector<Object> injector = getPropertyInjector(propertyName, mBeanClassHierarchy, createDestroyService, value);
                mBeanServices.addAttribute(valueFactoryConfig.getBeanName(), injector);
            } else {
                final Value<?> value = getValue(attributeConfig, mBeanClassHierarchy);
                final Injector<Object> injector = getPropertyInjector(propertyName, mBeanClassHierarchy, createDestroyService, Values.injectedValue());
                mBeanServices.addInjectionValue(injector, value);
            }
        }
    }
}
Also used : Inject(org.jboss.as.service.descriptor.JBossServiceAttributeConfig.Inject) MethodInjector(org.jboss.msc.inject.MethodInjector) Injector(org.jboss.msc.inject.Injector) JBossServiceAttributeConfig(org.jboss.as.service.descriptor.JBossServiceAttributeConfig) Value(org.jboss.msc.value.Value) ImmediateValue(org.jboss.msc.value.ImmediateValue) MethodValue(org.jboss.msc.value.MethodValue) ValueFactory(org.jboss.as.service.descriptor.JBossServiceAttributeConfig.ValueFactory)

Example 2 with Value

use of org.jboss.msc.value.Value in project wildfly by wildfly.

the class ParsedServiceDeploymentProcessor method getValue.

private static Value<?> getValue(final ValueFactory valueFactory, final ClassLoader classLoader) throws DeploymentUnitProcessingException {
    final String methodName = valueFactory.getMethodName();
    final ValueFactoryParameter[] parameters = valueFactory.getParameters();
    final List<Class<?>> paramTypes = new ArrayList<Class<?>>(parameters.length);
    final List<Value<?>> paramValues = new ArrayList<Value<?>>(parameters.length);
    for (ValueFactoryParameter parameter : parameters) {
        final Class<?> attributeTypeValue = ReflectionUtils.getClass(parameter.getType(), classLoader);
        paramTypes.add(attributeTypeValue);
        paramValues.add(new ImmediateValue<Object>(newValue(attributeTypeValue, parameter.getValue())));
    }
    final Value<Method> methodValue = new InjectedBeanMethodValue(Values.injectedValue(), new InjectedBeanMethodValue.MethodFinder() {

        @Override
        public Method find(Class<?> clazz) {
            return ReflectionUtils.getMethod(clazz, methodName, paramTypes.toArray(new Class<?>[0]));
        }
    });
    return cached(new MethodValue<Object>(methodValue, Values.injectedValue(), paramValues));
}
Also used : ValueFactoryParameter(org.jboss.as.service.descriptor.JBossServiceAttributeConfig.ValueFactoryParameter) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Value(org.jboss.msc.value.Value) ImmediateValue(org.jboss.msc.value.ImmediateValue) MethodValue(org.jboss.msc.value.MethodValue)

Example 3 with Value

use of org.jboss.msc.value.Value in project wildfly by wildfly.

the class AssociationService method start.

@Override
public void start(final StartContext context) throws StartException {
    // todo suspendController
    // noinspection unchecked
    List<Map.Entry<ProtocolSocketBinding, Registry<String, List<ClientMapping>>>> clientMappingsRegistries = this.clientMappingsRegistries.isEmpty() ? Collections.emptyList() : new ArrayList<>(this.clientMappingsRegistries.size());
    for (Map.Entry<Value<ProtocolSocketBinding>, Value<Registry>> entry : this.clientMappingsRegistries) {
        clientMappingsRegistries.add(new SimpleImmutableEntry<>(entry.getKey().getValue(), entry.getValue().getValue()));
    }
    value = new AssociationImpl(deploymentRepositoryInjector.getValue(), clientMappingsRegistries);
    String ourNodeName = serverEnvironmentServiceInjector.getValue().getNodeName();
    // track deployments at an association level for local dispatchers to utilize
    moduleAvailabilityListener = value.registerModuleAvailabilityListener(new ModuleAvailabilityListener() {

        public void moduleAvailable(final List<EJBModuleIdentifier> modules) {
            synchronized (serviceLock) {
                ourModules.addAll(modules);
                cachedServiceURL = null;
            }
        }

        public void moduleUnavailable(final List<EJBModuleIdentifier> modules) {
            synchronized (serviceLock) {
                ourModules.removeAll(modules);
                cachedServiceURL = null;
            }
        }
    });
    // do this last
    mutableDiscoveryProvider.setDiscoveryProvider((serviceType, filterSpec, result) -> {
        ServiceURL serviceURL = this.cachedServiceURL;
        if (serviceURL == null) {
            synchronized (serviceLock) {
                serviceURL = this.cachedServiceURL;
                if (serviceURL == null) {
                    ServiceURL.Builder b = new ServiceURL.Builder();
                    b.setUri(Affinity.LOCAL.getUri()).setAbstractType("ejb").setAbstractTypeAuthority("jboss");
                    b.addAttribute(EJBClientContext.FILTER_ATTR_NODE, AttributeValue.fromString(ourNodeName));
                    for (Map.Entry<ProtocolSocketBinding, Registry<String, List<ClientMapping>>> entry : clientMappingsRegistries) {
                        Group group = entry.getValue().getGroup();
                        if (!group.isSingleton()) {
                            b.addAttribute(EJBClientContext.FILTER_ATTR_CLUSTER, AttributeValue.fromString(group.getName()));
                        }
                    }
                    for (EJBModuleIdentifier moduleIdentifier : ourModules) {
                        final String appName = moduleIdentifier.getAppName();
                        final String moduleName = moduleIdentifier.getModuleName();
                        final String distinctName = moduleIdentifier.getDistinctName();
                        if (distinctName.isEmpty()) {
                            if (appName.isEmpty()) {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(moduleName));
                            } else {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(appName + '/' + moduleName));
                            }
                        } else {
                            if (appName.isEmpty()) {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(moduleName + '/' + distinctName));
                            } else {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(appName + '/' + moduleName + '/' + distinctName));
                            }
                        }
                    }
                    serviceURL = this.cachedServiceURL = b.create();
                }
            }
        }
        if (serviceURL.satisfies(filterSpec)) {
            result.addMatch(serviceURL);
        }
        result.complete();
        return DiscoveryRequest.NULL;
    });
}
Also used : Group(org.wildfly.clustering.group.Group) EJBModuleIdentifier(org.jboss.ejb.client.EJBModuleIdentifier) Registry(org.wildfly.clustering.registry.Registry) ModuleAvailabilityListener(org.jboss.ejb.server.ModuleAvailabilityListener) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) ProtocolSocketBinding(org.jboss.as.network.ProtocolSocketBinding) Value(org.jboss.msc.value.Value) AttributeValue(org.wildfly.discovery.AttributeValue) InjectedValue(org.jboss.msc.value.InjectedValue) ServiceURL(org.wildfly.discovery.ServiceURL) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ClientMapping(org.jboss.as.network.ClientMapping) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 4 with Value

use of org.jboss.msc.value.Value in project wildfly by wildfly.

the class EjbInjectionSource method resolve.

/**
 * Checks if this Jakarta Enterprise Beans injection has been resolved yet, and if not resolves it.
 */
private void resolve() {
    if (!resolved) {
        synchronized (this) {
            if (!resolved) {
                final Set<ViewDescription> views = getViews();
                final Set<EJBViewDescription> ejbsForViewName = new HashSet<EJBViewDescription>();
                for (final ViewDescription view : views) {
                    if (view instanceof EJBViewDescription) {
                        final MethodIntf viewType = ((EJBViewDescription) view).getMethodIntf();
                        // @EJB injection *shouldn't* consider the @WebService endpoint view or MDBs
                        if (viewType == MethodIntf.SERVICE_ENDPOINT || viewType == MethodIntf.MESSAGE_ENDPOINT) {
                            continue;
                        }
                        ejbsForViewName.add((EJBViewDescription) view);
                    }
                }
                if (ejbsForViewName.isEmpty()) {
                    if (beanName == null) {
                        error = EjbLogger.ROOT_LOGGER.ejbNotFound(typeName, bindingName);
                    } else {
                        error = EjbLogger.ROOT_LOGGER.ejbNotFound(typeName, beanName, bindingName);
                    }
                } else if (ejbsForViewName.size() > 1) {
                    if (beanName == null) {
                        error = EjbLogger.ROOT_LOGGER.moreThanOneEjbFound(typeName, bindingName, ejbsForViewName);
                    } else {
                        error = EjbLogger.ROOT_LOGGER.moreThanOneEjbFound(typeName, beanName, bindingName, ejbsForViewName);
                    }
                } else {
                    final EJBViewDescription description = ejbsForViewName.iterator().next();
                    final EJBViewDescription ejbViewDescription = (EJBViewDescription) description;
                    if (ejbViewDescription.getMethodIntf() == MethodIntf.REMOTE || ejbViewDescription.getMethodIntf() == MethodIntf.HOME) {
                        final EJBComponentDescription componentDescription = (EJBComponentDescription) description.getComponentDescription();
                        final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
                        final String earApplicationName = moduleDescription.getEarApplicationName();
                        final Value<ClassLoader> viewClassLoader = new Value<ClassLoader>() {

                            @Override
                            public ClassLoader getValue() throws IllegalStateException, IllegalArgumentException {
                                final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
                                return module != null ? module.getClassLoader() : null;
                            }
                        };
                        remoteFactory = new RemoteViewManagedReferenceFactory(earApplicationName, moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), description.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
                    }
                    final ServiceName serviceName = description.getServiceName();
                    resolvedViewName = serviceName;
                }
                resolved = true;
            }
        }
    }
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) Value(org.jboss.msc.value.Value) Module(org.jboss.modules.Module) HashSet(java.util.HashSet)

Aggregations

Value (org.jboss.msc.value.Value)4 ArrayList (java.util.ArrayList)2 ImmediateValue (org.jboss.msc.value.ImmediateValue)2 MethodValue (org.jboss.msc.value.MethodValue)2 Method (java.lang.reflect.Method)1 AbstractMap (java.util.AbstractMap)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 ViewDescription (org.jboss.as.ee.component.ViewDescription)1 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)1 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)1 MethodIntf (org.jboss.as.ejb3.component.MethodIntf)1 RemoteViewManagedReferenceFactory (org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory)1 ClientMapping (org.jboss.as.network.ClientMapping)1 ProtocolSocketBinding (org.jboss.as.network.ProtocolSocketBinding)1 JBossServiceAttributeConfig (org.jboss.as.service.descriptor.JBossServiceAttributeConfig)1