rabbit.proxy
Class WebConnectionResourceSource

java.lang.Object
  extended by rabbit.proxy.WebConnectionResourceSource
All Implemented Interfaces:
Runnable, ResourceSource, SocketHandler, Transferable

public class WebConnectionResourceSource
extends Object
implements ResourceSource, SocketHandler

A resource source that gets the data from a WebConnection

Author:
Robert Olofsson

Constructor Summary
WebConnectionResourceSource(Selector selector, WebConnection wc, ByteBuffer buffer, TrafficLogger tl, boolean isChunked, long dataSize, boolean strictHttp)
           
 
Method Summary
 void addBlockListener(BlockListener listener)
          Add a ByteBuffer listener.
 void finishedRead()
          Chunk reading has been completed.
 long length()
          Get the length of the resource in bytes.
 void readMore()
          The chunk reader needs to read more data, compact buffer before registering.
 void register()
          The chunk reader needs more data.
 void release(Connection con)
          Release any held resources.
 void run()
           
 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(Selector selector,
                                   WebConnection wc,
                                   ByteBuffer buffer,
                                   TrafficLogger tl,
                                   boolean isChunked,
                                   long dataSize,
                                   boolean strictHttp)
Method Detail

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: ResourceSource
Get the length of the resource in bytes.

Specified by:
length in interface ResourceSource
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()
Chunk reading has been completed.


register

public void register()
The chunk reader needs more data.


readMore

public void readMore()
The chunk reader needs to read more data, compact buffer before registering.


run

public void run()
Specified by:
run in interface Runnable

useSeparateThread

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

Specified by:
useSeparateThread in interface SocketHandler

timeout

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

Specified by:
timeout in interface SocketHandler

release

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

Specified by:
release in interface ResourceSource
Parameters:
con - the Connection handling the resource.