Search in sources :

Example 1 with ConnectionFactoryReferenceFactoryService

use of org.jboss.as.connector.services.resourceadapters.ConnectionFactoryReferenceFactoryService in project wildfly by wildfly.

the class JMSConnectionFactoryDefinitionInjectionSource method getDefaulResourceAdapter.

static String getDefaulResourceAdapter(DeploymentUnit deploymentUnit) {
    EEModuleDescription eeDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    if (eeDescription != null) {
        String defaultJndiName = eeDescription.getDefaultResourceJndiNames().getJmsConnectionFactory();
        ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(defaultJndiName);
        ServiceController binder = deploymentUnit.getServiceRegistry().getService(bindInfo.getBinderServiceName());
        if (binder != null) {
            Object pcf = binder.getService().getValue();
            ServiceController.State currentState = binder.getState();
            CountDownLatch latch = new CountDownLatch(1);
            if (currentState != ServiceController.State.UP) {
                LifecycleListener lifecycleListener = new LifecycleListener() {

                    @Override
                    public void handleEvent(ServiceController<?> controller, LifecycleEvent event) {
                        latch.countDown();
                    }
                };
                try {
                    binder.addListener(lifecycleListener);
                    latch.await();
                } catch (InterruptedException ex) {
                    return null;
                } finally {
                    binder.removeListener(lifecycleListener);
                }
            }
            if (currentState != ServiceController.State.UP) {
                return null;
            }
            // In case of multiple JNDI entries only the 1st is properly bound
            if (pcf != null && pcf instanceof ContextListAndJndiViewManagedReferenceFactory) {
                ManagedReference ref = ((ContextListAndJndiViewManagedReferenceFactory) pcf).getReference();
                Object ra = ref.getInstance();
                if (ra instanceof ActiveMQRAConnectionFactoryImpl) {
                    bindInfo = ContextNames.bindInfoFor(((ActiveMQRAConnectionFactoryImpl) ra).getReference().getClassName());
                    binder = deploymentUnit.getServiceRegistry().getService(bindInfo.getBinderServiceName());
                    if (binder != null) {
                        pcf = binder.getService().getValue();
                    }
                }
            }
            if (pcf != null && pcf instanceof ConnectionFactoryReferenceFactoryService) {
                return ((ConnectionFactoryReferenceFactoryService) pcf).getName();
            }
        }
    }
    return null;
}
Also used : ConnectionFactoryReferenceFactoryService(org.jboss.as.connector.services.resourceadapters.ConnectionFactoryReferenceFactoryService) ManagedReference(org.jboss.as.naming.ManagedReference) LifecycleListener(org.jboss.msc.service.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) LifecycleEvent(org.jboss.msc.service.LifecycleEvent) ServiceController(org.jboss.msc.service.ServiceController) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 ActiveMQRAConnectionFactoryImpl (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl)1 ConnectionFactoryReferenceFactoryService (org.jboss.as.connector.services.resourceadapters.ConnectionFactoryReferenceFactoryService)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 ContextListAndJndiViewManagedReferenceFactory (org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory)1 ManagedReference (org.jboss.as.naming.ManagedReference)1 ContextNames (org.jboss.as.naming.deployment.ContextNames)1 LifecycleEvent (org.jboss.msc.service.LifecycleEvent)1 LifecycleListener (org.jboss.msc.service.LifecycleListener)1 ServiceController (org.jboss.msc.service.ServiceController)1