Search in sources :

Example 1 with TopicConnection

use of javax.jms.TopicConnection in project spring-framework by spring-projects.

the class SingleConnectionFactory method createTopicConnection.

@Override
public TopicConnection createTopicConnection() throws JMSException {
    Connection con;
    synchronized (this.connectionMonitor) {
        this.pubSubMode = Boolean.TRUE;
        con = createConnection();
    }
    if (!(con instanceof TopicConnection)) {
        throw new javax.jms.IllegalStateException("This SingleConnectionFactory does not hold a TopicConnection but rather: " + con);
    }
    return ((TopicConnection) con);
}
Also used : Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) TopicConnection(javax.jms.TopicConnection)

Example 2 with TopicConnection

use of javax.jms.TopicConnection in project spring-framework by spring-projects.

the class TransactionAwareConnectionFactoryProxy method createTopicConnection.

@Override
public TopicConnection createTopicConnection() throws JMSException {
    ConnectionFactory target = obtainTargetConnectionFactory();
    if (!(target instanceof TopicConnectionFactory)) {
        throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no TopicConnectionFactory");
    }
    TopicConnection targetConnection = ((TopicConnectionFactory) target).createTopicConnection();
    return (TopicConnection) getTransactionAwareConnectionProxy(targetConnection);
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) TopicConnection(javax.jms.TopicConnection)

Example 3 with TopicConnection

use of javax.jms.TopicConnection in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testWithTopicConnectionFactoryAndJms11Usage.

@Test
public void testWithTopicConnectionFactoryAndJms11Usage() throws JMSException {
    TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
    TopicConnection con = mock(TopicConnection.class);
    given(cf.createConnection()).willReturn(con);
    SingleConnectionFactory scf = new SingleConnectionFactory(cf);
    Connection con1 = scf.createConnection();
    Connection con2 = scf.createConnection();
    con1.start();
    con2.start();
    con1.close();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) TopicConnection(javax.jms.TopicConnection) Test(org.junit.Test)

Example 4 with TopicConnection

use of javax.jms.TopicConnection in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testCachingConnectionFactoryWithTopicConnectionFactoryAndJms102Usage.

@Test
public void testCachingConnectionFactoryWithTopicConnectionFactoryAndJms102Usage() throws JMSException {
    TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
    TopicConnection con = mock(TopicConnection.class);
    TopicSession txSession = mock(TopicSession.class);
    TopicSession nonTxSession = mock(TopicSession.class);
    given(cf.createTopicConnection()).willReturn(con);
    given(con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
    given(txSession.getTransacted()).willReturn(true);
    given(con.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);
    CachingConnectionFactory scf = new CachingConnectionFactory(cf);
    scf.setReconnectOnException(false);
    Connection con1 = scf.createTopicConnection();
    Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
    session1.getTransacted();
    // should lead to rollback
    session1.close();
    session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    session1.close();
    con1.start();
    TopicConnection con2 = scf.createTopicConnection();
    Session session2 = con2.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
    session2.close();
    session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
    session2.getTransacted();
    session2.close();
    con2.start();
    con1.close();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(txSession).close();
    verify(nonTxSession).close();
    verify(con).start();
    verify(con).stop();
    verify(con).close();
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) TopicSession(javax.jms.TopicSession) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) TopicConnection(javax.jms.TopicConnection) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session) TopicSession(javax.jms.TopicSession) Test(org.junit.Test)

Example 5 with TopicConnection

use of javax.jms.TopicConnection in project ACS by ACS-Community.

the class PubSubTest method testTopicConnection.

public void testTopicConnection() throws Exception {
    TopicConnection topicConnection = factory.createTopicConnection();
    assertNotNull("Error creating the TopicConnection", topicConnection);
    TopicSession topicSession = topicConnection.createTopicSession(true, 0);
    assertNotNull("Error creating the TopicSession", topicSession);
    String chName = "TOPIC.TEST";
    Topic topic = topicSession.createTopic(chName);
    assertNotNull("Error creating Topic", topic);
    assertEquals("Wrong name for the topic", chName, topic.getTopicName());
    TopicPublisher publisher = topicSession.createPublisher(topic);
    assertNotNull("Error creating the TopicPublisher ", publisher);
    TopicSubscriber subscriber = topicSession.createSubscriber(topic);
    assertNotNull("Error creating the TopicSubscriber", subscriber);
    subscriber.setMessageListener(this);
    ACSJMSTextMessage msg = new ACSJMSTextMessage(getContainerServices());
    assertNotNull("Error creating ACSJMSTextMessage", msg);
    msg.setText(msgToSend);
    publisher.publish(msg);
    // Wait for awhile to have enough time to receive the message
    try {
        Thread.sleep(10000);
    } catch (Exception e) {
    }
    publisher.close();
    subscriber.close();
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) TopicPublisher(javax.jms.TopicPublisher) ACSJMSTextMessage(com.cosylab.acs.jms.ACSJMSTextMessage) Topic(javax.jms.Topic) TopicConnection(javax.jms.TopicConnection)

Aggregations

TopicConnection (javax.jms.TopicConnection)10 TopicConnectionFactory (javax.jms.TopicConnectionFactory)6 Connection (javax.jms.Connection)5 QueueConnection (javax.jms.QueueConnection)5 TopicSession (javax.jms.TopicSession)4 Test (org.junit.Test)4 ACSJMSTextMessage (com.cosylab.acs.jms.ACSJMSTextMessage)2 ConnectionFactory (javax.jms.ConnectionFactory)2 Message (javax.jms.Message)2 QueueConnectionFactory (javax.jms.QueueConnectionFactory)2 Topic (javax.jms.Topic)2 ACSMailAndSmsServer (alma.alarmsystem.core.mail.ACSMailAndSmsServer)1 StatsCalculator (alma.alarmsystem.statistics.StatsCalculator)1 AlarmCacheListenerImpl (cern.laser.business.cache.AlarmCacheListenerImpl)1 AdminUserDefinitionServiceImpl (cern.laser.business.pojo.AdminUserDefinitionServiceImpl)1 AlarmCacheServerImpl (cern.laser.business.pojo.AlarmCacheServerImpl)1 AlarmDefinitionServiceImpl (cern.laser.business.pojo.AlarmDefinitionServiceImpl)1 AlarmMessageProcessorImpl (cern.laser.business.pojo.AlarmMessageProcessorImpl)1 AlarmPublisherImpl (cern.laser.business.pojo.AlarmPublisherImpl)1 AlarmSourceMonitorImpl (cern.laser.business.pojo.AlarmSourceMonitorImpl)1