Search in sources :

Example 1 with Filter

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

the class PostOfficeImpl method addBinding.

// TODO - needs to be synchronized to prevent happening concurrently with activate()
// (and possible removeBinding and other methods)
// Otherwise can have situation where createQueue comes in before failover, then failover occurs
// and post office is activated but queue remains unactivated after failover so delivery never occurs
// even though failover is complete
@Override
public synchronized void addBinding(final Binding binding) throws Exception {
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeAddBinding(binding));
    }
    addressManager.addBinding(binding);
    TypedProperties props = new TypedProperties();
    props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, binding.getType().toInt());
    props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());
    props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
    props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
    props.putLongProperty(ManagementHelper.HDR_BINDING_ID, binding.getID());
    props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
    Filter filter = binding.getFilter();
    if (filter != null) {
        props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filter.getFilterString());
    }
    String uid = UUIDGenerator.getInstance().generateStringUUID();
    if (logger.isDebugEnabled()) {
        logger.debug("ClusterCommunication::Sending notification for addBinding " + binding + " from server " + server);
    }
    managementService.sendNotification(new Notification(uid, CoreNotificationType.BINDING_ADDED, props));
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterAddBinding(binding));
    }
}
Also used : Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 2 with Filter

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

the class QueueControlImpl method expireMessages.

@Override
public int expireMessages(final String filterStr) throws Exception {
    checkStarted();
    clearIO();
    try {
        Filter filter = FilterImpl.createFilter(filterStr);
        return queue.expireReferences(filter);
    } 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)

Example 3 with Filter

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

the class QueueControlImpl method moveMessages.

@Override
public int moveMessages(final int flushLimit, final String filterStr, final String otherQueueName, final boolean rejectDuplicates) throws Exception {
    checkStarted();
    clearIO();
    try {
        Filter filter = FilterImpl.createFilter(filterStr);
        Binding binding = postOffice.getBinding(new SimpleString(otherQueueName));
        if (binding == null) {
            throw ActiveMQMessageBundle.BUNDLE.noQueueFound(otherQueueName);
        }
        int retValue = queue.moveReferences(flushLimit, filter, binding.getAddress(), rejectDuplicates, binding);
        return retValue;
    } finally {
        blockOnIO();
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 4 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(String filter) throws Exception {
    checkStarted();
    clearIO();
    try {
        int pageSize = addressSettingsRepository.getMatch(queue.getName().toString()).getManagementBrowsePageSize();
        int currentPageSize = 0;
        ArrayList<CompositeData> c = new ArrayList<>();
        Filter thefilter = FilterImpl.createFilter(filter);
        queue.flushExecutor();
        try (LinkedListIterator<MessageReference> iterator = queue.browserIterator()) {
            try {
                while (iterator.hasNext() && currentPageSize++ < pageSize) {
                    MessageReference ref = iterator.next();
                    if (thefilter == null || thefilter.match(ref.getMessage())) {
                        c.add(OpenTypeSupport.convert(ref));
                    }
                }
            } 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) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with Filter

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

the class QueueControlImpl method sendMessagesToDeadLetterAddress.

@Override
public int sendMessagesToDeadLetterAddress(final String filterStr) throws Exception {
    checkStarted();
    clearIO();
    try {
        Filter filter = FilterImpl.createFilter(filterStr);
        return queue.sendMessagesToDeadLetterAddress(filter);
    } finally {
        blockOnIO();
    }
}
Also used : Filter(org.apache.activemq.artemis.core.filter.Filter)

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