FileDocCategorySizeDatePackage
MultipointBioSender.javaAPI DocApache Tomcat 6.0.145271Fri Jul 20 04:20:36 BST 2007org.apache.catalina.tribes.transport.bio

MultipointBioSender

public class MultipointBioSender extends org.apache.catalina.tribes.transport.AbstractSender implements org.apache.catalina.tribes.transport.MultiPointSender
author
Filip Hanik
version
$Revision: 532800 $ $Date: 2007-04-26 18:52:29 +0200 (jeu., 26 avr. 2007) $

Fields Summary
protected long
selectTimeout
protected HashMap
bioSenders
Constructors Summary
public MultipointBioSender()

    
Methods Summary
public voidadd(org.apache.catalina.tribes.Member member)


    
private synchronized voidclose()

        ChannelException x = null;
        Object[] members = bioSenders.keySet().toArray();
        for (int i=0; i<members.length; i++ ) {
            Member mbr = (Member)members[i];
            try {
                BioSender sender = (BioSender)bioSenders.get(mbr);
                sender.disconnect();
            }catch ( Exception e ) {
                if ( x == null ) x = new ChannelException(e);
                x.addFaultyMember(mbr,e);
            }
            bioSenders.remove(mbr);
        }
        if ( x != null ) throw x;
    
public voidconnect()

        //do nothing, we connect on demand
        setConnected(true);
    
public synchronized voiddisconnect()

        try {close(); }catch (Exception x){}
        setConnected(false);
    
public voidfinalize()

        try {disconnect(); }catch ( Exception ignore){}
    
public booleankeepalive()

        //throw new UnsupportedOperationException("Method ParallelBioSender.checkKeepAlive() not implemented");
        boolean result = false;
        Map.Entry[] entries = (Map.Entry[])bioSenders.entrySet().toArray(new Map.Entry[bioSenders.size()]);
        for ( int i=0; i<entries.length; i++ ) {
            BioSender sender = (BioSender)entries[i].getValue();
            if ( sender.keepalive() ) {
                bioSenders.remove(entries[i].getKey());
            }
        }
        return result;
    
public voidremove(org.apache.catalina.tribes.Member member)

        //disconnect senders
        BioSender sender = (BioSender)bioSenders.remove(member);
        if ( sender != null ) sender.disconnect();
    
public synchronized voidsendMessage(org.apache.catalina.tribes.Member[] destination, org.apache.catalina.tribes.ChannelMessage msg)


             
        byte[] data = XByteBuffer.createDataPackage((ChannelData)msg);
        BioSender[] senders = setupForSend(destination);
        ChannelException cx = null;
        for ( int i=0; i<senders.length; i++ ) {
            try {
                senders[i].sendMessage(data,(msg.getOptions()&Channel.SEND_OPTIONS_USE_ACK)==Channel.SEND_OPTIONS_USE_ACK);
            } catch (Exception x) {
                if (cx == null) cx = new ChannelException(x);
                cx.addFaultyMember(destination[i],x);
            }
        }
        if (cx!=null ) throw cx;
    
protected BioSender[]setupForSend(org.apache.catalina.tribes.Member[] destination)

        ChannelException cx = null;
        BioSender[] result = new BioSender[destination.length];
        for ( int i=0; i<destination.length; i++ ) {
            try {
                BioSender sender = (BioSender) bioSenders.get(destination[i]);
                if (sender == null) {
                    sender = new BioSender();
                    sender.transferProperties(this,sender);
                    sender.setDestination(destination[i]);
                    bioSenders.put(destination[i], sender);
                }
                result[i] = sender;
                if (!result[i].isConnected() ) result[i].connect();
                result[i].keepalive();
            }catch (Exception x ) {
                if ( cx== null ) cx = new ChannelException(x);
                cx.addFaultyMember(destination[i],x);
            }
        }
        if ( cx!=null ) throw cx;
        else return result;