Search in sources :

Example 31 with ManagedReference

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 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));
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) ManagedReference(org.jboss.as.naming.ManagedReference) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) InjectionSource(org.jboss.as.ee.component.InjectionSource) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) Injector(org.jboss.msc.inject.Injector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) RunResult(org.wildfly.extension.requestcontroller.RunResult) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 32 with ManagedReference

use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.

the class NamingBindingAdd method installExternalContext.

void installExternalContext(final OperationContext context, final String name, final ModelNode model) throws OperationFailedException {
    final String moduleID = NamingBindingResourceDefinition.MODULE.resolveModelAttribute(context, model).asString();
    final String className = NamingBindingResourceDefinition.CLASS.resolveModelAttribute(context, model).asString();
    final ModelNode cacheNode = NamingBindingResourceDefinition.CACHE.resolveModelAttribute(context, model);
    boolean cache = cacheNode.isDefined() ? cacheNode.asBoolean() : false;
    final ObjectFactory objectFactoryClassInstance = new ExternalContextObjectFactory();
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
    final Hashtable<String, String> environment = getObjectFactoryEnvironment(context, model);
    environment.put(ExternalContextObjectFactory.CACHE_CONTEXT, Boolean.toString(cache));
    environment.put(ExternalContextObjectFactory.INITIAL_CONTEXT_CLASS, className);
    environment.put(ExternalContextObjectFactory.INITIAL_CONTEXT_MODULE, moduleID);
    final ExternalContextBinderService binderService = new ExternalContextBinderService(name, objectFactoryClassInstance);
    binderService.getManagedObjectInjector().inject(new ContextListAndJndiViewManagedReferenceFactory() {

        @Override
        public ManagedReference getReference() {
            try {
                final Object value = objectFactoryClassInstance.getObjectInstance(name, null, null, environment);
                return new ImmediateManagedReference(value);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String getInstanceClassName() {
            return className;
        }

        @Override
        public String getJndiViewInstanceValue() {
            final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
            try {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(objectFactoryClassInstance.getClass().getClassLoader());
                return String.valueOf(getReference().getInstance());
            } finally {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
            }
        }
    });
    serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addDependency(ExternalContextsService.SERVICE_NAME, ExternalContexts.class, binderService.getExternalContextsInjector()).install();
}
Also used : ServiceTarget(org.jboss.msc.service.ServiceTarget) ManagedReference(org.jboss.as.naming.ManagedReference) ImmediateManagedReference(org.jboss.as.naming.ImmediateManagedReference) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory) ModuleLoadException(org.jboss.modules.ModuleLoadException) MalformedURLException(java.net.MalformedURLException) ModuleNotFoundException(org.jboss.modules.ModuleNotFoundException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ObjectFactory(javax.naming.spi.ObjectFactory) ExternalContextObjectFactory(org.jboss.as.naming.ExternalContextObjectFactory) ExternalContexts(org.jboss.as.naming.context.external.ExternalContexts) ImmediateManagedReference(org.jboss.as.naming.ImmediateManagedReference) ModelNode(org.jboss.dmr.ModelNode) ExternalContextObjectFactory(org.jboss.as.naming.ExternalContextObjectFactory) ContextNames(org.jboss.as.naming.deployment.ContextNames) ExternalContextBinderService(org.jboss.as.naming.service.ExternalContextBinderService)

Example 33 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)

Aggregations

ManagedReference (org.jboss.as.naming.ManagedReference)33 ComponentView (org.jboss.as.ee.component.ComponentView)11 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)9 NamingException (javax.naming.NamingException)4 ProcessApplicationInterface (org.camunda.bpm.application.ProcessApplicationInterface)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 StartException (org.jboss.msc.service.StartException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 InitialContext (javax.naming.InitialContext)2 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)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