Package org.apache.activemq.advisory

Examples of org.apache.activemq.advisory.DestinationSource


            connection.start();
            if (connection instanceof PooledConnection) {
                connection = ((PooledConnection) connection).getConnection();
            }
            if (connection instanceof ActiveMQConnection) {
                DestinationSource destinationSource = ((ActiveMQConnection) connection).getDestinationSource();
                Set<ActiveMQTopic> activeMQTopics = destinationSource.getTopics();
                for (ActiveMQTopic activeMQTopic : activeMQTopics) {
                    topics.add(activeMQTopic.getTopicName());
                }
            }
        } finally {
View Full Code Here


            else {
                throw new IllegalArgumentException("Created JMS Connection is not an EnhancedConnection: " + value);
            }
        }
        connection.start();
        DestinationSource source = connection.getDestinationSource();
        source.setDestinationListener(new DestinationListener() {
            public void onDestinationEvent(DestinationEvent event) {
                try {
                    ActiveMQDestination destination = event.getDestination();
                    if (destination instanceof ActiveMQQueue) {
                        ActiveMQQueue queue = (ActiveMQQueue) destination;
                        if (event.isAddOperation()) {
                            addQueue(queue);
                        }
                        else {
                            removeQueue(queue);
                        }
                    }
                    else if (destination instanceof ActiveMQTopic) {
                      ActiveMQTopic topic = (ActiveMQTopic) destination;
                      if (event.isAddOperation()) {
                          addTopic(topic);
                      }
                      else {
                          removeTopic(topic);
                      }
                    }
                }
                catch (Exception e) {
                    LOG.warn("Caught: " + e, e);
                }
            }
        });

        Set<ActiveMQQueue> queues = source.getQueues();
        for (ActiveMQQueue queue : queues) {
            addQueue(queue);
        }

        Set<ActiveMQTopic> topics = source.getTopics();
        for (ActiveMQTopic topic : topics) {
            addTopic(topic);
        }
    }
View Full Code Here

     * @return a lazily created destination source
     * @throws JMSException
     */
    public DestinationSource getDestinationSource() throws JMSException {
        if (destinationSource == null) {
            destinationSource = new DestinationSource(this);
            destinationSource.start();
        }
        return destinationSource;
    }
View Full Code Here

     * @return a lazily created destination source
     * @throws JMSException
     */
    public DestinationSource getDestinationSource() throws JMSException {
        if (destinationSource == null) {
            destinationSource = new DestinationSource(this);
            destinationSource.start();
        }
        return destinationSource;
    }
View Full Code Here

        XaPooledConnectionFactory pooledFactory =
                new XaPooledConnectionFactory(new ActiveMQXAConnectionFactory("mock:" + connector.getConnectUri() + "?closeAsync=false"));

        PooledConnection connection = (PooledConnection) pooledFactory.createConnection();
        EnhancedConnection enhancedConnection = (EnhancedConnection)connection.getConnection();
        DestinationSource destinationSource = enhancedConnection.getDestinationSource();
        assertNotNull(destinationSource);

    }
View Full Code Here

            else {
                throw new IllegalArgumentException("Created JMS Connection is not an EnhancedConnection: " + value);
            }
        }
        connection.start();
        DestinationSource source = connection.getDestinationSource();
        source.setDestinationListener(new DestinationListener() {
            public void onDestinationEvent(DestinationEvent event) {
                try {
                    ActiveMQDestination destination = event.getDestination();
                    if (destination instanceof ActiveMQQueue) {
                        ActiveMQQueue queue = (ActiveMQQueue) destination;
                        if (event.isAddOperation()) {
                            addQueue(queue);
                        }
                        else {
                            removeQueue(queue);
                        }
                    }
                    else if (destination instanceof ActiveMQTopic) {
                      ActiveMQTopic topic = (ActiveMQTopic) destination;
                      if (event.isAddOperation()) {
                          addTopic(topic);
                      }
                      else {
                          removeTopic(topic);
                      }
                    }
                }
                catch (Exception e) {
                    LOG.warn("Caught: " + e, e);
                }
            }
        });

        Set<ActiveMQQueue> queues = source.getQueues();
        for (ActiveMQQueue queue : queues) {
            addQueue(queue);
        }

        Set<ActiveMQTopic> topics = source.getTopics();
        for (ActiveMQTopic topic : topics) {
            addTopic(topic);
        }
    }
View Full Code Here

            else {
                throw new IllegalArgumentException("Created JMS Connection is not an EnhancedConnection: " + value);
            }
        }
        connection.start();
        DestinationSource source = connection.getDestinationSource();
        source.setDestinationListener(new DestinationListener() {
            public void onDestinationEvent(DestinationEvent event) {
                try {
                    ActiveMQDestination destination = event.getDestination();
                    if (destination instanceof ActiveMQQueue) {
                        ActiveMQQueue queue = (ActiveMQQueue) destination;
                        if (event.isAddOperation()) {
                            addQueue(queue);
                        }
                        else {
                            removeQueue(queue);
                        }
                    }
                    else if (destination instanceof ActiveMQTopic) {
                      ActiveMQTopic topic = (ActiveMQTopic) destination;
                      if (event.isAddOperation()) {
                          addTopic(topic);
                      }
                      else {
                          removeTopic(topic);
                      }
                    }
                }
                catch (Exception e) {
                    LOG.warn("Caught: " + e, e);
                }
            }
        });

        Set<ActiveMQQueue> queues = source.getQueues();
        for (ActiveMQQueue queue : queues) {
            addQueue(queue);
        }

        Set<ActiveMQTopic> topics = source.getTopics();
        for (ActiveMQTopic topic : topics) {
            addTopic(topic);
        }
    }
View Full Code Here

     * @throws JMSException
     */
    @Override
    public DestinationSource getDestinationSource() throws JMSException {
        if (destinationSource == null) {
            destinationSource = new DestinationSource(this);
            destinationSource.start();
        }
        return destinationSource;
    }
View Full Code Here

    @Test
    public void testRemoveDestinationWithoutSubscriber() throws Exception {

        ActiveMQConnection amqConnection = (ActiveMQConnection) createConnection(true);
        DestinationSource destinationSource = amqConnection.getDestinationSource();
        Session session = amqConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic("TEST.FOO");
        MessageProducer producer = session.createProducer(topic);
        MessageConsumer consumer = session.createConsumer(topic);

        TextMessage msg = session.createTextMessage("Hellow World");
        producer.send(msg);
        assertNotNull(consumer.receive(5000));
        Thread.sleep(1000);

        ActiveMQTopic amqTopic = (ActiveMQTopic) topic;
        assertTrue(destinationSource.getTopics().contains(amqTopic));

        consumer.close();
        producer.close();
        session.close();

        Thread.sleep(3000);
        amqConnection.destroyDestination((ActiveMQDestination) topic);
        Thread.sleep(3000);
        assertFalse(destinationSource.getTopics().contains(amqTopic));
    }
View Full Code Here

    }

    @Test
    public void testRemoveDestinationWithSubscriber() throws Exception {
        ActiveMQConnection amqConnection = (ActiveMQConnection) createConnection(true);
        DestinationSource destinationSource = amqConnection.getDestinationSource();

        Session session = amqConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic("TEST.FOO");
        MessageProducer producer = session.createProducer(topic);
        MessageConsumer consumer = session.createConsumer(topic);

        TextMessage msg = session.createTextMessage("Hellow World");
        producer.send(msg);
        assertNotNull(consumer.receive(5000));
        Thread.sleep(1000);

        ActiveMQTopic amqTopic = (ActiveMQTopic) topic;

        assertTrue(destinationPresentInAdminView(broker, amqTopic));
        assertTrue(destinationSource.getTopics().contains(amqTopic));

        // This line generates a broker error since the consumer is still active.
        try {
            amqConnection.destroyDestination((ActiveMQDestination) topic);
            fail("expect exception on destroy if comsumer present");
        } catch (JMSException expected) {
            assertTrue(expected.getMessage().indexOf(amqTopic.getTopicName()) != -1);
        }

        Thread.sleep(3000);

        assertTrue(destinationSource.getTopics().contains(amqTopic));
        assertTrue(destinationPresentInAdminView(broker, amqTopic));

        consumer.close();
        producer.close();
        session.close();

        Thread.sleep(3000);

        // The destination will not be removed with this call, but if you remove
        // the call above that generates the error it will.
        amqConnection.destroyDestination(amqTopic);
        Thread.sleep(3000);
        assertFalse(destinationSource.getTopics().contains(amqTopic));
        assertFalse(destinationPresentInAdminView(broker, amqTopic));
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.advisory.DestinationSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.