use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class XTSEJBInterceptor method processInvocation.
@Override
public Object processInvocation(InterceptorContext context) throws Exception {
ComponentView cv = context.getPrivateData(ComponentView.class);
ManagedReference mr = cv.createInstance();
Object serviceInstance = mr.getInstance();
Class serviceClass = context.getTarget().getClass();
Method serviceMethod = context.getMethod();
Object result;
ProtocolHandler protocolHandler = HandlerFactory.getInstance(new ServiceInvocationMeta(serviceInstance, serviceClass, serviceMethod));
try {
protocolHandler.preInvocation();
result = context.proceed();
protocolHandler.notifySuccess();
} catch (Exception e) {
protocolHandler.notifyFailure();
throw e;
}
return result;
}
use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class ServiceComponentDescription method createConfiguration.
@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
final ComponentConfiguration configuration = super.createConfiguration(classIndex, moduleClassLoader, moduleLoader);
// will not be used, but if instance factory is not set then components must have default constructor, which is not a
// requirement for MBeans
configuration.setInstanceFactory(new ComponentFactory() {
@Override
public ManagedReference create(final InterceptorContext context) {
return new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
return null;
}
};
}
});
return configuration;
}
use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class AbstractInvocationHandler method invokeInternal.
public void invokeInternal(final Endpoint endpoint, final Invocation wsInvocation) throws Exception {
// prepare for invocation
onBeforeInvocation(wsInvocation);
// prepare invocation data
final ComponentView componentView = getComponentView();
Component component = componentView.getComponent();
// in case of @FactoryType annotation we don't need to go into EE interceptors
final boolean forceTargetBean = (wsInvocation.getInvocationContext().getProperty("forceTargetBean") != null);
if (forceTargetBean) {
this.reference = new ManagedReference() {
public void release() {
}
public Object getInstance() {
return wsInvocation.getInvocationContext().getTargetBean();
}
};
if (component instanceof WSComponent) {
((WSComponent) component).setReference(reference);
}
}
final Method method = getComponentViewMethod(wsInvocation.getJavaMethod(), componentView.getViewMethods());
final InterceptorContext context = new InterceptorContext();
prepareForInvocation(context, wsInvocation);
context.setMethod(method);
context.setParameters(wsInvocation.getArgs());
context.putPrivateData(Component.class, component);
context.putPrivateData(ComponentView.class, componentView);
// pull in any XTS transaction
LocalTransactionContext.getCurrent().importProviderTransaction();
context.setTransaction(ContextTransactionManager.getInstance().getTransaction());
if (forceTargetBean) {
context.putPrivateData(ManagedReference.class, reference);
}
// invoke method
final Object retObj = componentView.invoke(context);
// set return value
wsInvocation.setReturnValue(retObj);
}
use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class EJBComponent method createViewInstanceProxy.
protected <T> T createViewInstanceProxy(final Class<T> viewInterface, final Map<Object, Object> contextData, final ServiceName serviceName) {
final ServiceController<?> serviceController = currentServiceContainer().getRequiredService(serviceName);
final ComponentView view = (ComponentView) serviceController.getValue();
final ManagedReference instance;
try {
if (WildFlySecurityManager.isChecking()) {
instance = WildFlySecurityManager.doUnchecked(new PrivilegedExceptionAction<ManagedReference>() {
@Override
public ManagedReference run() throws Exception {
return view.createInstance(contextData);
}
});
} else {
instance = view.createInstance(contextData);
}
} catch (Exception e) {
//TODO: do we need to let the exception propagate here?
throw new RuntimeException(e);
}
return viewInterface.cast(instance.getInstance());
}
use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.
the class InstanceNameBindingProcessor method bindServices.
private void bindServices(DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName contextServiceName) {
final ServiceName instanceNameServiceName = contextServiceName.append("InstanceName");
final BinderService instanceNameService = new BinderService("InstanceName");
serviceTarget.addService(instanceNameServiceName, instanceNameService).addDependency(contextServiceName, ServiceBasedNamingStore.class, instanceNameService.getNamingStoreInjector()).addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, new Injector<ServerEnvironment>() {
@Override
public void inject(final ServerEnvironment serverEnvironment) throws InjectionException {
instanceNameService.getManagedObjectInjector().inject(new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
return new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
final String nodeName = serverEnvironment.getNodeName();
return nodeName == null ? "" : nodeName;
}
};
}
});
}
@Override
public void uninject() {
instanceNameService.getManagedObjectInjector().uninject();
}
}).install();
deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, instanceNameServiceName);
}
Aggregations