Search in sources :

Example 1 with ContextListAndJndiViewManagedReferenceFactory

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

the class NamingBindingAdd method installObjectFactory.

void installObjectFactory(final OperationContext context, final String name, final ModelNode model) throws OperationFailedException {
    final ObjectFactory objectFactoryClassInstance = createObjectFactory(context, model);
    final Hashtable<String, String> environment = getObjectFactoryEnvironment(context, model);
    ContextListAndJndiViewManagedReferenceFactory factory = new ObjectFactoryManagedReference(objectFactoryClassInstance, name, environment);
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
    final BinderService binderService = new BinderService(name, objectFactoryClassInstance);
    binderService.getManagedObjectInjector().inject(new MutableManagedReferenceFactory(factory));
    serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).install();
}
Also used : ExternalContextBinderService(org.jboss.as.naming.service.ExternalContextBinderService) BinderService(org.jboss.as.naming.service.BinderService) ObjectFactory(javax.naming.spi.ObjectFactory) ExternalContextObjectFactory(org.jboss.as.naming.ExternalContextObjectFactory) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ServiceTarget(org.jboss.msc.service.ServiceTarget) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 2 with ContextListAndJndiViewManagedReferenceFactory

use of org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory 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) 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 3 with ContextListAndJndiViewManagedReferenceFactory

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

the class JMSDestinationDefinitionInjectionSource method inject.

private <D extends Destination> void inject(ServiceBuilder<?> serviceBuilder, Injector<ManagedReferenceFactory> injector, Service<D> destinationService) {
    final ContextListAndJndiViewManagedReferenceFactory referenceFactoryService = new MessagingJMSDestinationManagedReferenceFactory(destinationService);
    serviceBuilder.addInjection(injector, referenceFactoryService).addListener(new AbstractServiceListener<Object>() {

        public void transition(final ServiceController<? extends Object> controller, final ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        ROOT_LOGGER.boundJndiName(jndiName);
                        break;
                    }
                case START_REQUESTED_to_DOWN:
                    {
                        ROOT_LOGGER.unboundJndiName(jndiName);
                        break;
                    }
                case REMOVING_to_REMOVED:
                    {
                        ROOT_LOGGER.debugf("Removed messaging object [%s]", jndiName);
                        break;
                    }
            }
        }
    });
}
Also used : ServiceController(org.jboss.msc.service.ServiceController) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory)

Aggregations

ContextListAndJndiViewManagedReferenceFactory (org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory)3 ObjectFactory (javax.naming.spi.ObjectFactory)2 ExternalContextObjectFactory (org.jboss.as.naming.ExternalContextObjectFactory)2 ContextNames (org.jboss.as.naming.deployment.ContextNames)2 ExternalContextBinderService (org.jboss.as.naming.service.ExternalContextBinderService)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 MalformedURLException (java.net.MalformedURLException)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 ImmediateManagedReference (org.jboss.as.naming.ImmediateManagedReference)1 ManagedReference (org.jboss.as.naming.ManagedReference)1 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)1 ExternalContexts (org.jboss.as.naming.context.external.ExternalContexts)1 BinderService (org.jboss.as.naming.service.BinderService)1 ModelNode (org.jboss.dmr.ModelNode)1 ModuleLoadException (org.jboss.modules.ModuleLoadException)1 ServiceController (org.jboss.msc.service.ServiceController)1