Skip to content

Commit

Permalink
Added support for JMS classes implementing Connection and XAConnectio…
Browse files Browse the repository at this point in the history
…n Factory interfaces

fixes gh-1284
  • Loading branch information
marcingrzejszczak committed Apr 11, 2019
1 parent 7f0d4f1 commit e099b6d
Showing 1 changed file with 76 additions and 1 deletion.
Expand Up @@ -70,9 +70,13 @@ public Object postProcessAfterInitialization(Object bean, String beanName)
}
return bean;
}
if (bean instanceof XAConnectionFactory && bean instanceof ConnectionFactory) {
return new LazyConnectionAndXaConnectionFactory(this.beanFactory,
(ConnectionFactory) bean, (XAConnectionFactory) bean);
}
// We check XA first in case the ConnectionFactory also implements
// XAConnectionFactory
if (bean instanceof XAConnectionFactory) {
else if (bean instanceof XAConnectionFactory) {
return new LazyXAConnectionFactory(this.beanFactory,
(XAConnectionFactory) bean);
}
Expand Down Expand Up @@ -271,6 +275,77 @@ private ConnectionFactory wrappedDelegate() {

}

class LazyConnectionAndXaConnectionFactory
implements ConnectionFactory, XAConnectionFactory {

private final ConnectionFactory connectionFactoryDelegate;

private final XAConnectionFactory xaConnectionFactoryDelegate;

LazyConnectionAndXaConnectionFactory(BeanFactory beanFactory,
ConnectionFactory connectionFactoryDelegate,
XAConnectionFactory xaConnectionFactoryDelegate) {
this.connectionFactoryDelegate = new LazyConnectionFactory(beanFactory,
connectionFactoryDelegate);
this.xaConnectionFactoryDelegate = new LazyXAConnectionFactory(beanFactory,
xaConnectionFactoryDelegate);
}

@Override
public Connection createConnection() throws JMSException {
return this.connectionFactoryDelegate.createConnection();
}

@Override
public Connection createConnection(String userName, String password)
throws JMSException {
return this.connectionFactoryDelegate.createConnection(userName, password);
}

@Override
public JMSContext createContext() {
return this.connectionFactoryDelegate.createContext();
}

@Override
public JMSContext createContext(String userName, String password) {
return this.connectionFactoryDelegate.createContext(userName, password);
}

@Override
public JMSContext createContext(String userName, String password, int sessionMode) {
return this.connectionFactoryDelegate.createContext(userName, password,
sessionMode);
}

@Override
public JMSContext createContext(int sessionMode) {
return this.connectionFactoryDelegate.createContext(sessionMode);
}

@Override
public XAConnection createXAConnection() throws JMSException {
return this.xaConnectionFactoryDelegate.createXAConnection();
}

@Override
public XAConnection createXAConnection(String userName, String password)
throws JMSException {
return this.xaConnectionFactoryDelegate.createXAConnection(userName, password);
}

@Override
public XAJMSContext createXAContext() {
return this.xaConnectionFactoryDelegate.createXAContext();
}

@Override
public XAJMSContext createXAContext(String userName, String password) {
return this.xaConnectionFactoryDelegate.createXAContext(userName, password);
}

}

class LazyMessageListener implements MessageListener {

private final BeanFactory beanFactory;
Expand Down

0 comments on commit e099b6d

Please sign in to comment.