Java Code Examples for org.apache.catalina.tribes.Member#equals()

The following examples show how to use org.apache.catalina.tribes.Member#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplicatedMap.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void mapMemberAdded(Member member) {
    if ( member.equals(getChannel().getLocalMember(false)) ) return;
    boolean memberAdded = false;
    synchronized (mapMembers) {
        if (!mapMembers.containsKey(member) ) {
            mapMembers.put(member, Long.valueOf(System.currentTimeMillis()));
            memberAdded = true;
        }
    }
    if ( memberAdded ) {
        synchronized (stateMutex) {
            Member[] backup = getMapMembers();
            Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator();
            while (i.hasNext()) {
                Map.Entry<K,MapEntry<K,V>> e = i.next();
                MapEntry<K,V> entry = innerMap.get(e.getKey());
                if ( entry == null ) continue;
                if (entry.isPrimary() && !inSet(member,entry.getBackupNodes())) {
                    entry.setBackupNodes(backup);
                }
            }
        }
    }
}
 
Example 2
Source File: ReplicatedMap.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void mapMemberAdded(Member member) {
    if ( member.equals(getChannel().getLocalMember(false)) ) return;
    boolean memberAdded = false;
    synchronized (mapMembers) {
        if (!mapMembers.containsKey(member) ) {
            mapMembers.put(member, Long.valueOf(System.currentTimeMillis()));
            memberAdded = true;
        }
    }
    if ( memberAdded ) {
        synchronized (stateMutex) {
            Member[] backup = getMapMembers();
            for (Entry<K, MapEntry<K, V>> e : innerMap.entrySet()) {
                MapEntry<K,V> entry = innerMap.get(e.getKey());
                if ( entry == null ) continue;
                if (entry.isPrimary() && !inSet(member,entry.getBackupNodes())) {
                    entry.setBackupNodes(backup);
                }
            }
        }
    }
}
 
Example 3
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
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);
    }
}
 
Example 4
Source File: ReplicatedMap.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void mapMemberAdded(Member member) {
    if ( member.equals(getChannel().getLocalMember(false)) ) return;
    boolean memberAdded = false;
    synchronized (mapMembers) {
        if (!mapMembers.containsKey(member) ) {
            mapMembers.put(member, Long.valueOf(System.currentTimeMillis()));
            memberAdded = true;
        }
    }
    if ( memberAdded ) {
        synchronized (stateMutex) {
            Member[] backup = getMapMembers();
            Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator();
            while (i.hasNext()) {
                Map.Entry<K,MapEntry<K,V>> e = i.next();
                MapEntry<K,V> entry = innerMap.get(e.getKey());
                if ( entry == null ) continue;
                if (entry.isPrimary() && !inSet(member,entry.getBackupNodes())) {
                    entry.setBackupNodes(backup);
                }
            }
        }
    }
}
 
Example 5
Source File: AbstractReplicatedMap.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public boolean inSet(Member m, Member[] set) {
    if ( set == null ) return false;
    boolean result = false;
    for (int i=0; i<set.length && (!result); i++ )
        if ( m.equals(set[i]) ) result = true;
    return result;
}
 
Example 6
Source File: AbstractReplicatedMap.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public boolean inSet(Member m, Member[] set) {
    if ( set == null ) return false;
    boolean result = false;
    for (int i=0; i<set.length && (!result); i++ )
        if ( m.equals(set[i]) ) result = true;
    return result;
}
 
Example 7
Source File: AbstractReplicatedMap.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void mapMemberAdded(Member member) {
    if ( member.equals(getChannel().getLocalMember(false)) ) return;
    boolean memberAdded = false;
    //select a backup node if we don't have one
    Member mapMember = getChannel().getMember(member);
    if (mapMember == null) {
        log.warn("Notified member is not registered in the membership:" + member);
        return;
    }
    synchronized (mapMembers) {
        if (!mapMembers.containsKey(mapMember) ) {
            if (log.isInfoEnabled()) log.info("Map member added:" + mapMember);
            mapMembers.put(mapMember, Long.valueOf(System.currentTimeMillis()));
            memberAdded = true;
        }
    }
    if ( memberAdded ) {
        synchronized (stateMutex) {
            Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator();
            while (i.hasNext()) {
                Map.Entry<K,MapEntry<K,V>> e = i.next();
                MapEntry<K,V> entry = innerMap.get(e.getKey());
                if ( entry == null ) continue;
                if (entry.isPrimary() && (entry.getBackupNodes() == null || entry.getBackupNodes().length == 0)) {
                    try {
                        Member[] backup = publishEntryInfo(entry.getKey(), entry.getValue());
                        entry.setBackupNodes(backup);
                        entry.setPrimary(channel.getLocalMember(false));
                    } catch (ChannelException x) {
                        log.error("Unable to select backup node.", x);
                    } //catch
                } //end if
            } //while
        } //synchronized
    }//end if
}
 
Example 8
Source File: AbstractReplicatedMap.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public boolean inSet(Member m, Member[] set) {
    if ( set == null ) return false;
    boolean result = false;
    for (int i=0; i<set.length && (!result); i++ )
        if ( m.equals(set[i]) ) result = true;
    return result;
}
 
Example 9
Source File: AbstractReplicatedMap.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void mapMemberAdded(Member member) {
    if ( member.equals(getChannel().getLocalMember(false)) ) return;
    boolean memberAdded = false;
    //select a backup node if we don't have one
    Member mapMember = getChannel().getMember(member);
    if (mapMember == null) {
        log.warn("Notified member is not registered in the membership:" + member);
        return;
    }
    synchronized (mapMembers) {
        if (!mapMembers.containsKey(mapMember) ) {
            if (log.isInfoEnabled()) log.info("Map member added:" + mapMember);
            mapMembers.put(mapMember, Long.valueOf(System.currentTimeMillis()));
            memberAdded = true;
        }
    }
    if ( memberAdded ) {
        synchronized (stateMutex) {
            Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator();
            while (i.hasNext()) {
                Map.Entry<K,MapEntry<K,V>> e = i.next();
                MapEntry<K,V> entry = innerMap.get(e.getKey());
                if ( entry == null ) continue;
                if (entry.isPrimary() && (entry.getBackupNodes() == null || entry.getBackupNodes().length == 0)) {
                    try {
                        Member[] backup = publishEntryInfo(entry.getKey(), entry.getValue());
                        entry.setBackupNodes(backup);
                        entry.setPrimary(channel.getLocalMember(false));
                    } catch (ChannelException x) {
                        log.error("Unable to select backup node.", x);
                    } //catch
                } //end if
            } //while
        } //synchronized
    }//end if
}
 
Example 10
Source File: Membership.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Notify the membership that this member has announced itself.
 *
 * @param member - the member that just pinged us
 * @return - true if this member is new to the cluster, false otherwise.<br>
 * - false if this member is the local member or updated.
 */
public boolean memberAlive(Member member) {
    // Ignore ourselves
    if (member.equals(local)) {
        return false;
    }

    boolean result = false;
    synchronized (membersLock) {
        MbrEntry entry = map.get(member);
        if (entry == null) {
            entry = addMember(member);
            result = true;
        } else {
            // Update the member alive time
            Member updateMember = entry.getMember();
            if (updateMember.getMemberAliveTime() != member.getMemberAliveTime()) {
                // Update fields that can change
                updateMember.setMemberAliveTime(member.getMemberAliveTime());
                updateMember.setPayload(member.getPayload());
                updateMember.setCommand(member.getCommand());
                // Re-order. Can't sort in place since a call to
                // getMembers() may then receive an intermediate result.
                Member[] newMembers = members.clone();
                Arrays.sort(newMembers, memberComparator);
                members = newMembers;
            }
        }
        entry.accessed();
    }
    return result;
}
 
Example 11
Source File: Arrays.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public static Member[] diff(Membership complete, Membership local, Member ignore) {
    ArrayList<Member> result = new ArrayList<>();
    Member[] comp = complete.getMembers();
    for ( int i=0; i<comp.length; i++ ) {
        if ( ignore!=null && ignore.equals(comp[i]) ) continue;
        if ( local.getMember(comp[i]) == null ) result.add(comp[i]);
    }
    return result.toArray(new Member[result.size()]);
}
 
Example 12
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected void handleOtherToken(Member local, CoordinationMessage msg, Membership merged) throws ChannelException {
    if ( local.equals(msg.getLeader()) ) {
        //I am the new leader
        //startElection(false);
    } else {
        msg.view = merged.getMembers();
        sendElectionMsgToNextInline(local,msg);
    }
}
 
Example 13
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected void handleToken(CoordinationMessage msg, Membership merged) throws ChannelException {
    Member local = getLocalMember(false);
    if ( local.equals(msg.getSource()) ) {
        //my message msg.src=local
        handleMyToken(local, msg, merged);
    } else {
        handleOtherToken(local, msg, merged);
    }
}
 
Example 14
Source File: AbstractReplicatedMap.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public void mapMemberAdded(Member member) {
    if ( member.equals(getChannel().getLocalMember(false)) ) return;
    boolean memberAdded = false;
    //select a backup node if we don't have one
    Member mapMember = getChannel().getMember(member);
    if (mapMember == null) {
        log.warn(sm.getString("abstractReplicatedMap.mapMemberAdded.nullMember", member));
        return;
    }
    synchronized (mapMembers) {
        if (!mapMembers.containsKey(mapMember) ) {
            if (log.isInfoEnabled())
                log.info(sm.getString("abstractReplicatedMap.mapMemberAdded.added", mapMember));
            mapMembers.put(mapMember, Long.valueOf(System.currentTimeMillis()));
            memberAdded = true;
        }
    }
    if ( memberAdded ) {
        synchronized (stateMutex) {
            for (Entry<K, MapEntry<K, V>> e : innerMap.entrySet()) {
                MapEntry<K,V> entry = innerMap.get(e.getKey());
                if ( entry == null ) continue;
                if (entry.isPrimary() && (entry.getBackupNodes() == null || entry.getBackupNodes().length == 0)) {
                    try {
                        Member[] backup = publishEntryInfo(entry.getKey(), entry.getValue());
                        entry.setBackupNodes(backup);
                        entry.setPrimary(channel.getLocalMember(false));
                    } catch (ChannelException x) {
                        log.error(sm.getString("abstractReplicatedMap.unableSelect.backup"), x);
                    } //catch
                } //end if
            } //while
        } //synchronized
    }//end if
}
 
Example 15
Source File: Arrays.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public static int indexOf(Member member, Member[] members) {
    int result = -1;
    for (int i=0; (result==-1) && (i<members.length); i++ )
        if ( member.equals(members[i]) ) result = i;
    return result;
}
 
Example 16
Source File: Arrays.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public static int indexOf(Member member, Member[] members) {
    int result = -1;
    for (int i=0; (result==-1) && (i<members.length); i++ ) 
        if ( member.equals(members[i]) ) result = i;
    return result;
}
 
Example 17
Source File: Arrays.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public static int indexOf(Member member, Member[] members) {
    int result = -1;
    for (int i=0; (result==-1) && (i<members.length); i++ ) 
        if ( member.equals(members[i]) ) result = i;
    return result;
}