FileDocCategorySizeDatePackage
BioReceiver.javaAPI DocApache Tomcat 6.0.145641Fri Jul 20 04:20:34 BST 2007org.apache.catalina.tribes.transport.bio

BioReceiver

public class BioReceiver extends org.apache.catalina.tribes.transport.ReceiverBase implements org.apache.catalina.tribes.ChannelReceiver, Runnable, org.apache.catalina.tribes.io.ListenCallback

Title:

Description:

Company:

author
not attributable
version
1.0

Fields Summary
protected static org.apache.juli.logging.Log
log
protected ServerSocket
serverSocket
Constructors Summary
public BioReceiver()


      
    
Methods Summary
protected voidbind()

        // allocate an unbound server socket channel
        serverSocket = new ServerSocket();
        // set the port the server channel will listen to
        //serverSocket.bind(new InetSocketAddress(getBind(), getTcpListenPort()));
        bind(serverSocket,getPort(),getAutoBind());
    
public org.apache.catalina.tribes.transport.AbstractRxTaskcreateRxTask()

        return getReplicationThread();
    
protected BioReplicationTaskgetReplicationThread()

        BioReplicationTask result = new BioReplicationTask(this);
        result.setOptions(getWorkerThreadOptions());
        result.setUseBufferPool(this.getUseBufferPool());
        return result;
    
public voidlisten()

        if (doListen()) {
            log.warn("ServerSocket already started");
            return;
        }
        setListen(true);

        while ( doListen() ) {
            Socket socket = null;
            if ( getTaskPool().available() < 1 ) {
                if ( log.isWarnEnabled() )
                    log.warn("All BIO server replication threads are busy, unable to handle more requests until a thread is freed up.");
            }
            BioReplicationTask task = (BioReplicationTask)getTaskPool().getRxTask();
            if ( task == null ) continue; //should never happen
            try {
                socket = serverSocket.accept();
            }catch ( Exception x ) {
                if ( doListen() ) throw x;
            }
            if ( !doListen() ) {
                task.setDoRun(false);
                task.serviceSocket(null,null);
                getExecutor().execute(task);
                break; //regular shutdown
            }
            if ( socket == null ) continue;
            socket.setReceiveBufferSize(getRxBufSize());
            socket.setSendBufferSize(getRxBufSize());
            socket.setTcpNoDelay(getTcpNoDelay());
            socket.setKeepAlive(getSoKeepAlive());
            socket.setOOBInline(getOoBInline());
            socket.setReuseAddress(getSoReuseAddress());
            socket.setSoLinger(getSoLingerOn(),getSoLingerTime());
            socket.setTrafficClass(getSoTrafficClass());
            socket.setSoTimeout(getTimeout());
            ObjectReader reader = new ObjectReader(socket);
            task.serviceSocket(socket,reader);
        }//while
    
public voidrun()

        try {
            listen();
        } catch (Exception x) {
            log.error("Unable to run replication listener.", x);
        }
    
public voidstart()

throws
IOException
todo
Implement this org.apache.catalina.tribes.ChannelReceiver method

        super.start();
        try {
            setPool(new RxTaskPool(getMaxThreads(),getMinThreads(),this));
        } catch (Exception x) {
            log.fatal("ThreadPool can initilzed. Listener not started", x);
            if ( x instanceof IOException ) throw (IOException)x;
            else throw new IOException(x.getMessage());
        }
        try {
            getBind();
            bind();
            Thread t = new Thread(this, "BioReceiver");
            t.setDaemon(true);
            t.start();
        } catch (Exception x) {
            log.fatal("Unable to start cluster receiver", x);
            if ( x instanceof IOException ) throw (IOException)x;
            else throw new IOException(x.getMessage());
        }
    
public voidstop()

todo
Implement this org.apache.catalina.tribes.ChannelReceiver method

        setListen(false);
        try {
            this.serverSocket.close();
        }catch ( Exception x ) {}
        super.stop();