1 /*
   2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.corba.se.impl.encoding;
  27 
  28 import com.sun.corba.se.impl.orbutil.ORBConstants;
  29 import com.sun.corba.se.impl.orbutil.ORBUtility;
  30 import com.sun.corba.se.impl.encoding.ByteBufferWithInfo;
  31 import com.sun.corba.se.impl.encoding.BufferManagerWrite;
  32 import com.sun.corba.se.pept.encoding.OutputObject;
  33 import com.sun.corba.se.pept.transport.Connection;
  34 import com.sun.corba.se.spi.orb.ORB;
  35 import com.sun.corba.se.spi.orb.ORBData;
  36 
  37 public class BufferManagerWriteGrow extends BufferManagerWrite
  38 {
  39     BufferManagerWriteGrow( ORB orb )
  40     {
  41         super(orb) ;
  42     }
  43 
  44     public boolean sentFragment() {
  45         return false;
  46     }
  47 
  48     /**
  49      * Returns the correct buffer size for this type of
  50      * buffer manager as set in the ORB.
  51      */
  52     public int getBufferSize() {
  53         ORBData orbData = null;
  54         int bufferSize = ORBConstants.GIOP_DEFAULT_BUFFER_SIZE;
  55         if (orb != null) {
  56             orbData = orb.getORBData();
  57             if (orbData != null) {
  58                 bufferSize = orbData.getGIOPBufferSize();
  59                 dprint("BufferManagerWriteGrow.getBufferSize: bufferSize == " + bufferSize);
  60             } else {
  61                 dprint("BufferManagerWriteGrow.getBufferSize: orbData reference is NULL");
  62             }
  63         } else {
  64             dprint("BufferManagerWriteGrow.getBufferSize: orb reference is NULL");
  65         }
  66         return bufferSize;
  67     }
  68 
  69     public void overflow (ByteBufferWithInfo bbwi)
  70     {
  71         // The code that once lived directly in CDROutputStream.grow()
  72         // has been moved ByteBufferWithInfo.growBuffer().
  73 
  74         // Grow ByteBufferWithInfo to a larger size.
  75         bbwi.growBuffer(orb);
  76 
  77         // Must be false for the grow case
  78         bbwi.fragmented = false;
  79     }
  80 
  81     public void sendMessage ()
  82     {
  83         Connection conn =
  84               ((OutputObject)outputObject).getMessageMediator().getConnection();
  85 
  86         conn.writeLock();
  87 
  88         try {
  89 
  90             conn.sendWithoutLock((OutputObject)outputObject);
  91 
  92             sentFullMessage = true;
  93 
  94         } finally {
  95 
  96             conn.writeUnlock();
  97         }
  98     }
  99 
 100     /**
 101      * Close the BufferManagerWrite and do any outstanding cleanup.
 102      *
 103      * No work to do for a BufferManagerWriteGrow.
 104      */
 105     public void close() {}
 106 
 107     private void dprint(String msg) {
 108         if (orb.transportDebugFlag) {
 109             ORBUtility.dprint(this, msg);
 110 }
 111     }
 112 }