FileDocCategorySizeDatePackage
SelectorReadThread.javaAPI DocGlassfish v2 API5122Fri May 04 22:37:06 BST 2007com.sun.enterprise.web.connector.grizzly

SelectorReadThread

public class SelectorReadThread extends SelectorThread implements MultiSelectorThread
Specialized SelectorThread that only handle OP_READ.
author
Scott Oaks
author
Jean-Francois Arcand

Fields Summary
ArrayList
channels
List of Channel to process.
public static int
countName
Int used to differenciate thsi instance
Constructors Summary
Methods Summary
public synchronized voidaddChannel(java.nio.channels.SocketChannel channel)
Add a Channel to be processed by this Selector


    
                  
         
               
        channels.add(channel);
        getSelector().wakeup();
    
public intgetCurrentBusyProcessorThreads()
Provides the count of request threads that are currently being processed by the container

return
Count of requests

        return (getProcessorPipeline().getCurrentThreadsBusy());
    
public ReadTaskgetReadTask(java.nio.channels.SelectionKey key)
Return a ReadTask configured to use this instance.

        ReadTask task = super.getReadTask(key);
        task.setSelectorThread(this);
        return task;
    
public voidinitEndpoint()
Initialize this SelectorThread

 
        setName("SelectorReaderThread-" + getPort());
        initAlgorithm();
    
private synchronized voidregisterNewChannels()
Register all Channel with an OP_READ opeation.

        int size = channels.size();
        for (int i = 0; i < size; i++) {
            SocketChannel sc = channels.get(i);
            sc.configureBlocking(false);
            try {
                SelectionKey readKey = 
                        sc.register(getSelector(), SelectionKey.OP_READ);
                setSocketOptions(((SocketChannel)readKey.channel()).socket());
            } catch (ClosedChannelException cce) {
            }
        }
        channels.clear();
    
public voidstartEndpoint()
Start and wait for incoming connection

        setRunning(true);
        while (isRunning()) {
            try{
                if ( getSelector() == null ){
                    setSelector(Selector.open());
                }              
                
                registerNewChannels();
                doSelect();
            } catch (Throwable t){
                logger.log(Level.FINE,"selectorThread.errorOnRequest",t);
            }
        }