LimeWire Consolidated API

org.limewire.nio.channel
Class AbstractBufferChannelWriter

java.lang.Object
  extended by org.limewire.nio.channel.AbstractBufferChannelWriter
All Implemented Interfaces:
ChannelWriter, IOErrorObserver, Shutdownable, WriteObserver

public abstract class AbstractBufferChannelWriter
extends Object
implements ChannelWriter

A simple channel that buffers data in a ByteBuffer.


Field Summary
protected  ByteBuffer buffer
           
protected  InterestWritableByteChannel channel
          The sink channel we write to & interest ourselves on.
protected  boolean shutdown
           
 
Constructor Summary
AbstractBufferChannelWriter(int bufferSize)
           
 
Method Summary
 InterestWritableByteChannel getWriteChannel()
          The channel we're writing to.
 void handleIOException(IOException iox)
          Does nothing.
 boolean handleWrite()
          Writes as many messages as possible to the sink.
 void put(byte[] data)
          Adds data to the buffer and signals interest in writing to the channel.
 void setWriteChannel(InterestWritableByteChannel channel)
          The channel we're writing to.
 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
 

Field Detail

channel

protected InterestWritableByteChannel channel
The sink channel we write to & interest ourselves on.


buffer

protected ByteBuffer buffer

shutdown

protected volatile boolean shutdown
Constructor Detail

AbstractBufferChannelWriter

public AbstractBufferChannelWriter(int bufferSize)
Method Detail

getWriteChannel

public InterestWritableByteChannel getWriteChannel()
The channel we're writing to.

Specified by:
getWriteChannel in interface ChannelWriter

setWriteChannel

public void setWriteChannel(InterestWritableByteChannel channel)
The channel we're writing to.

Specified by:
setWriteChannel in interface ChannelWriter

put

public void put(byte[] data)
         throws IOException
Adds data to the buffer and signals interest in writing to the channel.

Throws:
IOException - If the channel is already shutdown
BufferOverflowException - If there is insufficient space in the buffer

handleWrite

public boolean handleWrite()
                    throws IOException
Writes as many messages as possible to the sink.

Specified by:
handleWrite in interface WriteObserver
Returns:
true there is still data to be written, otherwise false.
Throws:
IOException

handleIOException

public void handleIOException(IOException iox)
Does nothing.

Specified by:
handleIOException in interface IOErrorObserver

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

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.