Package org.apache.activemq.filter

Examples of org.apache.activemq.filter.MessageEvaluationContext


    public CompositeData[] browse(String selector) throws OpenDataException, InvalidSelectorException {
        Message[] messages = destination.browse();
        ArrayList<CompositeData> c = new ArrayList<CompositeData>();

        MessageEvaluationContext ctx = new MessageEvaluationContext();
        ctx.setDestination(destination.getActiveMQDestination());
        BooleanExpression selectorExpression = selector == null ? null : new SelectorParser().parse(selector);

        for (int i = 0; i < messages.length; i++) {
            try {

                if (selectorExpression == null) {
                    c.add(OpenTypeSupport.convert(messages[i]));
                } else {
                    ctx.setMessageReference(messages[i]);
                    if (selectorExpression.matches(ctx)) {
                        c.add(OpenTypeSupport.convert(messages[i]));
                    }
                }
View Full Code Here


     */
    public List<Object> browseMessages(String selector) throws InvalidSelectorException {
        Message[] messages = destination.browse();
        ArrayList<Object> answer = new ArrayList<Object>();

        MessageEvaluationContext ctx = new MessageEvaluationContext();
        ctx.setDestination(destination.getActiveMQDestination());
        BooleanExpression selectorExpression = selector == null ? null : new SelectorParser().parse(selector);

        for (int i = 0; i < messages.length; i++) {
            try {
                Message message = messages[i];
                if (selectorExpression == null) {
                    answer.add(OpenTypeSupport.convert(message));
                } else {
                    ctx.setMessageReference(message);
                    if (selectorExpression.matches(ctx)) {
                        answer.add(message);
                    }
                }

View Full Code Here

        Message[] messages = destination.browse();
        CompositeType ct = factory.getCompositeType();
        TabularType tt = new TabularType("MessageList", "MessageList", ct, new String[] {"JMSMessageID"});
        TabularDataSupport rc = new TabularDataSupport(tt);

        MessageEvaluationContext ctx = new MessageEvaluationContext();
        ctx.setDestination(destination.getActiveMQDestination());
        BooleanExpression selectorExpression = selector == null ? null : new SelectorParser().parse(selector);

        for (int i = 0; i < messages.length; i++) {
            try {
                if (selectorExpression == null) {
                    rc.put(new CompositeDataSupport(ct, factory.getFields(messages[i])));
                } else {
                    ctx.setMessageReference(messages[i]);
                    if (selectorExpression.matches(ctx)) {
                        rc.put(new CompositeDataSupport(ct, factory.getFields(messages[i])));
                    }
                }
            } catch (Throwable e) {
View Full Code Here

    public synchronized  void addSubscription(ConnectionContext context, Subscription sub) throws Exception {
        sub.add(context, this);
        destinationStatistics.getConsumers().increment();
        maximumPagedInMessages += sub.getConsumerInfo().getPrefetchSize();

        MessageEvaluationContext msgContext = context.getMessageEvaluationContext();
        try {
         
          //needs to be synchronized - so no contention with dispatching
            synchronized (consumers) {
                consumers.add(sub);
                if (sub.getConsumerInfo().isExclusive()) {
                    LockOwner owner = (LockOwner)sub;
                    if (exclusiveOwner == null) {
                        exclusiveOwner = owner;
                    } else {
                        // switch the owner if the priority is higher.
                        if (owner.getLockPriority() > exclusiveOwner.getLockPriority()) {
                            exclusiveOwner = owner;
                        }
                    }
                }
            }
           
            //we hold the lock on the dispatchValue - so lets build the paged in
            //list directly;
            buildList(false);
          
            // synchronize with dispatch method so that no new messages are sent
            // while
            // setting up a subscription. avoid out of order messages,
            // duplicates
            // etc. 
           
        
           
                msgContext.setDestination(destination);
                synchronized (pagedInMessages) {
                    // Add all the matching messages in the queue to the
                    // subscription.
                    for (Iterator<MessageReference> i = pagedInMessages.iterator(); i.hasNext();) {
                        QueueMessageReference node = (QueueMessageReference)i.next();
                        if (node.isDropped() ||  (!sub.getConsumerInfo().isBrowser() && node.getLockOwner()!=null)) {
                            continue;
                        }
                        try {
                            msgContext.setMessageReference(node);
                            if (sub.matches(node, msgContext)) {
                                sub.add(node);
                            }
                        } catch (IOException e) {
                            log.warn("Could not load message: " + e, e);
                        }
                    }
                }
         
           
           
        } finally {
            msgContext.clear();
        }
    }
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<QueueMessageReference> messagesToDispatch=new ArrayList<QueueMessageReference>();
        synchronized(pagedInMessages){
          for(Iterator<MessageReference> i=pagedInMessages.iterator();i
                  .hasNext();){
            QueueMessageReference node=(QueueMessageReference)i
                    .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<QueueMessageReference> iter=messagesToDispatch
                .iterator();iter.hasNext();){
          QueueMessageReference node=iter.next();
          node.incrementRedeliveryCounter();
          node.unlock();
          msgContext.setMessageReference(node);
          dispatchPolicy.dispatch(node,msgContext,consumers);
        }
      }finally{
        msgContext.clear();
      }
    }
  }
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

    public void finished() {
    }

    public synchronized boolean recoverMessage(Message message)
            throws Exception {
        MessageEvaluationContext messageEvaluationContext = new MessageEvaluationContext();
        messageEvaluationContext.setMessageReference(message);
        if (subscription.matches(message, messageEvaluationContext)) {
            message.setRegionDestination(regionDestination);
            if (!isDuplicate(message.getMessageId())) {
                // only increment if count is zero (could have been cached)
                if (message.getReferenceCount() == 0) {
View Full Code Here

        this.forwardOnly = forwardOnly;
        this.copyMessage = copyMessage;
    }

    public void send(ProducerBrokerExchange context, Message message) throws Exception {
        MessageEvaluationContext messageContext = null;

        for (Iterator iter = forwardDestinations.iterator(); iter.hasNext();) {
            ActiveMQDestination destination = null;
            Object value = iter.next();

            if (value instanceof FilteredDestination) {
                FilteredDestination filteredDestination = (FilteredDestination)value;
                if (messageContext == null) {
                    messageContext = new MessageEvaluationContext();
                    messageContext.setMessageReference(message);
                }
                messageContext.setDestination(filteredDestination.getDestination());
                if (filteredDestination.matches(messageContext)) {
                    destination = filteredDestination.getDestination();
                }
            } else if (value instanceof ActiveMQDestination) {
                destination = (ActiveMQDestination)value;
View Full Code Here

        return true;
    }

    public boolean addRecoveredMessage(ConnectionContext context, MessageReference message) throws Exception {
        boolean result = false;
        MessageEvaluationContext msgContext = context.getMessageEvaluationContext();
        try {
            msgContext.setDestination(message.getRegionDestination().getActiveMQDestination());
            msgContext.setMessageReference(message);
            result = matches(message, msgContext);
            if (result) {
                doAddRecoveredMessage(message);
            }

        } finally {
            msgContext.clear();
        }
        return result;
    }
View Full Code Here

    // Implementation methods
    // -------------------------------------------------------------------------
    protected void dispatch(final 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(message, msgContext, consumers)) {
                onMessageWithNoConsumers(context, message);
            }
        } finally {
            msgContext.clear();
            dispatchValve.decrement();
        }
    }
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.