Search in sources :

Example 21 with ManagedReference

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;
}
Also used : ProtocolHandler(org.jboss.narayana.txframework.impl.handlers.ProtocolHandler) ComponentView(org.jboss.as.ee.component.ComponentView) ServiceInvocationMeta(org.jboss.narayana.txframework.impl.ServiceInvocationMeta) ManagedReference(org.jboss.as.naming.ManagedReference) Method(java.lang.reflect.Method)

Example 22 with ManagedReference

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;
}
Also used : ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ComponentFactory(org.jboss.as.ee.component.ComponentFactory) InterceptorContext(org.jboss.invocation.InterceptorContext) ManagedReference(org.jboss.as.naming.ManagedReference)

Example 23 with ManagedReference

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);
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) InterceptorContext(org.jboss.invocation.InterceptorContext) WSComponent(org.jboss.as.webservices.injection.WSComponent) ManagedReference(org.jboss.as.naming.ManagedReference) Method(java.lang.reflect.Method) WSComponent(org.jboss.as.webservices.injection.WSComponent) Component(org.jboss.as.ee.component.Component)

Example 24 with ManagedReference

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());
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) ManagedReference(org.jboss.as.naming.ManagedReference) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) NamingException(javax.naming.NamingException) SystemException(javax.transaction.SystemException)

Example 25 with ManagedReference

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);
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ServiceName(org.jboss.msc.service.ServiceName) Injector(org.jboss.msc.inject.Injector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ServerEnvironment(org.jboss.as.server.ServerEnvironment) ManagedReference(org.jboss.as.naming.ManagedReference)

Aggregations

ManagedReference (org.jboss.as.naming.ManagedReference)25 ComponentView (org.jboss.as.ee.component.ComponentView)7 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)7 NamingException (javax.naming.NamingException)4 ImmediateManagedReference (org.jboss.as.naming.ImmediateManagedReference)4 InterceptorContext (org.jboss.invocation.InterceptorContext)4 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)3 ComponentInstance (org.jboss.as.ee.component.ComponentInstance)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 InitialContext (javax.naming.InitialContext)2 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)2 Component (org.jboss.as.ee.component.Component)2 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)2 ComponentFactory (org.jboss.as.ee.component.ComponentFactory)2 InjectionSource (org.jboss.as.ee.component.InjectionSource)2 ExtendedEntityManager (org.jboss.as.jpa.container.ExtendedEntityManager)2 Injector (org.jboss.msc.inject.Injector)2 ServiceName (org.jboss.msc.service.ServiceName)2