Search in sources :

Example 1 with TopicSession

use of javax.jms.TopicSession 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 2 with TopicSession

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

the class DynamicDestinationResolverTests method resolveWithPubSubTopicSession.

@Test
public void resolveWithPubSubTopicSession() throws Exception {
    Topic expectedDestination = new StubTopic();
    TopicSession session = mock(TopicSession.class);
    given(session.createTopic(DESTINATION_NAME)).willReturn(expectedDestination);
    testResolveDestination(session, expectedDestination, true);
}
Also used : StubTopic(org.springframework.jms.StubTopic) TopicSession(javax.jms.TopicSession) Topic(javax.jms.Topic) StubTopic(org.springframework.jms.StubTopic) Test(org.junit.Test)

Example 3 with TopicSession

use of javax.jms.TopicSession 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)

Example 4 with TopicSession

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

the class DefaultSubscriberImpl method subscribe.

/**
   * Method subscribe
   *
   *
   * @param topic
   * @param listener
   * @param selector
   *
   * @return long the subscription handle identifier
   *
   * @throws JMSException
   * @throws NamingException
   *
   */
public long subscribe(String topic, SubscriptionListener listener, String selector) throws JMSException, NamingException {
    cat.info("subscribe(" + topic + ", listener, " + selector + ")");
    if (closed) {
        throw (new JMSException("Subscriber closed."));
    }
    SubscriptionHandle handle = new SubscriptionHandle();
    handle.setSubscriptionTopic(topic);
    handle.setSubscriptionSelector(selector);
    handle.setSubscriptionListener(listener);
    StringBuffer local_selector = new StringBuffer();
    if (NotificationHelper.isNotification(topic)) {
        // this is a subscription to notifications, no further selection is required
        local_selector.append(selector);
    } else {
        // subscription to a generic topic, adding subscriber specific selection
        if (selector != null) {
            local_selector.append(selector);
            local_selector.append(" AND ");
        }
        local_selector.append("( (");
        local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
        local_selector.append(" IS NULL) OR (");
        local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
        local_selector.append(" = '");
        local_selector.append(subscriberId);
        local_selector.append("@");
        local_selector.append(handle.getSubscriptionToken());
        local_selector.append("') )");
    }
    TopicSession session = null;
    TopicSubscriber subscriber = null;
    Topic the_topic = createTopic(topic);
    try {
        session = connection.createTopicSession();
        subscriber = session.createSubscriber(the_topic, local_selector.toString(), false);
    } catch (JMSSecurityException jse) {
        cat.error("JMSSecurityException caught");
        throw (new NamingException(jse.getMessage()));
    } catch (JMSException je) {
        cat.error("JMSException caught");
        throw (new NamingException(je.getMessage()));
    } catch (ConnectionException ce) {
        cat.error("ConnectionException caught");
        throw (new JMSException(ce.getMessage()));
    } catch (Exception e) {
        cat.error("Generic exception caught", e);
    }
    subscriber.setMessageListener(listener);
    handle.setSubscriber(subscriber);
    handle.setSession(session);
    synchronized (subscribers) {
        subscribers.put(new Long(handle.getSubscriptionToken()), handle);
    }
    if (!NotificationHelper.isNotification(topic)) {
        publishNotification(NotificationHelper.CONSUMER_OPEN_NOTIFICATION, handle);
    }
    return handle.getSubscriptionToken();
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) JMSSecurityException(javax.jms.JMSSecurityException) JMSException(javax.jms.JMSException) NamingException(javax.naming.NamingException) Topic(javax.jms.Topic) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) MOMException(cern.cmw.mom.pubsub.MOMException) JMSSecurityException(javax.jms.JMSSecurityException)

Example 5 with TopicSession

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

the class DefaultSubscriberImpl method recoverSubscriptions.

/**
   * Method recoverSubscriptions
   *
   */
protected void recoverSubscriptions() {
    cat.info("recoverSubscriptions()");
    try {
        SubscriptionHandle handle = null;
        Iterator iterator = subscribers.values().iterator();
        while (iterator.hasNext()) {
            handle = (SubscriptionHandle) iterator.next();
            if (!NotificationHelper.isNotification(handle.getSubscriptionTopic())) {
                publishNotification(NotificationHelper.CONSUMER_CLOSE_NOTIFICATION, handle);
            }
            cat.debug("Recovering subscription to : " + handle.getSubscriptionTopic());
            TopicSession session = connection.createTopicSession();
            TopicSubscriber subscriber = session.createSubscriber(createTopic(handle.getSubscriptionTopic()), handle.getSubscriptionSelector(), false);
            subscriber.setMessageListener(handle.getSubscriptionListener());
            handle.setSession(session);
            handle.setSubscriber(subscriber);
            if (!NotificationHelper.isNotification(handle.getSubscriptionTopic())) {
                publishNotification(NotificationHelper.CONSUMER_OPEN_NOTIFICATION, handle);
            }
        }
        cat.info("Subscriptions succesfully recovered.");
    } catch (Exception e) {
        cat.error("unable to recover subscriptions", e);
    }
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) Iterator(java.util.Iterator) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) MOMException(cern.cmw.mom.pubsub.MOMException) JMSSecurityException(javax.jms.JMSSecurityException)

Aggregations

TopicSession (javax.jms.TopicSession)7 Topic (javax.jms.Topic)4 TopicConnection (javax.jms.TopicConnection)4 TopicSubscriber (javax.jms.TopicSubscriber)3 MOMException (cern.cmw.mom.pubsub.MOMException)2 ACSJMSTextMessage (com.cosylab.acs.jms.ACSJMSTextMessage)2 JMSException (javax.jms.JMSException)2 JMSSecurityException (javax.jms.JMSSecurityException)2 Message (javax.jms.Message)2 TopicConnectionFactory (javax.jms.TopicConnectionFactory)2 NamingException (javax.naming.NamingException)2 Test (org.junit.Test)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