LimeWire Consolidated API

org.limewire.nio.channel
Class AbstractChannelInterestReader

java.lang.Object
  extended by org.limewire.nio.channel.AbstractChannelInterestReader
All Implemented Interfaces:
Closeable, Channel, ReadableByteChannel, ScatteringByteChannel, ChannelReader, ChannelReadObserver, InterestReadableByteChannel, InterestScatteringByteChannel, IOErrorObserver, ReadObserver, Shutdownable
Direct Known Subclasses:
AsyncConnectionDispatcher

public abstract class AbstractChannelInterestReader
extends Object
implements ChannelReadObserver, InterestScatteringByteChannel

Handles allocating a ByteBuffer of a given size, allows chained readers to read from this, deals with propagating interest to a source channel, propagates close and isOpen, implements a stubbed-out handleIOException, and marks when the channel has been shutdown.

Subclasses only need to implement handleRead to move data from the source channel into the buffer and react to what was read.


Field Summary
protected  ByteBuffer buffer
          Implementors should write to buffer.
protected  boolean shutdown
           
protected  InterestReadableByteChannel source
           
 
Constructor Summary
AbstractChannelInterestReader(int bufferSize)
           
 
Method Summary
 void close()
           
 InterestReadableByteChannel getReadChannel()
          Gets the source channel.
 void handleIOException(IOException iox)
          Notification that an IOException occurred while dispatching.
 void interestRead(boolean status)
          Allows this ReadableByteChannel to be told that someone is no longer interested in reading from it.
 boolean isOpen()
           
 int read(ByteBuffer dst)
           
 long read(ByteBuffer[] dst)
           
 long read(ByteBuffer[] dst, int offset, int length)
           
 void setReadChannel(InterestReadableByteChannel newChannel)
          Set the source channel
 void shutdown()
          Releases any resources used by this component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.limewire.nio.observer.ReadObserver
handleRead
 

Field Detail

buffer

protected ByteBuffer buffer
Implementors should write to buffer.


source

protected InterestReadableByteChannel source

shutdown

protected boolean shutdown
Constructor Detail

AbstractChannelInterestReader

public AbstractChannelInterestReader(int bufferSize)
Method Detail

read

public int read(ByteBuffer dst)
Specified by:
read in interface ReadableByteChannel

read

public long read(ByteBuffer[] dst)
Specified by:
read in interface ScatteringByteChannel

read

public long read(ByteBuffer[] dst,
                 int offset,
                 int length)
Specified by:
read in interface ScatteringByteChannel

shutdown

public void shutdown()
Description copied from interface: Shutdownable
Releases any resources used by this component.

shutdown must never throw any exceptions.

Specified by:
shutdown in interface Shutdownable

getReadChannel

public InterestReadableByteChannel getReadChannel()
Description copied from interface: ChannelReader
Gets the source channel.

Specified by:
getReadChannel in interface ChannelReader

setReadChannel

public void setReadChannel(InterestReadableByteChannel newChannel)
Description copied from interface: ChannelReader
Set the source channel

Specified by:
setReadChannel in interface ChannelReader

interestRead

public void interestRead(boolean status)
Description copied from interface: InterestReadableByteChannel
Allows this ReadableByteChannel to be told that someone is no longer interested in reading from it. Conversely, you can signal interest in reading.

Specified by:
interestRead in interface InterestReadableByteChannel
Parameters:
status - true means interest in reading, false means a lack of interest.

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in interface Channel
Throws:
IOException

isOpen

public boolean isOpen()
Specified by:
isOpen in interface Channel

handleIOException

public void handleIOException(IOException iox)
Description copied from interface: IOErrorObserver
Notification that an IOException occurred while dispatching.

Specified by:
handleIOException in interface IOErrorObserver

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.