1. /*
  2. * @(#)BufferManagerWrite.java 1.10 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.encoding;
  8. import com.sun.corba.se.spi.logging.CORBALogDomains;
  9. import com.sun.corba.se.spi.orb.ORB;
  10. import com.sun.corba.se.impl.encoding.ByteBufferWithInfo;
  11. import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  12. /**
  13. * Defines the contract between the BufferManager and
  14. * CDR stream on the writing side. The CDR stream
  15. * calls back to the BufferManagerWrite when it needs
  16. * more room in the output buffer to continue. The
  17. * BufferManager can then grow the output buffer or
  18. * use some kind of fragmentation technique.
  19. */
  20. public abstract class BufferManagerWrite
  21. {
  22. protected ORB orb ;
  23. protected ORBUtilSystemException wrapper ;
  24. BufferManagerWrite( ORB orb )
  25. {
  26. this.orb = orb ;
  27. this.wrapper = ORBUtilSystemException.get( orb,
  28. CORBALogDomains.RPC_ENCODING ) ;
  29. }
  30. /**
  31. * Has the stream sent out any fragments so far?
  32. */
  33. public abstract boolean sentFragment();
  34. /**
  35. * Has the entire message been sent? (Has
  36. * sendMessage been called?)
  37. */
  38. public boolean sentFullMessage() {
  39. return sentFullMessage;
  40. }
  41. /**
  42. * Returns the correct buffer size for this type of
  43. * buffer manager as set in the ORB.
  44. */
  45. public abstract int getBufferSize();
  46. /*
  47. * Called from CDROutputStream.grow.
  48. *
  49. * bbwi.buf contains a byte array which needs to grow by bbwi.needed bytes.
  50. *
  51. * This can be handled in several ways:
  52. *
  53. * 1. Resize the bbwi.buf like the current implementation of
  54. * CDROutputStream.grow.
  55. *
  56. * 2. Collect the buffer for a later send:
  57. * this.bufQ.put(bbwi);
  58. * return new ByteBufferWithInfo(bbwi.length);
  59. *
  60. * 3. Send buffer as fragment:
  61. * Backpatch fragment size field in bbwi.buf.
  62. * Set more fragments bit in bbwi.buf.
  63. * this.connection.send(bbwi);
  64. * return reinitialized bbwi.buf with fragment header
  65. *
  66. * All cases should adjust the returned bbwi.* appropriately.
  67. *
  68. * Should set the bbwi.fragmented flag to true only in cases 2 and 3.
  69. */
  70. public abstract void overflow (ByteBufferWithInfo bbwi);
  71. /**
  72. * Called after Stub._invoke (i.e., before complete message has been sent).
  73. *
  74. * IIOPOutputStream.writeTo called from IIOPOutputStream.invoke
  75. *
  76. * Case: overflow was never called (bbwi.buf contains complete message).
  77. * Backpatch size field.
  78. * If growing or collecting:
  79. * this.bufQ.put(bbwi).
  80. * this.bufQ.iterate // However, see comment in getBufferQ
  81. * this.connection.send(fragment)
  82. * If streaming:
  83. * this.connection.send(bbwi).
  84. *
  85. * Case: overflow was called N times (bbwi.buf contains last buffer).
  86. * If growing or collecting:
  87. * this.bufQ.put(bbwi).
  88. * backpatch size field in first buffer.
  89. * this.bufQ.iterate // However, see comment in getBufferQ
  90. * this.connection.send(fragment)
  91. * If streaming:
  92. * backpatch fragment size field in bbwi.buf.
  93. * Set no more fragments bit.
  94. * this.connection.send(bbwi).
  95. */
  96. public abstract void sendMessage ();
  97. /**
  98. * A reference to the connection level stream will be required when
  99. * sending fragments.
  100. */
  101. public void setOutputObject(Object outputObject) {
  102. this.outputObject = outputObject;
  103. }
  104. /**
  105. * Close the BufferManagerWrite and do any outstanding cleanup.
  106. */
  107. abstract public void close();
  108. // XREVISIT - Currently a java.lang.Object during
  109. // the rip-int-generic transition. Should eventually
  110. // become a GIOPOutputObject.
  111. protected Object outputObject;
  112. protected boolean sentFullMessage = false;
  113. }