本文整理匯總了Java中org.apache.activemq.filter.MessageEvaluationContext類的典型用法代碼示例。如果您正苦於以下問題:Java MessageEvaluationContext類的具體用法?Java MessageEvaluationContext怎麽用?Java MessageEvaluationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MessageEvaluationContext類屬於org.apache.activemq.filter包,在下文中一共展示了MessageEvaluationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dispatch
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
public boolean dispatch(MessageReference node, MessageEvaluationContext msgContext, List<Subscription> consumers)
throws Exception {
int count = 0;
for (Subscription sub : consumers) {
// Don't deliver to browsers
if (sub.getConsumerInfo().isBrowser()) {
continue;
}
// Only dispatch to interested subscriptions
if (!sub.matches(node, msgContext)) {
sub.unmatched(node);
continue;
}
sub.add(node);
count++;
}
return count > 0;
}
示例2: dispatch
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
/**
* @param node
* @param msgContext
* @param consumers
* @return true if dispatched
* @throws Exception
* @see org.apache.activemq.broker.region.policy.DispatchPolicy#dispatch(org.apache.activemq.broker.region.MessageReference,
* org.apache.activemq.filter.MessageEvaluationContext, java.util.List)
*/
public boolean dispatch(MessageReference node, MessageEvaluationContext msgContext, List consumers) throws Exception {
// Big synch here so that only 1 message gets dispatched at a time.
// Ensures
// Everyone sees the same order.
synchronized (consumers) {
int count = 0;
for (Iterator iter = consumers.iterator(); iter.hasNext();) {
Subscription sub = (Subscription)iter.next();
// Only dispatch to interested subscriptions
if (!sub.matches(node, msgContext)) {
sub.unmatched(node);
continue;
}
sub.add(node);
count++;
}
return count > 0;
}
}
示例3: matchesSomeConsumer
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
private boolean matchesSomeConsumer(final Broker broker, Message message, Destination dest) throws IOException {
boolean matches = false;
MessageEvaluationContext msgContext = new NonCachedMessageEvaluationContext();
msgContext.setDestination(dest.getActiveMQDestination());
msgContext.setMessageReference(message);
List<Subscription> subs = dest.getConsumers();
for (Subscription sub : subs) {
if (sub.matches(message, msgContext)) {
matches = true;
break;
}
}
if (matches == false && subs.size() == 0) {
matches = tryMatchingCachedSubs(broker, dest, msgContext);
}
return matches;
}
示例4: tryMatchingCachedSubs
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
private boolean tryMatchingCachedSubs(final Broker broker, Destination dest, MessageEvaluationContext msgContext) {
boolean matches = false;
LOG.debug("No active consumer match found. Will try cache if configured...");
//retrieve the specific plugin class and lookup the selector for the destination.
final SubQueueSelectorCacheBroker cache = getSubQueueSelectorCacheBrokerPlugin(broker);
if (cache != null) {
final String selector = cache.getSelector(dest.getActiveMQDestination().getQualifiedName());
if (selector != null) {
try {
final BooleanExpression expression = getExpression(selector);
matches = expression.matches(msgContext);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
}
return matches;
}
示例5: addRecoveredMessage
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
@Override
public boolean addRecoveredMessage(ConnectionContext context, MessageReference message) throws Exception {
boolean result = false;
MessageEvaluationContext msgContext = context.getMessageEvaluationContext();
try {
Destination regionDestination = (Destination) message.getRegionDestination();
msgContext.setDestination(regionDestination.getActiveMQDestination());
msgContext.setMessageReference(message);
result = matches(message, msgContext);
if (result) {
doAddRecoveredMessage(message);
}
} finally {
msgContext.clear();
}
return result;
}
示例6: evaluate
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
/**
* Evaluate the given expression for this function in the given context. The result of the evaluation is a
* string with all matches of the regular expression, from the evaluation of the second argument, replaced by
* the string result from the evaluation of the third argument. Replacement is performed by
* String#replaceAll().
* <p/>
* Note that all three arguments must be Strings.
*
* @param expr - the expression consisting of a call to this function.
* @return String - the result of the replacement.
*/
public Object evaluate(FunctionCallExpression expr, MessageEvaluationContext message_ctx)
throws javax.jms.JMSException {
String src;
String match_regex;
String repl_lit;
String result;
src = (String) expr.getArgument(0).evaluate(message_ctx);
match_regex = (String) expr.getArgument(1).evaluate(message_ctx);
repl_lit = (String) expr.getArgument(2).evaluate(message_ctx);
result = src.replaceAll(match_regex, repl_lit);
return result;
}
示例7: evaluate
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
/**
* Evaluate the given expression for this function in the given context. A list of zero or more strings
* results from the evaluation. The result of the evaluation of the first argument is split with the regular
* expression which results from the evaluation of the second argument. If a third argument is given, it
* is an integer which limits the split. String#split() performs the split.
* <p/>
* The first two arguments must be Strings. If a third is given, it must be an Integer.
*
* @param expr - the expression consisting of a call to this function.
* @return List - a list of Strings resulting from the split.
*/
public Object evaluate(FunctionCallExpression expr, MessageEvaluationContext message_ctx)
throws javax.jms.JMSException {
String src;
String split_pat;
String[] result;
src = (String) expr.getArgument(0).evaluate(message_ctx);
split_pat = (String) expr.getArgument(1).evaluate(message_ctx);
if (expr.getNumArguments() > 2) {
Integer limit;
limit = (Integer) expr.getArgument(2).evaluate(message_ctx);
result = src.split(split_pat, limit.intValue());
} else {
result = src.split(split_pat);
}
return java.util.Arrays.asList(result);
}
示例8: evaluate
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
/**
* Evalutate the given expression, which consists of a call to this function, in the context given. Creates
* a list containing the evaluated results of its argument expressions.
*
* @param expr - the expression consisting of a call to this function.
* @param message_ctx - the context in which the call is being evaluated.
* @return java.util.List - the result of the evaluation.
*/
public Object evaluate(FunctionCallExpression expr, MessageEvaluationContext message)
throws javax.jms.JMSException {
java.util.ArrayList ele_arr;
int num_arg;
int cur;
num_arg = expr.getNumArguments();
ele_arr = new java.util.ArrayList(num_arg);
cur = 0;
while (cur < num_arg) {
ele_arr.add(expr.getArgument(cur).evaluate(message));
cur++;
}
return (java.util.List) ele_arr;
}
示例9: evaluate
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
/**
* Evalutate the given expression, which consists of a call to this function, in the context given. Checks
* whether the second argument is a member of the list in the first argument.
*
* @param expr - the expression consisting of a call to this function.
* @param message_ctx - the context in which the call is being evaluated.
* @return Boolean - the result of the evaluation.
*/
public Object evaluate(FunctionCallExpression expr, MessageEvaluationContext message_ctx)
throws javax.jms.JMSException {
java.util.List arr;
int cur;
Object cand;
boolean found_f;
arr = (java.util.List) expr.getArgument(0).evaluate(message_ctx);
cand = expr.getArgument(1).evaluate(message_ctx);
cur = 0;
found_f = false;
while ((cur < arr.size()) && (!found_f)) {
found_f = arr.get(cur).equals(cand);
cur++;
}
return Boolean.valueOf(found_f);
}
示例10: matchesForwardingFilter
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
@Override
protected boolean matchesForwardingFilter(Message message, final MessageEvaluationContext mec) {
boolean match = true;
if (mec.getDestination().isQueue() && contains(message.getBrokerPath(), networkBrokerId)) {
// potential replay back to origin
match = allowReplayWhenNoConsumers && hasNoLocalConsumers(message, mec) && hasNotJustArrived(message);
if (match) {
LOG.trace("Replaying [{}] for [{}] back to origin in the absence of a local consumer", message.getMessageId(), message.getDestination());
} else {
LOG.trace("Suppressing replay of [{}] for [{}] back to origin {}", new Object[]{ message.getMessageId(), message.getDestination(), Arrays.asList(message.getBrokerPath())} );
}
} else {
// use existing filter logic for topics and non replays
match = super.matchesForwardingFilter(message, mec);
}
if (match && rateLimitExceeded()) {
LOG.trace("Throttled network consumer rejecting [{}] for [{}] {}>{}/{}", new Object[]{
message.getMessageId(), message.getDestination(), matchCount, rateLimit, rateDuration
});
match = false;
}
return match;
}
示例11: hasNoLocalConsumers
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
private boolean hasNoLocalConsumers(final Message message, final MessageEvaluationContext mec) {
Destination regionDestination = (Destination) mec.getMessageReference().getRegionDestination();
List<Subscription> consumers = regionDestination.getConsumers();
for (Subscription sub : consumers) {
if (!sub.getConsumerInfo().isNetworkSubscription() && !sub.getConsumerInfo().isBrowser()) {
LOG.trace("Not replaying [{}] for [{}] to origin due to existing local consumer: {}", new Object[]{
message.getMessageId(), message.getDestination(), sub.getConsumerInfo()
});
return false;
}
}
return true;
}
示例12: suppressMessageDispatch
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
private boolean suppressMessageDispatch(MessageDispatch md, DemandSubscription sub) throws Exception {
boolean suppress = false;
// for durable subs, suppression via filter leaves dangling acks so we
// need to check here and allow the ack irrespective
if (sub.getLocalInfo().isDurable()) {
MessageEvaluationContext messageEvalContext = new MessageEvaluationContext();
messageEvalContext.setMessageReference(md.getMessage());
messageEvalContext.setDestination(md.getDestination());
suppress = !sub.getNetworkBridgeFilter().matches(messageEvalContext);
}
return suppress;
}
示例13: browse
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
@Override
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 : 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]));
}
}
} catch (Throwable e) {
// TODO DELETE ME
System.out.println(e);
e.printStackTrace();
// TODO DELETE ME
LOG.warn("exception browsing destination", e);
}
}
CompositeData rc[] = new CompositeData[c.size()];
c.toArray(rc);
return rc;
}
示例14: browseMessages
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
/**
* Browses the current destination with the given selector returning a list
* of messages
*/
@Override
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 : SelectorParser.parse(selector);
for (int i = 0; i < messages.length; i++) {
try {
Message message = messages[i];
message.setReadOnlyBody(true);
if (selectorExpression == null) {
answer.add(message);
} else {
ctx.setMessageReference(message);
if (selectorExpression.matches(ctx)) {
answer.add(message);
}
}
} catch (Throwable e) {
LOG.warn("exception browsing destination", e);
}
}
return answer;
}
示例15: browseAsTable
import org.apache.activemq.filter.MessageEvaluationContext; //導入依賴的package包/類
@Override
public TabularData browseAsTable(String selector) throws OpenDataException, InvalidSelectorException {
OpenTypeFactory factory = OpenTypeSupport.getFactory(ActiveMQMessage.class);
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 : 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) {
LOG.warn("exception browsing destination", e);
}
}
return rc;
}