Search in sources :

Example 6 with Membership

use of org.apache.catalina.tribes.membership.Membership in project tomcat by apache.

the class NonBlockingCoordinator method createElectionMsg.

private CoordinationMessage createElectionMsg(Member local, Member[] others, Member leader) {
    Membership m = new Membership(local, AbsoluteOrder.comp, true);
    Arrays.fill(m, others);
    Member[] mbrs = m.getMembers();
    m.reset();
    CoordinationMessage msg = new CoordinationMessage(leader, local, mbrs, new UniqueId(UUIDGenerator.randomUUID(true)), COORD_REQUEST);
    return msg;
}
Also used : UniqueId(org.apache.catalina.tribes.UniqueId) Membership(org.apache.catalina.tribes.membership.Membership) Member(org.apache.catalina.tribes.Member)

Example 7 with Membership

use of org.apache.catalina.tribes.membership.Membership in project tomcat by apache.

the class NonBlockingCoordinator method mergeOnArrive.

protected Membership mergeOnArrive(CoordinationMessage msg) {
    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_PRE_MERGE, this, "Pre merge"));
    Member local = getLocalMember(false);
    Membership merged = new Membership(local, AbsoluteOrder.comp, true);
    Arrays.fill(merged, msg.getMembers());
    Arrays.fill(merged, getMembers());
    Member[] diff = Arrays.diff(merged, membership, local);
    for (Member member : diff) {
        if (!alive(member)) {
            merged.removeMember(member);
        } else {
            memberAdded(member, false);
        }
    }
    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_POST_MERGE, this, "Post merge"));
    return merged;
}
Also used : Membership(org.apache.catalina.tribes.membership.Membership) Member(org.apache.catalina.tribes.Member)

Example 8 with Membership

use of org.apache.catalina.tribes.membership.Membership in project tomcat by apache.

the class NonBlockingCoordinator method handleMyToken.

protected void handleMyToken(Member local, CoordinationMessage msg, Membership merged) throws ChannelException {
    if (local.equals(msg.getLeader())) {
        // no leadership change
        if (Arrays.sameMembers(msg.getMembers(), merged.getMembers())) {
            msg.type = COORD_CONF;
            super.sendMessage(Arrays.remove(msg.getMembers(), local), createData(msg, local), null);
            handleViewConf(msg, merged);
        } else {
            // membership change
            suggestedView = new Membership(local, AbsoluteOrder.comp, true);
            suggestedviewId = msg.getId();
            Arrays.fill(suggestedView, merged.getMembers());
            msg.view = merged.getMembers();
            sendElectionMsgToNextInline(local, msg);
        }
    } else {
        // leadership change
        suggestedView = null;
        suggestedviewId = null;
        msg.view = merged.getMembers();
        sendElectionMsgToNextInline(local, msg);
    }
}
Also used : Membership(org.apache.catalina.tribes.membership.Membership)

Example 9 with Membership

use of org.apache.catalina.tribes.membership.Membership in project tomcat by apache.

the class NonBlockingCoordinator method handleViewConf.

protected void handleViewConf(CoordinationMessage msg, Membership merged) throws ChannelException {
    if (viewId != null && msg.getId().equals(viewId)) {
        // we already have this view
        return;
    }
    view = new Membership(getLocalMember(false), AbsoluteOrder.comp, true);
    Arrays.fill(view, msg.getMembers());
    viewId = msg.getId();
    if (viewId.equals(suggestedviewId)) {
        suggestedView = null;
        suggestedviewId = null;
    }
    if (suggestedView != null && AbsoluteOrder.comp.compare(suggestedView.getMembers()[0], merged.getMembers()[0]) < 0) {
        suggestedView = null;
        suggestedviewId = null;
    }
    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_CONF_RX, this, "Accepted View"));
    if (suggestedviewId == null && hasHigherPriority(merged.getMembers(), membership.getMembers())) {
        startElection(false);
    }
}
Also used : Membership(org.apache.catalina.tribes.membership.Membership)

Example 10 with Membership

use of org.apache.catalina.tribes.membership.Membership in project tomcat70 by apache.

the class NonBlockingCoordinator method mergeOnArrive.

protected Membership mergeOnArrive(CoordinationMessage msg, Member sender) {
    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_PRE_MERGE, this, "Pre merge"));
    MemberImpl local = (MemberImpl) getLocalMember(false);
    Membership merged = new Membership(local, AbsoluteOrder.comp, true);
    Arrays.fill(merged, msg.getMembers());
    Arrays.fill(merged, getMembers());
    Member[] diff = Arrays.diff(merged, membership, local);
    for (int i = 0; i < diff.length; i++) {
        if (!alive(diff[i]))
            merged.removeMember((MemberImpl) diff[i]);
        else
            memberAdded(diff[i], false);
    }
    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_POST_MERGE, this, "Post merge"));
    return merged;
}
Also used : MemberImpl(org.apache.catalina.tribes.membership.MemberImpl) Membership(org.apache.catalina.tribes.membership.Membership) Member(org.apache.catalina.tribes.Member)

Aggregations

Membership (org.apache.catalina.tribes.membership.Membership)12 Member (org.apache.catalina.tribes.Member)4 UniqueId (org.apache.catalina.tribes.UniqueId)4 MemberImpl (org.apache.catalina.tribes.membership.MemberImpl)4