FileDocCategorySizeDatePackage
NioChannel.javaAPI DocApache Tomcat 6.0.146086Fri Jul 20 04:20:34 BST 2007org.apache.tomcat.util.net

NioChannel

public class NioChannel extends Object implements ByteChannel
Base class for a SocketChannel wrapper used by the endpoint. This way, logic for a SSL socket channel remains the same as for a non SSL, making sure we don't need to code for any exception cases.
author
Filip Hanik
version
1.0

Fields Summary
protected static ByteBuffer
emptyBuf
protected SocketChannel
sc
protected org.apache.tomcat.util.net.SecureNioChannel.ApplicationBufferHandler
bufHandler
protected org.apache.tomcat.util.net.NioEndpoint.Poller
poller
Constructors Summary
public NioChannel(SocketChannel channel, org.apache.tomcat.util.net.SecureNioChannel.ApplicationBufferHandler bufHandler)


           
        this.sc = channel;
        this.bufHandler = bufHandler;
    
Methods Summary
public voidclose()
Closes this channel.

throws
IOException If an I/O error occurs
todo
Implement this java.nio.channels.Channel method

        getIOChannel().socket().close();
        getIOChannel().close();
    
public voidclose(boolean force)

        if (isOpen() || force ) close();
    
public booleanflush(boolean block, java.nio.channels.Selector s, long timeout)
returns true if the network buffer has been flushed out and is empty

return
boolean

        return true; //no network buffer in the regular channel
    
public java.lang.ObjectgetAttachment(boolean remove)

        Poller pol = getPoller();
        Selector sel = pol!=null?pol.getSelector():null;
        SelectionKey key = sel!=null?getIOChannel().keyFor(sel):null;
        Object att = key!=null?key.attachment():null;
        if (key != null && att != null && remove ) key.attach(null);
        return att;
    
public org.apache.tomcat.util.net.SecureNioChannel.ApplicationBufferHandlergetBufHandler()
getBufHandler

return
ApplicationBufferHandler
todo
Implement this org.apache.tomcat.util.net.SecureNioChannel method

        return bufHandler;
    
public intgetBufferSize()

        if ( bufHandler == null ) return 0;
        int size = 0;
        size += bufHandler.getReadBuffer()!=null?bufHandler.getReadBuffer().capacity():0;
        size += bufHandler.getWriteBuffer()!=null?bufHandler.getWriteBuffer().capacity():0;
        return size;
    
public java.nio.channels.SocketChannelgetIOChannel()
getIOChannel

return
SocketChannel
todo
Implement this org.apache.tomcat.util.net.SecureNioChannel method

        return sc;
    
public org.apache.tomcat.util.net.NioEndpoint.PollergetPoller()

        return poller;
    
public inthandshake(boolean read, boolean write)

        return 0;
    
public booleanisClosing()
isClosing

return
boolean
todo
Implement this org.apache.tomcat.util.net.SecureNioChannel method

        return false;
    
public booleanisInitHandshakeComplete()
isInitHandshakeComplete

return
boolean
todo
Implement this org.apache.tomcat.util.net.SecureNioChannel method

        return true;
    
public booleanisOpen()
Tells whether or not this channel is open.

return
true if, and only if, this channel is open
todo
Implement this java.nio.channels.Channel method

        return sc.isOpen();
    
public intread(java.nio.ByteBuffer dst)
Reads a sequence of bytes from this channel into the given buffer.

param
dst The buffer into which bytes are to be transferred
return
The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
throws
IOException If some other I/O error occurs
todo
Implement this java.nio.channels.ReadableByteChannel method

        return sc.read(dst);
    
public voidreset()

        bufHandler.getReadBuffer().clear();
        bufHandler.getWriteBuffer().clear();
    
public voidsetIOChannel(java.nio.channels.SocketChannel IOChannel)

        this.sc = IOChannel;
    
public voidsetPoller(org.apache.tomcat.util.net.NioEndpoint.Poller poller)

        this.poller = poller;
    
public java.lang.StringtoString()

        return super.toString()+":"+this.sc.toString();
    
public intwrite(java.nio.ByteBuffer src)
Writes a sequence of bytes to this channel from the given buffer.

param
src The buffer from which bytes are to be retrieved
return
The number of bytes written, possibly zero
throws
IOException If some other I/O error occurs
todo
Implement this java.nio.channels.WritableByteChannel method

        return sc.write(src);