use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.
the class StatefulSessionObjectReferenceImpl method getBusinessObject.
@Override
@SuppressWarnings({ "unchecked" })
public synchronized <S> S getBusinessObject(Class<S> businessInterfaceType) {
if (isRemoved()) {
WeldEjbLogger.ROOT_LOGGER.ejbHashBeenRemoved(ejbComponent);
}
final String businessInterfaceName = businessInterfaceType.getName();
ManagedReference managedReference = null;
if (businessInterfaceToReference == null) {
businessInterfaceToReference = new HashMap<String, ManagedReference>();
} else {
managedReference = businessInterfaceToReference.get(businessInterfaceName);
}
if (managedReference == null) {
if (viewServices.containsKey(businessInterfaceType)) {
final ServiceController<?> serviceController = currentServiceContainer().getRequiredService(viewServices.get(businessInterfaceType));
final ComponentView view = (ComponentView) serviceController.getValue();
try {
managedReference = view.createInstance(Collections.<Object, Object>singletonMap(SessionID.class, id));
businessInterfaceToReference.put(businessInterfaceName, managedReference);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw WeldLogger.ROOT_LOGGER.viewNotFoundOnEJB(businessInterfaceType.getName(), ejbComponent.getComponentName());
}
}
return (S) managedReference.getInstance();
}
use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.
the class WeldEjbInjectionServices method handleServiceLookup.
private ResourceReferenceFactory<Object> handleServiceLookup(ViewDescription viewDescription, InjectionPoint injectionPoint) {
/*
* Try to obtain ComponentView eagerly and validate the resource type
*/
final ComponentView view = getComponentView(viewDescription);
if (view != null && injectionPoint.getAnnotated().isAnnotationPresent(Produces.class)) {
Class<?> clazz = view.getViewClass();
Class<?> injectionPointRawType = Reflections.getRawType(injectionPoint.getType());
//we just compare names, as for remote views the actual classes may be loaded from different class loaders
Class<?> c = clazz;
boolean found = false;
while (c != null && c != Object.class) {
if (injectionPointRawType.getName().equals(c.getName())) {
found = true;
break;
}
c = c.getSuperclass();
}
if (!found) {
throw BeanLogger.LOG.invalidResourceProducerType(injectionPoint.getAnnotated(), clazz.getName());
}
return new ComponentViewToResourceReferenceFactoryAdapter<Object>(view);
} else {
return new LazyResourceReferenceFactory(viewDescription, serviceRegistry);
}
}
use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.
the class WeldEjbInjectionServices method createLazyResourceReferenceFactory.
protected ResourceReferenceFactory<Object> createLazyResourceReferenceFactory(final ViewDescription viewDescription) {
return new ResourceReferenceFactory<Object>() {
@Override
public ResourceReference<Object> createResource() {
final ManagedReference instance;
try {
final ServiceController<?> controller = serviceRegistry.getRequiredService(viewDescription.getServiceName());
final ComponentView view = (ComponentView) controller.getValue();
instance = view.createInstance();
return new ResourceReference<Object>() {
@Override
public Object getInstance() {
return instance.getInstance();
}
@Override
public void release() {
instance.release();
}
};
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
}
use of org.jboss.as.ee.component.ComponentView 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;
}
// 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 EJB 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, countdown);
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(), (InjectedValue<Object>) entry.getValue());
}
builder.addDependency(DeploymentRepository.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);
startBuilder.addDependencies(componentStartServices);
startBuilder.addDependency(moduleDeploymentService);
startBuilder.addDependency(DeploymentRepository.SERVICE_NAME, DeploymentRepository.class, deploymentStart.getDeploymentRepository());
startBuilder.install();
}
use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.
the class StatefulRemoveInterceptor method processInvocation.
@Override
public Object processInvocation(InterceptorContext context) throws Exception {
final Component component = context.getPrivateData(Component.class);
//if a session bean is participating in a transaction, it
//is an error for a client to invoke the remove method
//on the session object's home or component interface.
final ComponentView view = context.getPrivateData(ComponentView.class);
if (view != null) {
Ejb2xViewType viewType = view.getPrivateData(Ejb2xViewType.class);
if (viewType != null) {
//this means it is an EJB 2.x view
//which is not allowed to remove while enrolled in a TX
final StatefulTransactionMarker marker = context.getPrivateData(StatefulTransactionMarker.class);
if (marker != null && !marker.isFirstInvocation()) {
throw EjbLogger.ROOT_LOGGER.cannotRemoveWhileParticipatingInTransaction();
}
}
}
// just log a WARN and throw back the original exception
if (component instanceof StatefulSessionComponent == false) {
throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, StatefulSessionComponent.class);
}
final StatefulSessionComponent statefulComponent = (StatefulSessionComponent) component;
Object invocationResult = null;
try {
// proceed
invocationResult = context.proceed();
} catch (Exception e) {
// then just throw back the exception and don't remove the session instance.
if (this.isApplicationException(statefulComponent, e.getClass(), context.getMethod()) && this.retainIfException) {
throw e;
}
// otherwise, just remove it and throw back the original exception
final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
final SessionID sessionId = statefulComponentInstance.getId();
statefulComponent.removeSession(sessionId);
throw e;
}
final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
final SessionID sessionId = statefulComponentInstance.getId();
// just remove the session because of a call to @Remove method
statefulComponent.removeSession(sessionId);
// return the invocation result
return invocationResult;
}
Aggregations