FileDocCategorySizeDatePackage
ASSelectorProvider.javaAPI DocGlassfish v2 API5136Fri May 04 22:35:52 BST 2007com.sun.enterprise.server.ss.provider

ASSelectorProvider

public class ASSelectorProvider extends SelectorProvider
Application Server's implementation of SelectorProvider, which wraps the JDK's default SelectorProvider obtained by sun.nio.ch.DefaultSelectorProvider.create(). This wrapping is necessary to provide special implementations of ServerSocketChannel and Selector.

Fields Summary
public static final int
PORT_UNBOUND
public static final int
PORT_BOUND
public static final int
PORT_CONFLICT
private SelectorProvider
provider
private HashMap
statemap
private HashMap
socketmap
Constructors Summary
public ASSelectorProvider()


      
        provider = getProvider();
    
Methods Summary
public voidclear(int port)

        statemap.remove(port);
        socketmap.remove(port);
    
intgetPortState(int port)

        Integer i = statemap.get(port);
        if (i == null) {
            return PORT_UNBOUND;
        } else {
            return i.intValue();
        }
    
private java.nio.channels.spi.SelectorProvidergetProvider()

 
        SelectorProvider sp = null;
        try {
            Class clazz = Class.forName( "sun.nio.ch.DefaultSelectorProvider" );
            java.lang.reflect.Method createMeth = clazz.getMethod("create", new Class[] {});
            sp = (SelectorProvider) createMeth.invoke( null, new Object[] {} ); 
        } catch( Exception e ) {
	    throw new RuntimeException("Unable to create default SelectorProvider.", e);
	}

	return sp;
    
java.net.ServerSocketgetServerSocket(int port)

        return socketmap.get(port);
    
public java.nio.channels.DatagramChannelopenDatagramChannel()

        return provider.openDatagramChannel();
    
public java.nio.channels.PipeopenPipe()

        return provider.openPipe();
    
public java.nio.channels.spi.AbstractSelectoropenSelector()

        AbstractSelector sel =  provider.openSelector();
        return new ASSelector(sel, this);
    
public java.nio.channels.ServerSocketChannelopenServerSocketChannel()

        ServerSocketChannel ssc = provider.openServerSocketChannel();
        return new ASServerSocketChannel(ssc, this);
    
public java.nio.channels.SocketChannelopenSocketChannel()

        //SocketChannel sc = provider.openSocketChannel();
        //return new ASSocketChannel(sc, this);
        return provider.openSocketChannel();
    
public voidsetPortState(int port, int state)

        statemap.put(port, state);
    
voidsetServerSocket(java.net.ServerSocket ss, int port)

        int state = getPortState(port);

	/**
        if  (state < 3)  {
            state++;
            statemap.put(s, new Integer(state));
        }
	**/

        if (state == PORT_UNBOUND) {
            socketmap.put(port, ss);
            setPortState(port, PORT_BOUND);
        }
	else if (state == PORT_BOUND) {
            setPortState(port, PORT_CONFLICT);
	}