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);
}
}
}
}
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));
}
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;
});
}
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;
}
}
}
}
Aggregations