Search in sources :

Example 21 with Filter

use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.

the class QueueControlImpl method countMessages.

@Override
public long countMessages(final String filterStr) throws Exception {
    checkStarted();
    clearIO();
    try {
        Filter filter = FilterImpl.createFilter(filterStr);
        if (filter == null) {
            return getMessageCount();
        } else {
            try (LinkedListIterator<MessageReference> iterator = queue.browserIterator()) {
                int count = 0;
                try {
                    while (iterator.hasNext()) {
                        MessageReference ref = iterator.next();
                        if (filter.match(ref.getMessage())) {
                            count++;
                        }
                    }
                } catch (NoSuchElementException ignored) {
                // this could happen through paging browsing
                }
                return count;
            }
        }
    } finally {
        blockOnIO();
    }
}
Also used : Filter(org.apache.activemq.artemis.core.filter.Filter) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) NoSuchElementException(java.util.NoSuchElementException)

Example 22 with Filter

use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.

the class QueueControlImpl method changeMessagesPriority.

@Override
public int changeMessagesPriority(final String filterStr, final int newPriority) throws Exception {
    checkStarted();
    clearIO();
    try {
        if (newPriority < 0 || newPriority > 9) {
            throw ActiveMQMessageBundle.BUNDLE.invalidNewPriority(newPriority);
        }
        Filter filter = FilterImpl.createFilter(filterStr);
        return queue.changeReferencesPriority(filter, (byte) newPriority);
    } finally {
        blockOnIO();
    }
}
Also used : Filter(org.apache.activemq.artemis.core.filter.Filter)

Example 23 with Filter

use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.

the class QueueControlImpl method listMessages.

@Override
public Map<String, Object>[] listMessages(final String filterStr) throws Exception {
    checkStarted();
    clearIO();
    try {
        Filter filter = FilterImpl.createFilter(filterStr);
        List<Map<String, Object>> messages = new ArrayList<>();
        queue.flushExecutor();
        try (LinkedListIterator<MessageReference> iterator = queue.browserIterator()) {
            try {
                while (iterator.hasNext()) {
                    MessageReference ref = iterator.next();
                    if (filter == null || filter.match(ref.getMessage())) {
                        Message message = ref.getMessage();
                        messages.add(message.toMap());
                    }
                }
            } catch (NoSuchElementException ignored) {
            // this could happen through paging browsing
            }
            return messages.toArray(new Map[messages.size()]);
        }
    } catch (ActiveMQException e) {
        throw new IllegalStateException(e.getMessage());
    } finally {
        blockOnIO();
    }
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Filter(org.apache.activemq.artemis.core.filter.Filter) ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) HashMap(java.util.HashMap) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException)

Example 24 with Filter

use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.

the class QueueControlImpl method browse.

@Override
public CompositeData[] browse(int page, int pageSize) throws Exception {
    String filter = null;
    checkStarted();
    clearIO();
    try {
        long index = 0;
        long start = (page - 1) * pageSize;
        long end = Math.min(page * pageSize, queue.getMessageCount());
        ArrayList<CompositeData> c = new ArrayList<>();
        Filter thefilter = FilterImpl.createFilter(filter);
        queue.flushExecutor();
        try (LinkedListIterator<MessageReference> iterator = queue.browserIterator()) {
            try {
                while (iterator.hasNext() && index < end) {
                    MessageReference ref = iterator.next();
                    if (thefilter == null || thefilter.match(ref.getMessage())) {
                        if (index >= start) {
                            c.add(OpenTypeSupport.convert(ref));
                        }
                    }
                    index++;
                }
            } catch (NoSuchElementException ignored) {
            // this could happen through paging browsing
            }
            CompositeData[] rc = new CompositeData[c.size()];
            c.toArray(rc);
            return rc;
        }
    } catch (ActiveMQException e) {
        throw new IllegalStateException(e.getMessage());
    } finally {
        blockOnIO();
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Filter(org.apache.activemq.artemis.core.filter.Filter) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) NoSuchElementException(java.util.NoSuchElementException)

Example 25 with Filter

use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.

the class QueueImplTest method testGetFilter.

@Test
public void testGetFilter() {
    QueueImpl queue = getTemporaryQueue();
    Assert.assertNull(queue.getFilter());
    Filter filter = new Filter() {

        @Override
        public boolean match(final Message message) {
            return false;
        }

        @Override
        public SimpleString getFilterString() {
            return null;
        }
    };
    queue = getFilteredQueue(filter);
    Assert.assertEquals(filter, queue.getFilter());
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) Filter(org.apache.activemq.artemis.core.filter.Filter) FakeFilter(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Aggregations

Filter (org.apache.activemq.artemis.core.filter.Filter)30 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)18 Binding (org.apache.activemq.artemis.core.postoffice.Binding)9 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 ArrayList (java.util.ArrayList)7 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)7 Test (org.junit.Test)7 Queue (org.apache.activemq.artemis.core.server.Queue)6 QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)6 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)5 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)5 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)5 QueueConfig (org.apache.activemq.artemis.core.server.QueueConfig)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 Message (org.apache.activemq.artemis.api.core.Message)4 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)4 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)4 DivertBinding (org.apache.activemq.artemis.core.postoffice.impl.DivertBinding)4 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)4 HierarchicalRepository (org.apache.activemq.artemis.core.settings.HierarchicalRepository)4