Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

TcpIpChunkProvider Class Reference

Inheritance diagram for TcpIpChunkProvider:

Inheritance graph
[legend]
Collaboration diagram for TcpIpChunkProvider:

Collaboration graph
[legend]
List of all members.

Public Methods

Chunk prepare () throws JonathanException
void close ()
Chunk duplicate () throws JonathanException
Chunk duplicate (int off, int t) throws JonathanException
void release ()

Protected Methods

void finalize ()

Private Methods

 TcpIpChunkProvider (TcpIpProtocol.Session session)
 TcpIpChunkProvider (TcpIpChunkProvider message)
final void delete ()

Private Attributes

TcpIpProtocol Session session
IpConnection connection
int max
Chunk cache

Static Private Attributes

final byte [] empty_data = new byte[0]
final Chunk empty_chunk = new Chunk(empty_data,0,0)

Detailed Description

TcpIpChunkProvider is a ChunkProvider implementation encapsulating a socket input stream.

Definition at line 629 of file TcpIpProtocol.java.


Constructor & Destructor Documentation

TcpIpChunkProvider::TcpIpChunkProvider ( TcpIpProtocol.Session session ) [inline, private]
 

Definition at line 642 of file TcpIpProtocol.java.

00642                                                      {
00643       super(empty_data,0,0);
00644       max = 0;
00645       this.session = session;
00646       connection = session.connection;
00647       cache = empty_chunk;
00648    }

TcpIpChunkProvider::TcpIpChunkProvider ( TcpIpChunkProvider message ) [inline, private]
 

Definition at line 650 of file TcpIpProtocol.java.

00650                                                   {
00651       super(message.data,message.offset,message.top);
00652       cache = message.cache;
00653       max = message.max;
00654       session = message.session;
00655       connection = message.connection;
00656       message.cache = null;
00657    }


Member Function Documentation

void TcpIpChunkProvider::close ( ) [inline]
 

Closes the chunk provider. This method must be called if the target provider is no longer used.

Reimplemented from ChunkProvider.

Definition at line 699 of file TcpIpProtocol.java.

Referenced by TcpIpProtocol::CltSession::send(), and TcpIpProtocol::SrvSession::send().

00699                        {
00700       if (cache != null) {
00701          session.closeNotify(this);
00702       }
00703    }

final void TcpIpChunkProvider::delete ( ) [inline, private]
 

Definition at line 713 of file TcpIpProtocol.java.

Referenced by TcpIpProtocol::Session::closeNotify().

00713                        {
00714       if (cache != null) {
00715          cache.release();
00716          cache = null;
00717       }
00718       
00719       session.deleteNotify(this);
00720    }

Chunk TcpIpChunkProvider::duplicate ( int off,
int t ) [inline]
 

Partially duplicates this chunk. 'offset' must be greater than the target chunk's offset, 'top' must be less or equal than the target's top.

The default implementation copies the appropriate portion of the buffer, and creates a new chunk with it.

Parameters:
offset   the offset of the chunk copy.
top   the top of the chunk copy.
Returns:
a chunk containing the specified part of the target chunk.
Exceptions:
org   .objectweb.jonathan.exceptions.JonathanException if an error occurs.

Reimplemented from Chunk.

Definition at line 727 of file TcpIpProtocol.java.

00727                                                                   {
00728       cache.top = top;
00729       return cache.duplicate(off,t);
00730    }

Chunk TcpIpChunkProvider::duplicate ( ) [inline]
 

Duplicates the whole chunk.

The default implementation copies the buffer, and creates a new chunk with it.

Returns:
a copy of this chunk.
Exceptions:
org   .objectweb.jonathan.exceptions.JonathanException if an IO error occurs.

Reimplemented from Chunk.

Definition at line 722 of file TcpIpProtocol.java.

00722                                                      {
00723       cache.top = top;
00724       return cache.duplicate(offset,top);
00725    }

void TcpIpChunkProvider::finalize ( ) [inline, protected]
 

Definition at line 705 of file TcpIpProtocol.java.

00705                              {
00706       if (cache != null) {
00707          System.err.println("Resource management error. message " + this + 
00708                             " has not been properly closed.");
00709          delete();
00710       }
00711    }   

Chunk TcpIpChunkProvider::prepare ( ) [inline]
 

Returns a chunk to read data from.

When done with the chunk, its user must update its offset and top members and release it.

ChunkProviders should not be used concurrently.

Returns:
a chunk;
Exceptions:
JonathanException   if no chunk can be provided.

Reimplemented from ChunkProvider.

Definition at line 659 of file TcpIpProtocol.java.

00659                                                    {
00660       TcpIpProtocol protocol = session.getProtocol();
00661       if (top == offset) {
00662          // there is nothing left to read from this message
00663          try {
00664             int to_read = connection.available();
00665             if (to_read > 1) {
00666                if (to_read > max - top) {
00667                   cache.release();
00668                   cache = protocol.chunk_factory.newChunk(to_read);
00669                   data = cache.data;
00670                   offset = cache.offset;
00671                   top = cache.top;
00672                   max = data.length;
00673                }
00674                connection.receive(this,to_read);
00675                return this;
00676             } else {
00677                if (max - top == 0) {
00678                   cache.release();
00679                   cache = protocol.chunk_factory.newChunk();
00680                   data = cache.data;
00681                   offset = cache.offset;
00682                   top = cache.top;
00683                   max = data.length;
00684                }
00685                connection.receive(this,1);
00686                return this;
00687             }
00688          } catch (IOException e) {
00689             delete();
00690             connection.delete();
00691             connection = null;
00692             throw new JonathanException(e);
00693          } 
00694       } else {
00695          return this;
00696       }
00697    }

void TcpIpChunkProvider::release ( ) [inline]
 

Releases the chunk. The data of a chunk may be obtained from managed buffers. It may thus be necessary to tell when the data encapsulated by a chunk may be reused.

The default implementation resets offset and top to 0.

Reimplemented from Chunk.

Definition at line 732 of file TcpIpProtocol.java.

00732 {}   


Member Data Documentation

Chunk TcpIpChunkProvider::cache [private]
 

the data of this chunk provider are the cache data.

Definition at line 640 of file TcpIpProtocol.java.

IpConnection TcpIpChunkProvider::connection [private]
 

The network connection

Definition at line 636 of file TcpIpProtocol.java.

final Chunk TcpIpChunkProvider::empty_chunk = new Chunk(empty_data,0,0) [static, private]
 

Definition at line 631 of file TcpIpProtocol.java.

final byte [] TcpIpChunkProvider::empty_data = new byte[0] [static, private]
 

Definition at line 630 of file TcpIpProtocol.java.

int TcpIpChunkProvider::max [private]
 

Definition at line 637 of file TcpIpProtocol.java.

TcpIpProtocol Session TcpIpChunkProvider::session [private]
 

Reader associated with the chunk

Definition at line 634 of file TcpIpProtocol.java.


The documentation for this class was generated from the following file:
Generated at Fri May 31 19:25:33 2002 for Jonathan by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001