1. /*
  2. * @(#)BufferManagerWrite.java 1.8 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.iiop;
  8. import com.sun.corba.se.internal.iiop.ByteBufferWithInfo;
  9. import java.util.Iterator;
  10. import com.sun.corba.se.internal.iiop.CDROutputStream;
  11. import com.sun.corba.se.internal.iiop.IIOPOutputStream;
  12. import com.sun.corba.se.internal.iiop.IIOPInputStream;
  13. public abstract class BufferManagerWrite
  14. {
  15. /**
  16. * Case: Called from CDROutputStream constructor
  17. * before starting to marshal.
  18. *
  19. * Does:
  20. *
  21. * bbwi = new ByteBufferWithInfo(size);
  22. *
  23. * Fill in initial message headers and adjust bbwi.* appropriately
  24. *
  25. * Returns bbwi
  26. */
  27. // This has taken on a different meaning -- simply allocating the
  28. // first bbwi. It doesn't marshal in the header.
  29. public abstract ByteBufferWithInfo getInitialBuffer (int size);
  30. public abstract int getInitialBufferSize();
  31. /*
  32. * Case: Called from CDROutputStream.grow (instead of current default).
  33. *
  34. * bbwi.buf contains a byte array which needs to grow by bbwi.needed bytes.
  35. *
  36. * This can be handled in several ways:
  37. *
  38. * 1. Resize the bbwi.buf like the current implementation of
  39. * CDROutputStream.grow.
  40. *
  41. * 2. Collect the buffer for a later send:
  42. * this.bufQ.put(bbwi);
  43. * return new ByteBufferWithInfo(bbwi.length);
  44. *
  45. * 3. Send buffer as fragment:
  46. * Backpatch fragment size field in bbwi.buf.
  47. * Set more fragments bit in bbwi.buf.
  48. * this.connection.send(bbwi);
  49. * return reinitialized bbwi.buf with fragment header
  50. *
  51. * All cases should adjust the returned bbwi.* appropriately.
  52. *
  53. * Should set the bbwi.fragmented flag to true only in cases 2 and 3.
  54. */
  55. public abstract void overflow (ByteBufferWithInfo bbwi);
  56. /**
  57. * Called after Stub._invoke (i.e., before complete message has been sent).
  58. *
  59. * IIOPOutputStream.writeTo called from IIOPOutputStream.invoke
  60. *
  61. * Case: overflow was never called (bbwi.buf contains complete message).
  62. * Backpatch size field.
  63. * If growing or collecting:
  64. * this.bufQ.put(bbwi).
  65. * this.bufQ.iterate // However, see comment in getBufferQ
  66. * this.connection.send(fragment)
  67. * If streaming:
  68. * this.connection.send(bbwi).
  69. *
  70. * Case: overflow was called N times (bbwi.buf contains last buffer).
  71. * If growing or collecting:
  72. * this.bufQ.put(bbwi).
  73. * backpatch size field in first buffer.
  74. * this.bufQ.iterate // However, see comment in getBufferQ
  75. * this.connection.send(fragment)
  76. * If streaming:
  77. * backpatch fragment size field in bbwi.buf.
  78. * Set no more fragments bit.
  79. * this.connection.send(bbwi).
  80. */
  81. public abstract void sendMessage ();
  82. /**
  83. * Case: Access bufferQ to no fragments, grow, or collect.
  84. *
  85. *
  86. * IIOPOutputStream.writeTo needs buffer Q to write its
  87. * contents on the connection.
  88. *
  89. * Does:
  90. *
  91. * Abstracts bufferQ.
  92. */
  93. // public Iterator iterator ();
  94. // A reference to the IIOPOutputStream will be required when
  95. // sending fragments.
  96. public void setIIOPOutputStream(IIOPOutputStream stream) {
  97. this.stream = stream;
  98. }
  99. protected IIOPOutputStream stream;
  100. }