FileDocCategorySizeDatePackage
StaticMembershipInterceptor.javaAPI DocApache Tomcat 6.0.144062Fri Jul 20 04:20:36 BST 2007org.apache.catalina.tribes.group.interceptors

StaticMembershipInterceptor

public class StaticMembershipInterceptor extends org.apache.catalina.tribes.group.ChannelInterceptorBase

Fields Summary
protected ArrayList
members
protected org.apache.catalina.tribes.Member
localMember
Constructors Summary
public StaticMembershipInterceptor()


      
        super();
    
Methods Summary
public voidaddStaticMember(org.apache.catalina.tribes.Member member)

        synchronized (members) {
            if (!members.contains(member)) members.add(member);
        }
    
public org.apache.catalina.tribes.MembergetLocalMember(boolean incAlive)
Return the member that represents this node.

return
Member

        if (this.localMember != null ) return localMember;
        else return super.getLocalMember(incAlive);
    
public org.apache.catalina.tribes.MembergetMember(org.apache.catalina.tribes.Member mbr)

param
mbr Member
return
Member

        if ( members.contains(mbr) ) return (Member)members.get(members.indexOf(mbr));
        else return super.getMember(mbr);
    
public org.apache.catalina.tribes.Member[]getMembers()
Get all current cluster members

return
all members or empty array

        if ( members.size() == 0 ) return super.getMembers();
        else {
            synchronized (members) {
                Member[] others = super.getMembers();
                Member[] result = new Member[members.size() + others.length];
                for (int i = 0; i < others.length; i++) result[i] = others[i];
                for (int i = 0; i < members.size(); i++) result[i + others.length] = (Member) members.get(i);
                AbsoluteOrder.absoluteOrder(result);
                return result;
            }//sync
        }//end if
    
public booleanhasMembers()
has members

        return super.hasMembers() || (members.size()>0);
    
public voidremoveStaticMember(org.apache.catalina.tribes.Member member)

        synchronized (members) {
            if (members.contains(member)) members.remove(member);
        }
    
public voidsetLocalMember(org.apache.catalina.tribes.Member member)

        this.localMember = member;
    
public voidstart(int svc)
Send notifications upwards

param
svc int
throws
ChannelException

        if ( (Channel.SND_RX_SEQ&svc)==Channel.SND_RX_SEQ ) super.start(Channel.SND_RX_SEQ); 
        if ( (Channel.SND_TX_SEQ&svc)==Channel.SND_TX_SEQ ) super.start(Channel.SND_TX_SEQ); 
        final Member[] mbrs = (Member[])members.toArray(new Member[members.size()]);
        final ChannelInterceptorBase base = this;
        Thread t = new Thread() {
            public void run() {
                for (int i=0; i<mbrs.length; i++ ) {
                    base.memberAdded(mbrs[i]);
                }
            }
        };
        t.start();
        super.start(svc & (~Channel.SND_RX_SEQ) & (~Channel.SND_TX_SEQ));