src/share/classes/com/sun/corba/se/impl/encoding/BufferManagerWriteStream.java

changeset 0
7ef37b2cdcad
child 748
6845b95cba6b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/corba/se/impl/encoding/BufferManagerWriteStream.java	Wed Apr 27 01:21:28 2016 +0800
     1.3 @@ -0,0 +1,134 @@
     1.4 +/*
     1.5 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +package com.sun.corba.se.impl.encoding;
    1.29 +
    1.30 +import java.nio.ByteBuffer;
    1.31 +
    1.32 +import com.sun.corba.se.impl.orbutil.ORBConstants;
    1.33 +import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
    1.34 +import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase;
    1.35 +import com.sun.corba.se.impl.protocol.giopmsgheaders.FragmentMessage;
    1.36 +import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage;
    1.37 +import com.sun.corba.se.impl.encoding.BufferManagerWrite;
    1.38 +import com.sun.corba.se.impl.encoding.ByteBufferWithInfo;
    1.39 +import com.sun.corba.se.impl.encoding.CDROutputObject;
    1.40 +import com.sun.corba.se.spi.orb.ORB;
    1.41 +import com.sun.corba.se.pept.transport.Connection;
    1.42 +import com.sun.corba.se.pept.encoding.OutputObject;
    1.43 +import org.omg.CORBA.SystemException;
    1.44 +
    1.45 +/**
    1.46 + * Streaming buffer manager.
    1.47 + */
    1.48 +public class BufferManagerWriteStream extends BufferManagerWrite
    1.49 +{
    1.50 +    private int fragmentCount = 0;
    1.51 +
    1.52 +    BufferManagerWriteStream( ORB orb )
    1.53 +    {
    1.54 +        super(orb) ;
    1.55 +    }
    1.56 +
    1.57 +    public boolean sentFragment() {
    1.58 +        return fragmentCount > 0;
    1.59 +    }
    1.60 +
    1.61 +    /**
    1.62 +     * Returns the correct buffer size for this type of
    1.63 +     * buffer manager as set in the ORB.
    1.64 +     */
    1.65 +    public int getBufferSize() {
    1.66 +        return orb.getORBData().getGIOPFragmentSize();
    1.67 +    }
    1.68 +
    1.69 +    public void overflow (ByteBufferWithInfo bbwi)
    1.70 +    {
    1.71 +        // Set the fragment's moreFragments field to true
    1.72 +        MessageBase.setFlag(bbwi.byteBuffer, Message.MORE_FRAGMENTS_BIT);
    1.73 +
    1.74 +        try {
    1.75 +           sendFragment(false);
    1.76 +        } catch(SystemException se){
    1.77 +                orb.getPIHandler().invokeClientPIEndingPoint(
    1.78 +                        ReplyMessage.SYSTEM_EXCEPTION, se);
    1.79 +                throw se;
    1.80 +        }
    1.81 +
    1.82 +        // Reuse the old buffer
    1.83 +
    1.84 +        // REVISIT - need to account for case when needed > available
    1.85 +        // even after fragmenting.  This is the large array case, so
    1.86 +        // the caller should retry when it runs out of space.
    1.87 +        bbwi.position(0);
    1.88 +        bbwi.buflen = bbwi.byteBuffer.limit();
    1.89 +        bbwi.fragmented = true;
    1.90 +
    1.91 +        // Now we must marshal in the fragment header/GIOP header
    1.92 +
    1.93 +        // REVISIT - we can optimize this by not creating the fragment message
    1.94 +        // each time.
    1.95 +
    1.96 +        FragmentMessage header = ((CDROutputObject)outputObject).getMessageHeader().createFragmentMessage();
    1.97 +
    1.98 +        header.write(((CDROutputObject)outputObject));
    1.99 +    }
   1.100 +
   1.101 +    private void sendFragment(boolean isLastFragment)
   1.102 +    {
   1.103 +        Connection conn = ((OutputObject)outputObject).getMessageMediator().getConnection();
   1.104 +
   1.105 +        // REVISIT: need an ORB
   1.106 +        //System.out.println("sendFragment: last?: " + isLastFragment);
   1.107 +        conn.writeLock();
   1.108 +
   1.109 +        try {
   1.110 +            // Send the fragment
   1.111 +            conn.sendWithoutLock(((OutputObject)outputObject));
   1.112 +
   1.113 +            fragmentCount++;
   1.114 +
   1.115 +        } finally {
   1.116 +
   1.117 +            conn.writeUnlock();
   1.118 +        }
   1.119 +
   1.120 +    }
   1.121 +
   1.122 +    // Sends the last fragment
   1.123 +    public void sendMessage ()
   1.124 +    {
   1.125 +        sendFragment(true);
   1.126 +
   1.127 +        sentFullMessage = true;
   1.128 +    }
   1.129 +
   1.130 +    /**
   1.131 +     * Close the BufferManagerWrite and do any outstanding cleanup.
   1.132 +     *
   1.133 +     * No work to do for a BufferManagerWriteStream
   1.134 +     */
   1.135 +    public void close(){};
   1.136 +
   1.137 +}

mercurial