use of org.jboss.as.ejb3.component.EJBComponentDescription 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;
}
}
}
}
use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.
the class EjbIIOPDeploymentUnitProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!IIOPDeploymentMarker.isIIOPDeployment(deploymentUnit)) {
return;
}
if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
return;
}
// a bean-name -> IIOPMetaData map, reflecting the assembly descriptor IIOP configuration.
Map<String, IIOPMetaData> iiopMetaDataMap = new HashMap<String, IIOPMetaData>();
final EjbJarMetaData ejbMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbMetaData != null && ejbMetaData.getAssemblyDescriptor() != null) {
List<IIOPMetaData> iiopMetaDatas = ejbMetaData.getAssemblyDescriptor().getAny(IIOPMetaData.class);
if (iiopMetaDatas != null && !iiopMetaDatas.isEmpty()) {
for (IIOPMetaData metaData : iiopMetaDatas) {
iiopMetaDataMap.put(metaData.getEjbName(), metaData);
}
}
}
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (moduleDescription != null) {
for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
if (componentDescription instanceof EJBComponentDescription) {
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
if (ejbComponentDescription.getEjbRemoteView() != null && ejbComponentDescription.getEjbHomeView() != null) {
// check if there is IIOP metadata for the bean - first using the bean name, then the wildcard "*" if needed.
IIOPMetaData iiopMetaData = iiopMetaDataMap.get(ejbComponentDescription.getEJBName());
if (iiopMetaData == null) {
iiopMetaData = iiopMetaDataMap.get(IIOPMetaData.WILDCARD_BEAN_NAME);
}
// has been enabled by default in the EJB3 subsystem.
if (iiopMetaData != null || settingsService.isEnabledByDefault()) {
processEjb(ejbComponentDescription, deploymentReflectionIndex, module, phaseContext.getServiceTarget(), iiopMetaData);
}
}
}
}
}
}
use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.
the class EjbJndiBindingsDeploymentUnitProcessor method registerRemoteBinding.
private void registerRemoteBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName) {
final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient)));
componentDescription.getConfigurators().add(new ComponentConfigurator() {
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
viewClassLoader.setValue(Values.immediateValue(configuration.getModuleClassLoader()));
}
});
}
use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.
the class EjbJndiBindingsDeploymentUnitProcessor method registerControlPointBinding.
private void registerControlPointBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName, final DeploymentUnit deploymentUnit) {
final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
final InjectedValue<ControlPoint> controlPointInjectedValue = new InjectedValue<>();
final RemoteViewInjectionSource delegate = new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
final ServiceName depName = ControlPointService.serviceName(deploymentUnit.getParent() == null ? deploymentUnit.getName() : deploymentUnit.getParent().getName(), EJBComponentSuspendDeploymentUnitProcessor.ENTRY_POINT_NAME + deploymentUnit.getName() + "." + componentDescription.getComponentName());
componentDescription.getConfigurators().add((context, description, configuration) -> {
viewClassLoader.setValue(Values.immediateValue(configuration.getModuleClassLoader()));
configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.addDependency(depName, ControlPoint.class, controlPointInjectedValue));
});
// we need to wrap the injection source to allow graceful shutdown to function, although this is not ideal
// as it will also reject local lookups as well, although in general local code should never be looking up the
// exported bindings
// the other option would be to reject it at the remote naming service level, however then we loose the per-deployment granularity
final InjectionSource is = new InjectionSource() {
@Override
public void getResourceValue(ResolutionContext resolutionContext, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final InjectedValue<ManagedReferenceFactory> delegateInjection = new InjectedValue<>();
delegate.getResourceValue(resolutionContext, serviceBuilder, phaseContext, delegateInjection);
injector.inject(new RemoteViewManagedReferenceFactory(moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient) {
@Override
public ManagedReference getReference() {
ControlPoint cp = controlPointInjectedValue.getValue();
try {
RunResult res = cp.beginRequest();
if (res != RunResult.RUN) {
throw EjbLogger.ROOT_LOGGER.containerSuspended();
}
try {
return delegateInjection.getValue().getReference();
} finally {
cp.requestComplete();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
};
moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, is));
}
use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.
the class DeploymentRepositoryProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (eeModuleDescription == null) {
return;
}
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
// don't create this for EAR's, as they cannot hold Jakarta Enterprise Beans's
return;
}
// Note, we do not use the EEModuleDescription.getApplicationName() because that API returns the
// module name if the top level unit isn't a .ear, which is not what we want. We really want a
// .ear name as application name (that's the semantic in Jakarta Enterprise Beans spec). So use EEModuleDescription.getEarApplicationName
String applicationName = eeModuleDescription.getEarApplicationName();
// if it's not a .ear deployment then set app name to empty string
applicationName = applicationName == null ? "" : applicationName;
final DeploymentModuleIdentifier identifier = new DeploymentModuleIdentifier(applicationName, eeModuleDescription.getModuleName(), eeModuleDescription.getDistinctName());
final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
final Map<String, EjbDeploymentInformation> deploymentInformationMap = new HashMap<String, EjbDeploymentInformation>();
final Set<ServiceName> componentStartServices = new HashSet<ServiceName>();
final Map<ServiceName, InjectedValue<?>> injectedValues = new HashMap<ServiceName, InjectedValue<?>>();
for (final ComponentDescription component : componentDescriptions) {
if (component instanceof EJBComponentDescription) {
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) component;
componentStartServices.add(component.getStartServiceName());
final InjectedValue<EJBComponent> componentInjectedValue = new InjectedValue<EJBComponent>();
injectedValues.put(component.getCreateServiceName(), componentInjectedValue);
final Map<String, InjectedValue<ComponentView>> remoteViews = new HashMap<String, InjectedValue<ComponentView>>();
final Map<String, InjectedValue<ComponentView>> localViews = new HashMap<String, InjectedValue<ComponentView>>();
for (final ViewDescription view : ejbComponentDescription.getViews()) {
boolean remoteView = false;
if (view instanceof EJBViewDescription) {
final MethodIntf viewType = ((EJBViewDescription) view).getMethodIntf();
if (viewType == MethodIntf.HOME || viewType == MethodIntf.REMOTE) {
remoteView = true;
}
}
final InjectedValue<ComponentView> componentViewInjectedValue = new InjectedValue<ComponentView>();
if (remoteView) {
remoteViews.put(view.getViewClassName(), componentViewInjectedValue);
} else {
localViews.put(view.getViewClassName(), componentViewInjectedValue);
}
injectedValues.put(view.getServiceName(), componentViewInjectedValue);
}
final InjectedValue<EjbIIOPService> iorFactory = new InjectedValue<EjbIIOPService>();
if (ejbComponentDescription.isExposedViaIiop()) {
injectedValues.put(ejbComponentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), iorFactory);
}
final EjbDeploymentInformation info = new EjbDeploymentInformation(ejbComponentDescription.getEJBName(), componentInjectedValue, remoteViews, localViews, module.getClassLoader(), iorFactory);
deploymentInformationMap.put(ejbComponentDescription.getEJBName(), info);
}
}
final StartupCountdown countdown = deploymentUnit.getAttachment(Attachments.STARTUP_COUNTDOWN);
final ModuleDeployment deployment = new ModuleDeployment(identifier, deploymentInformationMap);
ServiceName moduleDeploymentService = deploymentUnit.getServiceName().append(ModuleDeployment.SERVICE_NAME);
final ServiceBuilder<ModuleDeployment> builder = phaseContext.getServiceTarget().addService(moduleDeploymentService, deployment);
for (Map.Entry<ServiceName, InjectedValue<?>> entry : injectedValues.entrySet()) {
builder.addDependency(entry.getKey(), Object.class, (InjectedValue<Object>) entry.getValue());
}
builder.addDependency(DeploymentRepositoryService.SERVICE_NAME, DeploymentRepository.class, deployment.getDeploymentRepository());
builder.install();
final ModuleDeployment.ModuleDeploymentStartService deploymentStart = new ModuleDeployment.ModuleDeploymentStartService(identifier, countdown);
final ServiceBuilder<Void> startBuilder = phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append(ModuleDeployment.START_SERVICE_NAME), deploymentStart);
for (final ServiceName componentStartService : componentStartServices) {
startBuilder.requires(componentStartService);
}
startBuilder.requires(moduleDeploymentService);
startBuilder.addDependency(DeploymentRepositoryService.SERVICE_NAME, DeploymentRepository.class, deploymentStart.getDeploymentRepository());
startBuilder.install();
}
Aggregations