Search in sources :

Example 1 with RoutingNodeIterator

use of com.yahoo.messagebus.routing.RoutingNodeIterator in project vespa by vespa-engine.

the class DocumentProtocol method merge.

/**
 * This method implements the common way to merge document replies for whatever routing policy. In case of an error
 * in any of the replies, it will prepare an EmptyReply() and add all errors to it. If there are no errors, this
 * method will use the first reply in the list and transfer whatever feed answers might exist in the replies to it.
 *
 * @param ctx  The context whose children to merge.
 * @param mask The indexes of the children to skip.
 */
public static void merge(RoutingContext ctx, Set<Integer> mask) {
    List<Reply> replies = new LinkedList<>();
    for (RoutingNodeIterator it = ctx.getChildIterator(); it.isValid(); it.next()) {
        Reply ref = it.getReplyRef();
        replies.add(ref);
    }
    Tuple2<Integer, Reply> tuple = merge(replies, mask);
    if (tuple.first != null) {
        ctx.getChildIterator().skip(tuple.first).removeReply();
    }
    ctx.setReply(tuple.second);
}
Also used : RoutingNodeIterator(com.yahoo.messagebus.routing.RoutingNodeIterator) Reply(com.yahoo.messagebus.Reply) LinkedList(java.util.LinkedList)

Example 2 with RoutingNodeIterator

use of com.yahoo.messagebus.routing.RoutingNodeIterator in project vespa by vespa-engine.

the class CustomPolicy method merge.

public void merge(RoutingContext context) {
    List<String> lst = new ArrayList<String>();
    Reply ret = new EmptyReply();
    for (RoutingNodeIterator it = context.getChildIterator(); it.isValid(); it.next()) {
        lst.add(it.getRoute().toString());
        Reply reply = it.getReplyRef();
        for (int i = 0; i < reply.getNumErrors(); ++i) {
            ret.addError(reply.getError(i));
        }
    }
    context.setReply(ret);
    context.trace(1, "Merged " + lst + ".");
}
Also used : RoutingNodeIterator(com.yahoo.messagebus.routing.RoutingNodeIterator) ArrayList(java.util.ArrayList) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 3 with RoutingNodeIterator

use of com.yahoo.messagebus.routing.RoutingNodeIterator in project vespa by vespa-engine.

the class LoadBalancerPolicy method merge.

public void merge(RoutingContext context) {
    RoutingNodeIterator it = context.getChildIterator();
    Reply reply = it.removeReply();
    LoadBalancer.Node target = (LoadBalancer.Node) context.getContext();
    boolean busy = false;
    for (int i = 0; i < reply.getNumErrors(); i++) {
        if (reply.getError(i).getCode() == ErrorCode.SESSION_BUSY) {
            busy = true;
        }
    }
    loadBalancer.received(target, busy);
    context.setReply(reply);
}
Also used : RoutingNodeIterator(com.yahoo.messagebus.routing.RoutingNodeIterator) Reply(com.yahoo.messagebus.Reply)

Aggregations

Reply (com.yahoo.messagebus.Reply)3 RoutingNodeIterator (com.yahoo.messagebus.routing.RoutingNodeIterator)3 EmptyReply (com.yahoo.messagebus.EmptyReply)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1