FileDocCategorySizeDatePackage
BufferManagerWriteCollect.javaAPI DocJava SE 5 API6799Fri Aug 26 14:54:20 BST 2005com.sun.corba.se.impl.encoding

BufferManagerWriteCollect

public class BufferManagerWriteCollect extends com.sun.corba.se.impl.encoding.BufferManagerWrite
Collect buffer manager.

Fields Summary
private com.sun.corba.se.impl.encoding.BufferQueue
queue
private boolean
sentFragment
private boolean
debug
Constructors Summary
BufferManagerWriteCollect(com.sun.corba.se.spi.orb.ORB orb)



     
    
        super(orb);
         if (orb != null)
            debug = orb.transportDebugFlag;
    
Methods Summary
public voidclose()
Close the BufferManagerWrite - do any outstanding cleanup. For a BufferManagerWriteGrow any queued ByteBufferWithInfo must have its ByteBuffer released to the ByteBufferPool.

        // iterate thru queue and release any ByteBufferWithInfo's
        // ByteBuffer that may be remaining on the queue to the
        // ByteBufferPool.

        Iterator bufs = iterator();

        ByteBufferPool byteBufferPool = orb.getByteBufferPool();

        while (bufs.hasNext())
        {
            ByteBufferWithInfo bbwi = (ByteBufferWithInfo)bufs.next();
            if (bbwi != null && bbwi.byteBuffer != null)
            {
                if (debug)
                {
                    // print address of ByteBuffer being released
                    int bbAddress = System.identityHashCode(bbwi.byteBuffer);
                    StringBuffer sb = new StringBuffer(80);
                    sb.append("close() - releasing ByteBuffer id (");
                    sb.append(bbAddress).append(") to ByteBufferPool.");
                    String msg = sb.toString();
                    dprint(msg);
                }
                 byteBufferPool.releaseByteBuffer(bbwi.byteBuffer);
                 bbwi.byteBuffer = null;
                 bbwi = null;
            }
        }
    
private voiddprint(java.lang.String msg)

        ORBUtility.dprint("BufferManagerWriteCollect", msg);
    
public intgetBufferSize()
Returns the correct buffer size for this type of buffer manager as set in the ORB.

        return orb.getORBData().getGIOPFragmentSize();
    
private java.util.Iteratoriterator()

	return new BufferManagerWriteCollectIterator();
    
public voidoverflow(com.sun.corba.se.impl.encoding.ByteBufferWithInfo bbwi)

        // Set the fragment's moreFragments field to true
        MessageBase.setFlag(bbwi.byteBuffer, Message.MORE_FRAGMENTS_BIT);

        // Enqueue the previous fragment
        queue.enqueue(bbwi);

        // Create a new bbwi
        ByteBufferWithInfo newBbwi = new ByteBufferWithInfo(orb, this);
        newBbwi.fragmented = true;

        // XREVISIT - Downcast
        ((CDROutputObject)outputObject).setByteBufferWithInfo(newBbwi);

        // Now we must marshal in the fragment header/GIOP header

        // REVISIT - we can optimize this by not creating the fragment message
        // each time.  

        // XREVISIT - Downcast
        FragmentMessage header =
              ((CDROutputObject)outputObject).getMessageHeader()
                                             .createFragmentMessage();

        header.write((CDROutputObject)outputObject);
    
public voidsendMessage()

        // Enqueue the last fragment
        queue.enqueue(((CDROutputObject)outputObject).getByteBufferWithInfo());

        Iterator bufs = iterator();

        Connection conn = 
                          ((OutputObject)outputObject).getMessageMediator().
                                                       getConnection();

        // With the collect strategy, we must lock the connection
        // while fragments are being sent.  This is so that there are
        // no interleved fragments in GIOP 1.1.
        //
        // Note that this thread must not call writeLock again in any
        // of its send methods!
        conn.writeLock();

        try {

            // Get a reference to ByteBufferPool so that the ByteBufferWithInfo
            // ByteBuffer can be released to the ByteBufferPool
            ByteBufferPool byteBufferPool = orb.getByteBufferPool();

            while (bufs.hasNext()) {
                
                ByteBufferWithInfo bbwi = (ByteBufferWithInfo)bufs.next();
                ((CDROutputObject)outputObject).setByteBufferWithInfo(bbwi);
                
                conn.sendWithoutLock(((CDROutputObject)outputObject));

                sentFragment = true;

                // Release ByteBufferWithInfo's ByteBuffer back to the pool
                // of ByteBuffers.
                if (debug)
                {
                    // print address of ByteBuffer being released
                    int bbAddress = System.identityHashCode(bbwi.byteBuffer);
                    StringBuffer sb = new StringBuffer(80);
                    sb.append("sendMessage() - releasing ByteBuffer id (");
                    sb.append(bbAddress).append(") to ByteBufferPool.");
                    String msg = sb.toString();
                    dprint(msg);
                }
                byteBufferPool.releaseByteBuffer(bbwi.byteBuffer);
                bbwi.byteBuffer = null;
                bbwi = null;
            }

            sentFullMessage = true;
            
        } finally {

            conn.writeUnlock();
        }
    
public booleansentFragment()

        return sentFragment;