FileDocCategorySizeDatePackage
ASSelector.javaAPI DocGlassfish v2 API6540Tue Jun 05 10:53:36 BST 2007com.sun.enterprise.server.ss.provider

ASSelector

public class ASSelector extends AbstractSelector implements com.sun.enterprise.server.ss.util.ASWrapperCreator
Selector implementation of the quick appserver startup implementation. JDK's NIO implementation only recognises its own channel implementation. It doesnt accept any other implementation for select registrations. This implementation make sure that JDK's NIO implementation gets only the JDK's channels.

Fields Summary
private static final Logger
logger
private AbstractSelector
sel
private boolean
wakenup
private boolean
wrapSelectionKeys
private int
port
Constructors Summary
ASSelector(AbstractSelector sel, SelectorProvider provider)


        
        super(provider);
        this.sel = sel;
    
Methods Summary
public booleanequals(java.lang.Object obj)

        if (obj == this.sel) return true;

        if (obj instanceof Selector) {
            return ((Selector) obj).equals(this.sel);
        }
        return false;
    
public java.nio.channels.SelectorgetSelector()

        return sel;
    
public inthashCode()

        return this.sel.hashCode();
    
protected voidimplCloseSelector()

        if ( logger.isLoggable(Level.FINER) ) {
            logger.log(Level.FINER, "Selector is getting closed :" + sel);
        }
        sel.close();
    
public java.util.Setkeys()

        if (wrapSelectionKeys && 
            ASSocketFacadeUtils.getASSocketService().isServerStartingUp(port)) {
            return new ASSet(sel.keys(), this);
        } else {
            return sel.keys();
        }
    
protected java.nio.channels.SelectionKeyregister(java.nio.channels.spi.AbstractSelectableChannel ac, int ops, java.lang.Object obj)

 
        try {
            if (ac instanceof ASChannel) {
                ASChannel asc = (ASChannel) ac;
                SelectableChannel sc = asc.getActualChannel();

                if (ac instanceof ASServerSocketChannel && 
                    ops == SelectionKey.OP_ACCEPT) {
                    this.port = ((ASServerSocketChannel)ac).getPortNumber();
                    wrapSelectionKeys = true;
                }
                return sc.register(sel, ops, obj);
            } else {
                if ( logger.isLoggable(Level.FINEST) ) {
	            logger.log(java.util.logging.Level.FINEST, 
                    "In ASSelector.register channel class = " 
                    + ac.getClass().getName(), new Exception());
                }
                return ac.register(sel, ops, obj);
            }
        } catch (ClosedChannelException ce) {
            throw new RuntimeException (ce);
        }
    
public intselect(long l)

        return sel.select(l);
    
public intselect()

        return sel.select();
    
public intselectNow()

        return sel.selectNow();
    
public java.util.SetselectedKeys()

        if (wrapSelectionKeys && 
            ASSocketFacadeUtils.getASSocketService().isServerStartingUp(port)) {
            return new ASSet(sel.selectedKeys(), this);
        } else {
            return sel.selectedKeys();
        }
 
    
booleanwakenUp()

        boolean result = wakenup;
        wakenup = false;
        return result;
    
public java.nio.channels.Selectorwakeup()

        wakenup = true;
        return sel.wakeup();
    
public java.lang.ObjectwrapIfNecessary(java.lang.Object next)

       SelectionKey selKey = (SelectionKey) next;
        if ((selKey.interestOps() & SelectionKey.OP_ACCEPT) != 0) {
            ASServerSocketChannel channel = new ASServerSocketChannel(
            (ServerSocketChannel) selKey.channel(), this.sel.provider());
            SelectionKey key = new ASSelectionKey(channel, selKey, this);
            key.attach(selKey.attachment());
            return key;
        } else {
            return selKey;
        }