Package org.apache.activemq.filter

Examples of org.apache.activemq.filter.MessageEvaluationContext


            // Do we need to create the subscription?
            if (info == null) {
                store.addSubsciption(clientId, subscriptionName, selector, subscription.getConsumerInfo().isRetroactive());
            }
   
            final MessageEvaluationContext msgContext = new MessageEvaluationContext();
            msgContext.setDestination(destination);
            if(subscription.isRecoveryRequired()){
                store.recoverSubscription(clientId,subscriptionName,new MessageRecoveryListener(){
                    public void recoverMessage(Message message) throws Exception{
                        message.setRegionDestination(Topic.this);
                        try{
                            msgContext.setMessageReference(message);
                            if(subscription.matches(message,msgContext)){
                                subscription.add(message);
                            }
                        }catch(InterruptedException e){
                            Thread.currentThread().interrupt();
View Full Code Here


    // Implementation methods
    // -------------------------------------------------------------------------
    protected void dispatch(ConnectionContext context, Message message) throws Exception {
        destinationStatistics.getEnqueues().increment();
        dispatchValve.increment();
        MessageEvaluationContext msgContext = context.getMessageEvaluationContext();
        try {
            if (!subscriptionRecoveryPolicy.add(context, message)) {
                return;
            }
            synchronized(consumers) {
                if (consumers.isEmpty()) {
                    onMessageWithNoConsumers(context, message);
                    return;
                }
            }

            msgContext.setDestination(destination);
            msgContext.setMessageReference(message);

            if (!dispatchPolicy.dispatch(context, message, msgContext, consumers)) {
                onMessageWithNoConsumers(context, message);
            }
        }
        finally {
            msgContext.clear();
            dispatchValve.decrement();
        }
    }
View Full Code Here

            ConsumerId consumerId = sub.getConsumerInfo().getConsumerId();
            MessageGroupSet ownedGroups = getMessageGroupOwners().removeConsumer(consumerId);

            if (!sub.getConsumerInfo().isBrowser()) {
                MessageEvaluationContext msgContext = context.getMessageEvaluationContext();
                try {
                    msgContext.setDestination(destination);

                    // lets copy the messages to dispatch to avoid deadlock
                    List messagesToDispatch = new ArrayList();
                    synchronized (messages) {
                        messages.reset();
                        while(messages.hasNext()) {
                            QueueMessageReference node = (QueueMessageReference) messages.next();
                            if (node.isDropped()) {
                                continue;
                            }

                            String groupID = node.getGroupID();

                            // Re-deliver all messages that the sub locked
                            if (node.getLockOwner() == sub || wasExclusiveOwner || (groupID != null && ownedGroups.contains(groupID))) {
                                messagesToDispatch.add(node);
                            }
                        }
                    }

                    // now lets dispatch from the copy of the collection to
                    // avoid deadlocks
                    for (Iterator iter = messagesToDispatch.iterator(); iter.hasNext();) {
                        QueueMessageReference node = (QueueMessageReference) iter.next();
                        node.incrementRedeliveryCounter();
                        node.unlock();
                        msgContext.setMessageReference(node);
                        dispatchPolicy.dispatch(context, node, msgContext, consumers);
                    }
                }
                finally {
                    msgContext.clear();
                }
            }
        }
        finally {
            dispatchValve.turnOn();
View Full Code Here

    }

    private void dispatch(ConnectionContext context, MessageReference node, Message message) throws Exception {

        dispatchValve.increment();
        MessageEvaluationContext msgContext = context.getMessageEvaluationContext();
        try {
            destinationStatistics.getEnqueues().increment();
      destinationStatistics.getMessages().increment();
            synchronized (messages) {
                messages.addMessageLast(node);
            }

            synchronized (consumers) {
                if (consumers.isEmpty()) {
                    log.debug("No subscriptions registered, will not dispatch message at this time.");
                    return;
                }
            }

            msgContext.setDestination(destination);
            msgContext.setMessageReference(node);

            dispatchPolicy.dispatch(context, node, msgContext, consumers);
        }
        finally {
            msgContext.clear();
            dispatchValve.decrement();
        }
    }
View Full Code Here

    protected MessageReferenceFilter createSelectorFilter(String selector) throws InvalidSelectorException {
        final BooleanExpression selectorExpression = new SelectorParser().parse(selector);

        return new MessageReferenceFilter() {
            public boolean evaluate(ConnectionContext context, MessageReference r) throws JMSException {
                MessageEvaluationContext messageEvaluationContext = context.getMessageEvaluationContext();
               
                messageEvaluationContext.setMessageReference(r);
                if (messageEvaluationContext.getDestination() == null) {
                    messageEvaluationContext.setDestination(getActiveMQDestination());
                }
               
                return selectorExpression.matches(messageEvaluationContext);
            }
        };
View Full Code Here

        return query.validateUpdate(message.getMessage());
    }

    public void recover(ConnectionContext context, final Topic topic, final Subscription sub) throws Exception {
        if (query != null) {
            final MessageEvaluationContext msgContext = context.getMessageEvaluationContext();
            try {
                ActiveMQDestination destination = sub.getConsumerInfo().getDestination();
                query.execute(destination, new MessageListener() {
                    public void onMessage(Message message) {
                        dispatchInitialMessage(message, topic, msgContext, sub);
                    }
                });
            }
            finally {
                msgContext.clear();
            }
        }
    }
View Full Code Here

    public void recover(ConnectionContext context, Topic topic, Subscription sub) throws Exception {
        // Re-dispatch the last message seen.
        MessageReference node = lastImage;
        if( node != null ){
            MessageEvaluationContext msgContext = context.getMessageEvaluationContext();
            try {
                msgContext.setDestination(node.getRegionDestination().getActiveMQDestination());
                msgContext.setMessageReference(node);                       
                if (sub.matches(node, msgContext)) {
                    sub.add(node);
                }
            } finally {
                msgContext.clear();
            }
        }
    }
View Full Code Here

    }

    protected void assertSelector(Message message, String text, boolean expected) throws JMSException {
        BooleanExpression selector = SelectorParser.parse(text);
        assertTrue("Created a valid selector", selector != null);
        MessageEvaluationContext context = new MessageEvaluationContext();
        context.setMessageReference((org.apache.activemq.command.Message)message);
        boolean value = selector.matches(context);
        assertEquals("Selector for: " + text, expected, value);
    }
View Full Code Here

    }
   
       
    @Override
    public synchronized boolean recoverMessage(Message message, boolean cached) throws Exception {
        MessageEvaluationContext messageEvaluationContext = new NonCachedMessageEvaluationContext();
        messageEvaluationContext.setMessageReference(message);
        if (this.subscription.matches(message, messageEvaluationContext)) {
            return super.recoverMessage(message, cached);
        }
        return false;
       
View Full Code Here

                    LOG.debug("dispatch to browser: " + pendingBrowserDispatch.getBrowser()
                            + ", already dispatched/paged count: " + alreadyDispatchedMessages.size());
                }
                do {
                    try {
                        MessageEvaluationContext msgContext = new NonCachedMessageEvaluationContext();
                        msgContext.setDestination(destination);

                        QueueBrowserSubscription browser = pendingBrowserDispatch.getBrowser();
                        for (QueueMessageReference node : alreadyDispatchedMessages) {
                            if (!node.isAcked()) {
                                msgContext.setMessageReference(node);
                                if (browser.matches(node, msgContext)) {
                                    browser.add(node);
                                }
                            }
                        }
View Full Code Here

TOP

Related Classes of org.apache.activemq.filter.MessageEvaluationContext

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.