Search in sources :

Example 21 with ManagedReferenceFactory

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

the class JndiViewOperation method addEntries.

private void addEntries(final ModelNode current, final Context context) throws NamingException {
    final NamingEnumeration<NameClassPair> entries = context.list("");
    while (entries.hasMore()) {
        final NameClassPair pair = entries.next();
        final ModelNode node = current.get(pair.getName());
        node.get("class-name").set(pair.getClassName());
        try {
            final Object value;
            if (context instanceof NamingContext) {
                value = ((NamingContext) context).lookup(pair.getName(), false);
            } else {
                value = context.lookup(pair.getName());
            }
            if (value instanceof Context) {
                addEntries(node.get("children"), Context.class.cast(value));
            } else if (value instanceof Reference) {
            //node.get("value").set(value.toString());
            } else {
                String jndiViewValue = JndiViewManagedReferenceFactory.DEFAULT_JNDI_VIEW_INSTANCE_VALUE;
                if (value instanceof JndiViewManagedReferenceFactory) {
                    try {
                        jndiViewValue = JndiViewManagedReferenceFactory.class.cast(value).getJndiViewInstanceValue();
                    } catch (Throwable e) {
                        // just log, don't stop the operation
                        NamingLogger.ROOT_LOGGER.failedToLookupJndiViewValue(pair.getName(), e);
                    }
                } else if (!(value instanceof ManagedReferenceFactory)) {
                    jndiViewValue = String.valueOf(value);
                }
                node.get("value").set(jndiViewValue);
            }
        } catch (NamingException e) {
            // just log, don't stop the operation
            NamingLogger.ROOT_LOGGER.failedToLookupJndiViewValue(pair.getName(), e);
        }
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) NamingContext(org.jboss.as.naming.NamingContext) Context(javax.naming.Context) NameClassPair(javax.naming.NameClassPair) Reference(javax.naming.Reference) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) JndiViewManagedReferenceFactory(org.jboss.as.naming.JndiViewManagedReferenceFactory) NamingException(javax.naming.NamingException) ModelNode(org.jboss.dmr.ModelNode) NamingContext(org.jboss.as.naming.NamingContext) JndiViewManagedReferenceFactory(org.jboss.as.naming.JndiViewManagedReferenceFactory)

Example 22 with ManagedReferenceFactory

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

the class AbstractResourceInjectionServices method handleServiceLookup.

protected ResourceReferenceFactory<Object> handleServiceLookup(final String result, InjectionPoint injectionPoint) {
    final ContextNames.BindInfo ejbBindInfo = getBindInfo(result);
    /*
         * Try to obtain ManagedReferenceFactory and validate the resource type
         */
    final ManagedReferenceFactory factory = getManagedReferenceFactory(ejbBindInfo);
    validateResourceInjectionPointType(factory, injectionPoint);
    if (factory != null) {
        return new ManagedReferenceFactoryToResourceReferenceFactoryAdapter<Object>(factory);
    } else {
        return createLazyResourceReferenceFactory(ejbBindInfo);
    }
}
Also used : ContextListManagedReferenceFactory(org.jboss.as.naming.ContextListManagedReferenceFactory) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 23 with ManagedReferenceFactory

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

the class UndertowDeploymentInfoService method addListener.

private static void addListener(final ClassLoader classLoader, final ComponentRegistry components, final DeploymentInfo d, final ListenerMetaData listener) throws ClassNotFoundException {
    ListenerInfo l;
    final Class<? extends EventListener> listenerClass = (Class<? extends EventListener>) classLoader.loadClass(listener.getListenerClass());
    ManagedReferenceFactory creator = components.createInstanceFactory(listenerClass);
    if (creator != null) {
        InstanceFactory<EventListener> factory = createInstanceFactory(creator);
        l = new ListenerInfo(listenerClass, factory);
    } else {
        l = new ListenerInfo(listenerClass);
    }
    d.addListener(l);
}
Also used : ListenerInfo(io.undertow.servlet.api.ListenerInfo) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) EventListener(java.util.EventListener)

Example 24 with ManagedReferenceFactory

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

the class BinderServiceBuilder method build.

@Override
public ServiceBuilder<ManagedReferenceFactory> build(ServiceTarget target) {
    if (!this.enabled) {
        // If naming is not enabled, just install a dummy service that never starts
        Value<ManagedReferenceFactory> value = new ImmediateValue<>(null);
        return target.addService(this.getServiceName(), new ValueService<>(value)).setInitialMode(ServiceController.Mode.NEVER);
    }
    String name = this.binding.getBindName();
    BinderService binder = new BinderService(name);
    ServiceBuilder<ManagedReferenceFactory> builder = target.addService(this.getServiceName(), binder).addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(name)).addDependency(this.targetServiceName, this.targetClass, new ManagedReferenceInjector<T>(binder.getManagedObjectInjector())).addDependency(this.binding.getParentContextServiceName(), ServiceBasedNamingStore.class, binder.getNamingStoreInjector());
    for (ContextNames.BindInfo alias : this.aliases) {
        builder.addAliases(alias.getBinderServiceName(), ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(alias.getBindName()));
    }
    return builder.setInitialMode(ServiceController.Mode.PASSIVE);
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ManagedReferenceInjector(org.jboss.as.naming.ManagedReferenceInjector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ValueService(org.jboss.msc.service.ValueService) ImmediateValue(org.jboss.msc.value.ImmediateValue) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 25 with ManagedReferenceFactory

use of org.jboss.as.naming.ManagedReferenceFactory 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));
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) 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) RunResult(org.wildfly.extension.requestcontroller.RunResult) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Aggregations

ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)29 BinderService (org.jboss.as.naming.service.BinderService)12 ContextNames (org.jboss.as.naming.deployment.ContextNames)9 ManagedReference (org.jboss.as.naming.ManagedReference)7 ServiceName (org.jboss.msc.service.ServiceName)6 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)5 InjectionSource (org.jboss.as.ee.component.InjectionSource)5 ContextListManagedReferenceFactory (org.jboss.as.naming.ContextListManagedReferenceFactory)5 ValueManagedReferenceFactory (org.jboss.as.naming.ValueManagedReferenceFactory)5 ServiceController (org.jboss.msc.service.ServiceController)5 HashMap (java.util.HashMap)3 NamingException (javax.naming.NamingException)3 Injector (org.jboss.msc.inject.Injector)3 ListenerInfo (io.undertow.servlet.api.ListenerInfo)2 HashSet (java.util.HashSet)2 InitialContext (javax.naming.InitialContext)2 OperationContext (org.jboss.as.controller.OperationContext)2 Resource (org.jboss.as.controller.registry.Resource)2 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)2 ContextListAndJndiViewManagedReferenceFactory (org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory)2