Methods Summary |
---|
public synchronized org.apache.catalina.tribes.membership.Membership$MbrEntry | addMember(MemberImpl member)Add a member to this component and sort array with memberComparator
synchronized (members) {
MbrEntry entry = new MbrEntry(member);
if (!map.containsKey(member) ) {
map.put(member, entry);
MemberImpl results[] = new MemberImpl[members.length + 1];
for (int i = 0; i < members.length; i++) results[i] = members[i];
results[members.length] = member;
members = results;
Arrays.sort(members, memberComparator);
}
return entry;
}
|
public java.lang.Object | clone()
synchronized (members) {
Membership clone = new Membership(local, memberComparator);
clone.map = (HashMap) map.clone();
clone.members = new MemberImpl[members.length];
System.arraycopy(members,0,clone.members,0,members.length);
return clone;
}
|
public boolean | contains(org.apache.catalina.tribes.Member mbr)
return getMember(mbr)!=null;
|
public synchronized MemberImpl[] | expire(long maxtime)Runs a refresh cycle and returns a list of members that has expired.
This also removes the members from the membership, in such a way that
getMembers() = getMembers() - expire()
if(!hasMembers() )
return EMPTY_MEMBERS;
ArrayList list = null;
Iterator i = map.values().iterator();
while(i.hasNext()) {
MbrEntry entry = (MbrEntry)i.next();
if( entry.hasExpired(maxtime) ) {
if(list == null) // only need a list when members are expired (smaller gc)
list = new java.util.ArrayList();
list.add(entry.getMember());
}
}
if(list != null) {
MemberImpl[] result = new MemberImpl[list.size()];
list.toArray(result);
for( int j=0; j<result.length; j++) {
removeMember(result[j]);
}
return result;
} else {
return EMPTY_MEMBERS ;
}
|
public MemberImpl | getMember(org.apache.catalina.tribes.Member mbr)
if(hasMembers()) {
MemberImpl result = null;
for ( int i=0; i<this.members.length && result==null; i++ ) {
if ( members[i].equals(mbr) ) result = members[i];
}//for
return result;
} else {
return null;
}
|
protected synchronized org.apache.catalina.tribes.membership.Membership$MbrEntry[] | getMemberEntries()get a copy from all member entries
MbrEntry[] result = new MbrEntry[map.size()];
java.util.Iterator i = map.entrySet().iterator();
int pos = 0;
while ( i.hasNext() )
result[pos++] = ((MbrEntry)((java.util.Map.Entry)i.next()).getValue());
return result;
|
public MemberImpl[] | getMembers()Returning a list of all the members in the membership
We not need a copy: add and remove generate new arrays.
if(hasMembers()) {
return members;
} else {
return EMPTY_MEMBERS;
}
|
public boolean | hasMembers()Returning that service has members or not
return members.length > 0 ;
|
public synchronized boolean | memberAlive(MemberImpl member)Notify the membership that this member has announced itself.
boolean result = false;
//ignore ourselves
if ( member.equals(local) ) return result;
//return true if the membership has changed
MbrEntry entry = (MbrEntry)map.get(member);
if ( entry == null ) {
entry = addMember(member);
result = true;
} else {
//update the member alive time
MemberImpl 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());
Arrays.sort(members, memberComparator);
}
}
entry.accessed();
return result;
|
public void | removeMember(MemberImpl member)Remove a member from this component.
map.remove(member);
synchronized (members) {
int n = -1;
for (int i = 0; i < members.length; i++) {
if (members[i] == member || members[i].equals(member)) {
n = i;
break;
}
}
if (n < 0) return;
MemberImpl results[] = new MemberImpl[members.length - 1];
int j = 0;
for (int i = 0; i < members.length; i++) {
if (i != n)
results[j++] = members[i];
}
members = results;
}
|
public synchronized void | reset()Reset the membership and start over fresh.
Ie, delete all the members and wait for them to ping again and join this membership
map.clear();
members = EMPTY_MEMBERS ;
|