use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.
the class BindingsImpl method getNextBinding.
/**
* This code has a race on the assigned value to routing names.
* <p>
* This is not that much of an issue because<br>
* Say you have the same queue name bound into two servers. The routing will load balance between
* these two servers. This will eventually send more messages to one server than the other
* (depending if you are using multi-thread), and not lose messages.
*/
private Binding getNextBinding(final Message message, final SimpleString routingName, final List<Binding> bindings) {
Integer ipos = routingNamePositions.get(routingName);
int pos = ipos != null ? ipos : 0;
int length = bindings.size();
int startPos = pos;
Binding theBinding = null;
int lastLowPriorityBinding = -1;
while (true) {
Binding binding;
try {
binding = bindings.get(pos);
} catch (IndexOutOfBoundsException e) {
// This can occur if binding is removed while in route
if (!bindings.isEmpty()) {
pos = 0;
startPos = 0;
length = bindings.size();
continue;
} else {
break;
}
}
Filter filter = binding.getFilter();
if (filter == null || filter.match(message)) {
// unnecessary overhead)
if (length == 1 || (binding.isConnected() && (messageLoadBalancingType.equals(MessageLoadBalancingType.STRICT) || binding.isHighAcceptPriority(message)))) {
theBinding = binding;
pos = incrementPos(pos, length);
break;
} else {
// the localQueue should always have the priority over the secondary bindings
if (lastLowPriorityBinding == -1 || messageLoadBalancingType.equals(MessageLoadBalancingType.ON_DEMAND) && binding instanceof LocalQueueBinding) {
lastLowPriorityBinding = pos;
}
}
}
pos = incrementPos(pos, length);
if (pos == startPos) {
// if no bindings were found, we will apply a secondary level on the routing logic
if (lastLowPriorityBinding != -1) {
try {
theBinding = bindings.get(lastLowPriorityBinding);
} catch (IndexOutOfBoundsException e) {
// This can occur if binding is removed while in route
if (!bindings.isEmpty()) {
pos = 0;
lastLowPriorityBinding = -1;
continue;
} else {
break;
}
}
pos = incrementPos(lastLowPriorityBinding, length);
}
break;
}
}
if (pos != startPos) {
routingNamePositions.put(routingName, pos);
}
if (messageLoadBalancingType.equals(MessageLoadBalancingType.OFF) && theBinding instanceof RemoteQueueBinding) {
theBinding = getNextBinding(message, routingName, bindings);
}
return theBinding;
}
use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.
the class BindingsImpl method redistribute.
@Override
public boolean redistribute(final Message message, final Queue originatingQueue, final RoutingContext context) throws Exception {
if (messageLoadBalancingType.equals(MessageLoadBalancingType.STRICT) || messageLoadBalancingType.equals(MessageLoadBalancingType.OFF)) {
return false;
}
if (logger.isTraceEnabled()) {
logger.trace("Redistributing message " + message);
}
SimpleString routingName = originatingQueue.getName();
List<Binding> bindings = routingNameBindingMap.get(routingName);
if (bindings == null) {
// ConcurrentHashMap behaviour!
return false;
}
Integer ipos = routingNamePositions.get(routingName);
int pos = ipos != null ? ipos.intValue() : 0;
int length = bindings.size();
int startPos = pos;
Binding theBinding = null;
// TODO - combine this with similar logic in route()
while (true) {
Binding binding;
try {
binding = bindings.get(pos);
} catch (IndexOutOfBoundsException e) {
// This can occur if binding is removed while in route
if (!bindings.isEmpty()) {
pos = 0;
startPos = 0;
length = bindings.size();
continue;
} else {
break;
}
}
pos = incrementPos(pos, length);
Filter filter = binding.getFilter();
boolean highPrior = binding.isHighAcceptPriority(message);
if (highPrior && binding.getBindable() != originatingQueue && (filter == null || filter.match(message))) {
theBinding = binding;
break;
}
if (pos == startPos) {
break;
}
}
routingNamePositions.put(routingName, pos);
if (theBinding != null) {
theBinding.route(message, context);
return true;
} else {
return false;
}
}
use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.
the class QueueControlImpl method retryMessage.
@Override
public boolean retryMessage(final long messageID) throws Exception {
checkStarted();
clearIO();
try {
Filter singleMessageFilter = new Filter() {
@Override
public boolean match(Message message) {
return message.getMessageID() == messageID;
}
@Override
public SimpleString getFilterString() {
return new SimpleString("custom filter for MESSAGEID= messageID");
}
};
return queue.retryMessages(singleMessageFilter) > 0;
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.
the class QueueControlImpl method getFilter.
@Override
public String getFilter() {
checkStarted();
clearIO();
try {
Filter filter = queue.getFilter();
return filter != null ? filter.getFilterString().toString() : null;
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.
the class QueueControlImpl method removeMessages.
@Override
public int removeMessages(final int flushLimit, final String filterStr) throws Exception {
checkStarted();
clearIO();
try {
Filter filter = FilterImpl.createFilter(filterStr);
return queue.deleteMatchingReferences(flushLimit, filter);
} finally {
blockOnIO();
}
}
Aggregations