List of usage examples for org.springframework.jms.connection JmsResourceHolder getConnection
@Nullable public <C extends Connection> C getConnection(Class<C> connectionType)
From source file:org.springframework.jms.connection.ConnectionFactoryUtils.java
/** * Obtain a JMS QueueSession that is synchronized with the current transaction, if any. * <p>Mainly intended for use with the JMS 1.0.2 API. * @param cf the ConnectionFactory to obtain a Session for * @param existingCon the existing JMS Connection to obtain a Session for * (may be {@code null})/*ww w . j ava 2 s.c om*/ * @param synchedLocalTransactionAllowed whether to allow for a local JMS transaction * that is synchronized with a Spring-managed transaction (where the main transaction * might be a JDBC-based one for a specific DataSource, for example), with the JMS * transaction committing right after the main transaction. If not allowed, the given * ConnectionFactory needs to handle transaction enlistment underneath the covers. * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ @Nullable public static QueueSession getTransactionalQueueSession(final QueueConnectionFactory cf, @Nullable final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return (QueueSession) doGetTransactionalSession(cf, new ResourceFactory() { @Override @Nullable public Session getSession(JmsResourceHolder holder) { return holder.getSession(QueueSession.class, existingCon); } @Override @Nullable public Connection getConnection(JmsResourceHolder holder) { return (existingCon != null ? existingCon : holder.getConnection(QueueConnection.class)); } @Override public Connection createConnection() throws JMSException { return cf.createQueueConnection(); } @Override public Session createSession(Connection con) throws JMSException { return ((QueueConnection) con).createQueueSession(synchedLocalTransactionAllowed, Session.AUTO_ACKNOWLEDGE); } @Override public boolean isSynchedLocalTransactionAllowed() { return synchedLocalTransactionAllowed; } }, true); }
From source file:org.springframework.jms.connection.ConnectionFactoryUtils.java
/** * Obtain a JMS TopicSession that is synchronized with the current transaction, if any. * <p>Mainly intended for use with the JMS 1.0.2 API. * @param cf the ConnectionFactory to obtain a Session for * @param existingCon the existing JMS Connection to obtain a Session for * (may be {@code null})/*from w ww .j a v a2 s. c o m*/ * @param synchedLocalTransactionAllowed whether to allow for a local JMS transaction * that is synchronized with a Spring-managed transaction (where the main transaction * might be a JDBC-based one for a specific DataSource, for example), with the JMS * transaction committing right after the main transaction. If not allowed, the given * ConnectionFactory needs to handle transaction enlistment underneath the covers. * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ @Nullable public static TopicSession getTransactionalTopicSession(final TopicConnectionFactory cf, @Nullable final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return (TopicSession) doGetTransactionalSession(cf, new ResourceFactory() { @Override @Nullable public Session getSession(JmsResourceHolder holder) { return holder.getSession(TopicSession.class, existingCon); } @Override @Nullable public Connection getConnection(JmsResourceHolder holder) { return (existingCon != null ? existingCon : holder.getConnection(TopicConnection.class)); } @Override public Connection createConnection() throws JMSException { return cf.createTopicConnection(); } @Override public Session createSession(Connection con) throws JMSException { return ((TopicConnection) con).createTopicSession(synchedLocalTransactionAllowed, Session.AUTO_ACKNOWLEDGE); } @Override public boolean isSynchedLocalTransactionAllowed() { return synchedLocalTransactionAllowed; } }, true); }