use of org.jboss.as.naming.ManagedReference 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.naming.ManagedReference 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.naming.ManagedReference in project wildfly by wildfly.
the class WeldInjectionInterceptor method processInvocation.
@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
WeldInjectionContext injectionContext = context.getPrivateData(WeldInjectionContext.class);
ManagedReference reference = (ManagedReference) context.getPrivateData(ComponentInstance.class).getInstanceData(BasicComponentInstance.INSTANCE_KEY);
if (reference != null) {
injectionContext.inject(reference.getInstance());
}
return context.proceed();
}
use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class WeldInterceptorInjectionInterceptor method processInvocation.
@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
WeldInjectionContext injectionContext = context.getPrivateData(WeldInjectionContext.class);
final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
//now inject the interceptors
for (final Class<?> interceptorClass : interceptorClasses) {
final ManagedReference instance = (ManagedReference) componentInstance.getInstanceData(interceptorClass);
if (instance != null) {
injectionContext.injectInterceptor(instance.getInstance());
}
}
return context.proceed();
}
use of org.jboss.as.naming.ManagedReference 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 ManagedReferenceFactory() {
@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));
}
Aggregations