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;
}
Aggregations