rabbit.httpio
Class WebConnectionResourceSource

java.lang.Object
  extended by rabbit.httpio.WebConnectionResourceSource
All Implemented Interfaces:
ChunkDataFeeder, ResourceSource, Transferable, ReadHandler, SocketChannelHandler

public class WebConnectionResourceSource
extends Object
implements ResourceSource, ReadHandler, ChunkDataFeeder

A resource source that gets the data from a WebConnection

Author:
Robert Olofsson

Constructor Summary
WebConnectionResourceSource(ConnectionHandler con, NioHandler nioHandler, WebConnection wc, BufferHandle bufHandle, TrafficLogger tl, boolean isChunked, long dataSize, boolean strictHttp)
           
 
Method Summary
 void addBlockListener(BlockListener listener)
          Add a ByteBuffer listener.
 void closed()
          Signal that the channel has been closed.
 void finishedRead()
          Chunk reading has been completed.
 String getDescription()
          Get a string description.
 Long getTimeout()
          Get the timeout time in millis.
 long length()
          Get the length of the resource in bytes.
 void read()
          The channel is ready for read.
 void readMore()
          The chunk reader needs to read more data, compact buffer before registering.
 void register()
          The chunk reader needs more data.
 void release()
          Release any held resources.
 boolean supportsTransfer()
          FileChannels can not be used, will always return false.
 void timeout()
          Signal that the select operation timed out.
 long transferTo(long position, long count, WritableByteChannel target)
          Transfers bytes from this channel's file to the given writable byte channel.
 boolean useSeparateThread()
          Check if this handler needs to run in a separate thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebConnectionResourceSource

public WebConnectionResourceSource(ConnectionHandler con,
                                   NioHandler nioHandler,
                                   WebConnection wc,
                                   BufferHandle bufHandle,
                                   TrafficLogger tl,
                                   boolean isChunked,
                                   long dataSize,
                                   boolean strictHttp)
Method Detail

getDescription

public String getDescription()
Description copied from interface: SocketChannelHandler
Get a string description.

Specified by:
getDescription in interface SocketChannelHandler

supportsTransfer

public boolean supportsTransfer()
FileChannels can not be used, will always return false.

Specified by:
supportsTransfer in interface ResourceSource
Returns:
false

length

public long length()
Description copied from interface: Transferable
Get the length of the resource in bytes.

Specified by:
length in interface Transferable
Returns:
the size of the resource or -1 if unknown.

transferTo

public long transferTo(long position,
                       long count,
                       WritableByteChannel target)
                throws IOException
Description copied from interface: Transferable
Transfers bytes from this channel's file to the given writable byte channel.

Specified by:
transferTo in interface Transferable
Parameters:
position - The position within the file at which the transfer is to begin; must be non-negative
count - The maximum number of bytes to be transferred; must be non-negative
target - The target channel
Returns:
The number of bytes, possibly zero, that were actually transferred
Throws:
IOException
See Also:
transferTo

addBlockListener

public void addBlockListener(BlockListener listener)
Description copied from interface: ResourceSource
Add a ByteBuffer listener.

Specified by:
addBlockListener in interface ResourceSource

finishedRead

public void finishedRead()
Description copied from interface: ChunkDataFeeder
Chunk reading has been completed.

Specified by:
finishedRead in interface ChunkDataFeeder

register

public void register()
Description copied from interface: ChunkDataFeeder
The chunk reader needs more data.

Specified by:
register in interface ChunkDataFeeder

readMore

public void readMore()
Description copied from interface: ChunkDataFeeder
The chunk reader needs to read more data, compact buffer before registering.

Specified by:
readMore in interface ChunkDataFeeder

read

public void read()
Description copied from interface: ReadHandler
The channel is ready for read.

Specified by:
read in interface ReadHandler

useSeparateThread

public boolean useSeparateThread()
Description copied from interface: SocketChannelHandler
Check if this handler needs to run in a separate thread.

Specified by:
useSeparateThread in interface SocketChannelHandler

closed

public void closed()
Description copied from interface: SocketChannelHandler
Signal that the channel has been closed.

Specified by:
closed in interface SocketChannelHandler

timeout

public void timeout()
Description copied from interface: SocketChannelHandler
Signal that the select operation timed out.

Specified by:
timeout in interface SocketChannelHandler

getTimeout

public Long getTimeout()
Description copied from interface: SocketChannelHandler
Get the timeout time in millis.

Specified by:
getTimeout in interface SocketChannelHandler
Returns:
the time when this operation times out, null if no timeout is set.

release

public void release()
Description copied from interface: ResourceSource
Release any held resources.

Specified by:
release in interface ResourceSource