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

ASServerSocketImpl

public final class ASServerSocketImpl extends SocketImpl
NIO based SocketImpl implementation used by java.net.ServerSocket.

Fields Summary
private static final Logger
logger
private InetAddress
hostToBind
private int
portToBind
private ServerSocketChannel
ssc
private ServerSocket
ss
private Selector
selector
private Hashtable
options
Constructors Summary
Methods Summary
public voidaccept(java.net.SocketImpl si)

        try {
	    Socket sock = ss.accept();
	    ((ASClientSocketImpl)si).setClientSocket(sock);
        } catch (AsynchronousCloseException ase) {
            SocketException se = new SocketException(ase.getMessage());
            se.initCause(ase);
            throw se;
        }
    
public intavailable()

    
         
	throw new UnsupportedOperationException(
		    "available() not supported in ASServerSocketImpl");
    
public voidbind(java.net.InetAddress host, int port)

	hostToBind = host;
	portToBind = port;

	// actual binding happens in listen() below, because listen() is
	// called after bind() by java.net.ServerSocket.java.
    
public voidclose()

        if (ss != null && !ss.isClosed()) {
            try { 
                ServerSocketChannel channelToClose = ssc;
                ServerSocket socketToClose = ss;
                if (ssc instanceof ASServerSocketChannel) {
                    ASServerSocketChannel assc = 
                    (ASServerSocketChannel) ssc;
                    channelToClose = (ServerSocketChannel) assc.getActualChannel();
                    socketToClose = ssc.socket();
                }
                ASSocketFacadeUtils.getASSocketService().close(portToBind, 
                                            socketToClose, channelToClose);
            } catch (IOException e) {
                if ( logger.isLoggable(Level.FINE) ) {
                    logger.log(Level.FINE, ""+ e.getMessage(),e);
                }
            }
        }
    
public voidconnect(java.lang.String s, int i)

	throw new UnsupportedOperationException(
		    "connect() not supported in ASServerSocketImpl");
    
public voidconnect(java.net.InetAddress ia, int i)

	throw new UnsupportedOperationException(
		    "connect() not supported in ASServerSocketImpl");
    
public voidconnect(java.net.SocketAddress sa, int i)

	throw new UnsupportedOperationException(
		    "connect() not supported in ASServerSocketImpl");
    
public voidcreate(boolean stream)

	// No-op: stream is always true when called from ServerSocket
    
public java.io.InputStreamgetInputStream()

	throw new UnsupportedOperationException(
		    "getInputStream() not supported in ASServerSocketImpl");
    
public java.lang.ObjectgetOption(int opt)

       switch (opt) {
        case SO_TIMEOUT:
            try {
                return new Integer(ss.getSoTimeout());
            } catch( IOException ioe ) {
                throw new SocketException(ioe.getMessage()) ;
            }
        case SO_RCVBUF:
            return new Integer(ss.getReceiveBufferSize());
        case SO_REUSEADDR:
            return new Boolean(ss.getReuseAddress());
        default:
            throw new SocketException("unrecognized TCP option: " + opt);
        }

    
public java.io.OutputStreamgetOutputStream()

	throw new UnsupportedOperationException(
		    "getOutputStream() not supported in ASServerSocketImpl");
    
public voidlisten(int backlog)


	// Check for services that are not lazily initialized
        if (!ASSocketFacadeUtils.getASSocketService().exists(portToBind)) { 
	    ssc = ServerSocketChannel.open();
	    ss = ssc.socket();
        } else {
            ssc = ASSocketFacadeUtils.getASSocketService().
                                             getServerSocketChannel(portToBind);
            ss = ASSocketFacadeUtils.getASSocketService().
                                             getServerSocket(portToBind);
	}

        InetSocketAddress isa = new InetSocketAddress(hostToBind, portToBind);
	ss.bind(isa, backlog);

        localport = ss.getLocalPort();
        address = ss.getInetAddress();
    
public voidsendUrgentData(int i)

	throw new UnsupportedOperationException(
		    "sendUrgentData() not supported in ASServerSocketImpl");
    
public voidsetOption(int opt, java.lang.Object val)

        if ( logger.isLoggable(Level.FINE) ) {
             logger.log(java.util.logging.Level.FINE, "In ASServerSocketImpl.setOption, opt = "
                        +opt+" val = "+val, new Exception());
        }

	//Consider only those options that are settable in a ServerSocket
     	switch (opt) {

	case SO_TIMEOUT:
	    if (val == null || (!(val instanceof Integer)))
		throw new SocketException("Bad parameter for SO_TIMEOUT");
	    int tmp = ((Integer) val).intValue();
	    if (tmp < 0)
		throw new IllegalArgumentException("timeout < 0");
	    ss.setSoTimeout( tmp );
	    break;
	
	case SO_RCVBUF:
	    if (val == null || !(val instanceof Integer) ||
		!(((Integer)val).intValue() > 0)) {
		throw new SocketException("bad parameter for SO_SNDBUF " +
					  "or SO_RCVBUF");
	    }
	    ss.setReceiveBufferSize( ((Integer) val).intValue() );
	    break;
	
	case SO_REUSEADDR:
	    if (val == null || !(val instanceof Boolean)) 
	        throw new SocketException("bad parameter for SO_REUSEADDR");
            if (ss != null) 
	        ss.setReuseAddress( ((Boolean)val).booleanValue() );
	    break;
	default:
	    throw new SocketException("unrecognized TCP option: " + opt);
	}
    
public voidshutdownInput()

	throw new UnsupportedOperationException(
		    "shutdownInput() not supported in ASServerSocketImpl");
    
public voidshutdownOutput()

	throw new UnsupportedOperationException(
		    "shutdownOutput() not supported in ASServerSocketImpl");
    
public booleansupportsUrgentData()

	throw new UnsupportedOperationException(
		    "supportsUrgentData() not supported in ASServerSocketImpl");