Package org.apache.activemq.broker.region

Examples of org.apache.activemq.broker.region.Destination


    private boolean isDestinationDLQ(Message message) {
        DeadLetterStrategy deadLetterStrategy;
        Message tmp;

        Destination regionDestination = (Destination) message.getRegionDestination();
        if (message != null && regionDestination != null) {
            deadLetterStrategy = regionDestination.getDeadLetterStrategy();
            if (deadLetterStrategy != null) {
                // Cheap copy, since we only need two fields
                tmp = new ActiveMQMessage();
                tmp.setDestination(message.getOriginalDestination());
                tmp.setRegionDestination(regionDestination);
View Full Code Here


    public Destination intercept(Destination destination) {
        Set matchingDestinations = destinationMap.get(destination.getActiveMQDestination());
        List<Destination> destinations = new ArrayList<Destination>();
        for (Iterator iter = matchingDestinations.iterator(); iter.hasNext();) {
            VirtualDestination virtualDestination = (VirtualDestination)iter.next();
            Destination newDestination = virtualDestination.intercept(destination);
            destinations.add(newDestination);
        }
        if (!destinations.isEmpty()) {
            if (destinations.size() == 1) {
                return destinations.get(0);
View Full Code Here

    protected Destination createCompositeDestination(Destination destination, final List<Destination> destinations) {
        return new DestinationFilter(destination) {
            public void send(ProducerBrokerExchange context, Message messageSend) throws Exception {
                for (Iterator<Destination> iter = destinations.iterator(); iter.hasNext();) {
                    Destination destination = iter.next();
                    destination.send(context, messageSend);
                }
            }
        };
    }
View Full Code Here

        bridgeBrokers("broker1", "broker2").start();

        // Verify that broker1 and broker2's test queues have no memory usage.
        ActiveMQDestination testQueue = createDestination(
                AMQ4147Test.class.getSimpleName() + ".queue", false);
        final Destination broker1TestQueue = broker1.getDestination(testQueue);
        final Destination broker2TestQueue = broker2.getDestination(testQueue);

        assertEquals(0, broker1TestQueue.getMemoryUsage().getUsage());
        assertEquals(0, broker2TestQueue.getMemoryUsage().getUsage());

        // Produce a message to broker1's test queue and verify that broker1's
        // memory usage has increased, but broker2 still has no memory usage.
        sendMessages("broker1", testQueue, 1);
        assertTrue(broker1TestQueue.getMemoryUsage().getUsage() > 0);
        assertEquals(0, broker2TestQueue.getMemoryUsage().getUsage());

        // Create a consumer on broker2 that is synchronized to allow detection
        // of "in flight" messages to the consumer.
        MessageIdList broker2Messages = getBrokerMessages("broker2");
        final Semaphore consumerReady = new Semaphore(0);
        final Semaphore consumerProceed = new Semaphore(0);

        broker2Messages.setParent(new MessageListener() {
            @Override
            public void onMessage(Message message) {
                consumerReady.release();
                try {
                    consumerProceed.acquire();
                } catch (InterruptedException ex) {
                    Thread.currentThread().interrupt();
                }
            }
        });

        createConsumer("broker2", testQueue);

        // Verify that when broker2's consumer receives the message, the memory
        // usage has moved broker1 to broker2. The first assertion is expected
        // to fail due to the bug; the try/finally ensures the consumer is
        // released prior to failure so that the broker can shut down.
        consumerReady.acquire();

        try {
            assertTrue("Memory Usage Should be Zero: ", Wait.waitFor(new Wait.Condition() {
                @Override
                public boolean isSatisified() throws Exception {
                    return broker1TestQueue.getMemoryUsage().getUsage() == 0;
                }
            }));
            assertTrue(broker2TestQueue.getMemoryUsage().getUsage() > 0);
        } finally {
            // Consume the message and verify that there is no more memory
            // usage.
            consumerProceed.release();
        }

        assertTrue("Memory Usage Should be Zero: ", Wait.waitFor(new Wait.Condition() {
            @Override
            public boolean isSatisified() throws Exception {
                return broker1TestQueue.getMemoryUsage().getUsage() == 0;
            }
        }));
        assertTrue("Memory Usage Should be Zero: ", Wait.waitFor(new Wait.Condition() {
            @Override
            public boolean isSatisified() throws Exception {
                return broker2TestQueue.getMemoryUsage().getUsage() == 0;
            }
        }));
    }
View Full Code Here

        runTest(new ActiveMQConnectionFactory(connectionUri));
    }

    private void runTest(ConnectionFactory connFactory) throws Exception {
        // Verify that test queue is empty and not using any memory.
        Destination physicalDestination = broker.getDestination(destination);
        Assert.assertEquals(0, physicalDestination.getMemoryUsage().getUsage());

        // Enqueue a single message and verify that the test queue is using
        // memory.
        Connection conn = connFactory.createConnection();
        conn.start();
        Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
        MessageProducer producer = session.createProducer(destination);

        producer.send(new ActiveMQMessage());

        // Commit, which ensures message is in queue and memory usage updated.
        session.commit();
        Assert.assertTrue(physicalDestination.getMemoryUsage().getUsage() > 0);

        // Consume the message and verify that the test queue is no longer using
        // any memory.
        MessageConsumer consumer = session.createConsumer(destination);
        Message received = consumer.receive();
        Assert.assertNotNull(received);

        // Commit, which ensures message is removed from queue and memory usage
        // updated.
        session.commit();
        Assert.assertEquals(0, physicalDestination.getMemoryUsage().getUsage());

        // Resend the message to a different queue and verify that the original
        // test queue is still not using any memory.
        ActiveMQQueue secondDestination = new ActiveMQQueue(AMQ4116Test.class + ".second");
        MessageProducer secondPproducer = session.createProducer(secondDestination);

        secondPproducer.send(received);

        // Commit, which ensures message is in queue and memory usage updated.
        // NOTE: This assertion fails due to bug.
        session.commit();
        Assert.assertEquals(0, physicalDestination.getMemoryUsage().getUsage());

        conn.stop();
    }
View Full Code Here

        bridgeBrokers("broker1", "broker2").start();

        // Verify that broker1 and broker2's test queues have no memory usage.
        ActiveMQDestination testQueue = createDestination(
                AMQ4147Test.class.getSimpleName() + ".queue", false);
        final Destination broker1TestQueue = broker1.getDestination(testQueue);
        final Destination broker2TestQueue = broker2.getDestination(testQueue);

        assertEquals(0, broker1TestQueue.getMemoryUsage().getUsage());
        assertEquals(0, broker2TestQueue.getMemoryUsage().getUsage());

        // Produce a message to broker1's test queue and verify that broker1's
        // memory usage has increased, but broker2 still has no memory usage.
        sendMessages("broker1", testQueue, 1);
        assertTrue(broker1TestQueue.getMemoryUsage().getUsage() > 0);
        assertEquals(0, broker2TestQueue.getMemoryUsage().getUsage());

        // Create a consumer on broker2 that is synchronized to allow detection
        // of "in flight" messages to the consumer.
        MessageIdList broker2Messages = getBrokerMessages("broker2");
        final Semaphore consumerReady = new Semaphore(0);
        final Semaphore consumerProceed = new Semaphore(0);

        broker2Messages.setParent(new MessageListener() {
            @Override
            public void onMessage(Message message) {
                consumerReady.release();
                try {
                    consumerProceed.acquire();
                } catch (InterruptedException ex) {
                    Thread.currentThread().interrupt();
                }
            }
        });

        createConsumer("broker2", testQueue);

        // Verify that when broker2's consumer receives the message, the memory
        // usage has moved broker1 to broker2.
        consumerReady.acquire();

        try {
            assertTrue("Memory Usage Should be Zero: ", Wait.waitFor(new Wait.Condition() {
                @Override
                public boolean isSatisified() throws Exception {
                    return broker1TestQueue.getMemoryUsage().getUsage() == 0;
                }
            }));
            assertTrue(broker2TestQueue.getMemoryUsage().getUsage() > 0);
        } finally {
            // Consume the message and verify that there is no more memory
            // usage.
            consumerProceed.release();
        }

        // Pause to allow ACK to be processed.
        assertTrue("Memory Usage Should be Zero: ", Wait.waitFor(new Wait.Condition() {
            @Override
            public boolean isSatisified() throws Exception {
                return broker1TestQueue.getMemoryUsage().getUsage() == 0;
            }
        }));
        assertTrue("Memory Usage Should be Zero: ", Wait.waitFor(new Wait.Condition() {
            @Override
            public boolean isSatisified() throws Exception {
                return broker2TestQueue.getMemoryUsage().getUsage() == 0;
            }
        }));
    }
View Full Code Here

        // Pause to allow subscriptions to be created.
        TimeUnit.SECONDS.sleep(5);

        // Verify that the hub has a subscription from each spoke, but that each
        // spoke has a single subscription from the hub (since the network TTL is 1).
        final Destination hubTestQueue = hub.getDestination(testQueue);
        assertTrue("Expecting {" + spokes.length + "} consumer but was {" + hubTestQueue.getConsumers().size() + "}",
            Wait.waitFor(new Wait.Condition() {

                @Override
                public boolean isSatisified() throws Exception {
                    return spokes.length == hubTestQueue.getConsumers().size();
                }
            })
        );

        // Now check each spoke has exactly one consumer on the Queue.
        for (int i = 0; i < 4; i++) {
            Destination spokeTestQueue = spokes[i].getDestination(testQueue);
            Assert.assertEquals(1, spokeTestQueue.getConsumers().size());
        }

        for (NetworkConnector nc : ncs) {
            nc.stop();
        }
View Full Code Here

        regionBroker.unregisterSubscription(sub);
        super.destroySubscription(sub);
    }

    protected Destination createDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception {
        Destination rc = super.createDestination(context, destination);
        regionBroker.register(destination, rc);
        return rc;
    }
View Full Code Here

        private boolean hasNotJustArrived(Message message) {
            return replayDelay == 0 || (message.getBrokerInTime() + replayDelay < System.currentTimeMillis());
        }

        private boolean hasNoLocalConsumers(final Message message, final MessageEvaluationContext mec) {
            Destination regionDestination = (Destination) mec.getMessageReference().getRegionDestination();
            List<Subscription> consumers = regionDestination.getConsumers();
            for (Subscription sub : consumers) {
                if (!sub.getConsumerInfo().isNetworkSubscription() && !sub.getConsumerInfo().isBrowser()) {
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("Not replaying [" + message.getMessageId() + "] for [" + message.getDestination()
                                + "] to origin due to existing local consumer: " + sub.getConsumerInfo());
View Full Code Here

        }
    }

    @Override
    public Destination addDestination(ConnectionContext context, ActiveMQDestination destination,boolean create) throws Exception {
        Destination answer = super.addDestination(context, destination,create);
        if (!AdvisorySupport.isAdvisoryTopic(destination)) {
            DestinationInfo info = new DestinationInfo(context.getConnectionId(), DestinationInfo.ADD_OPERATION_TYPE, destination);
            DestinationInfo previous = destinations.putIfAbsent(destination, info);
            if( previous==null ) {
                ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destination);
View Full Code Here

TOP

Related Classes of org.apache.activemq.broker.region.Destination

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.