1. /*
  2. * @(#)BufferManagerFactory.java 1.12 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.BufferManagerReadGrow;
  9. import com.sun.corba.se.internal.iiop.BufferManagerWriteGrow;
  10. import com.sun.corba.se.internal.iiop.BufferManagerWriteCollect;
  11. import com.sun.corba.se.internal.iiop.BufferManagerWriteStream;
  12. import com.sun.corba.se.internal.iiop.Connection;
  13. import com.sun.corba.se.internal.iiop.IIOPOutputStream;
  14. import com.sun.corba.se.internal.iiop.IIOPInputStream;
  15. import com.sun.corba.se.internal.core.GIOPVersion;
  16. import com.sun.corba.se.internal.corba.ORB;
  17. import com.sun.corba.se.internal.orbutil.ORBConstants;
  18. import org.omg.CORBA.INTERNAL;
  19. /**
  20. * Creates read/write buffer managers to handle over/under flow
  21. * in CDR*putStream.
  22. */
  23. public class BufferManagerFactory
  24. {
  25. public static final int GROW = 0;
  26. public static final int COLLECT = 1;
  27. public static final int STREAM = 2;
  28. /**
  29. * Case: Given to ClientRequest (who gives it to CDROutputStream)
  30. * constructor.
  31. *
  32. * ClientDelegate.createRequest - remote case
  33. *
  34. * newBufferManagerWrite(conn);
  35. * new ClientRequestImpl(.... writeBufferManager ...);
  36. * IIOPOutputStream constructor
  37. * CDROutputStream constructor
  38. *
  39. * Does:
  40. *
  41. * this.connection = connection;
  42. *
  43. * If collecting (i.e., GIOP 1.2 phase one implementation):
  44. * this.bufQ = new BufQ();
  45. *
  46. * This will return a different concrete instance depending
  47. * on the strategy: grow, collect or stream.
  48. *
  49. * This given connection is ignored in all cases except streaming.
  50. */
  51. /*
  52. public static BufferManagerWrite newBufferManagerWrite(int strategy,
  53. Connection connection)
  54. {
  55. switch (strategy) {
  56. case GROW : return new BufferManagerWriteGrow();
  57. default : throw new INTERNAL();
  58. }
  59. }
  60. */
  61. // The next two methods allow creation of BufferManagers based on GIOP version.
  62. // We may want more criteria to be involved in this decision.
  63. // These are only used for sending messages (so could be fragmenting)
  64. public static BufferManagerRead newBufferManagerRead(GIOPVersion version,
  65. org.omg.CORBA.ORB orb)
  66. {
  67. // REVISIT - On the reading side, shouldn't we monitor the incoming
  68. // fragments on a given connection to determine what fragment size
  69. // they're using, then use that ourselves?
  70. switch (version.intValue())
  71. {
  72. case GIOPVersion.VERSION_1_0:
  73. return new BufferManagerReadGrow();
  74. case GIOPVersion.VERSION_1_1:
  75. case GIOPVersion.VERSION_1_2:
  76. return new BufferManagerReadStream();
  77. default:
  78. // REVISIT - what is appropriate?
  79. throw new INTERNAL();
  80. }
  81. }
  82. public static BufferManagerWrite newBufferManagerWrite(GIOPVersion version,
  83. org.omg.CORBA.ORB orb,
  84. int size)
  85. {
  86. int strategy;
  87. switch (version.intValue())
  88. {
  89. case GIOPVersion.VERSION_1_0:
  90. return new BufferManagerWriteGrow(size);
  91. case GIOPVersion.VERSION_1_1:
  92. if (orb != null)
  93. strategy = ((ORB)orb).getGIOPBuffMgrStrategy(version);
  94. else
  95. strategy = ORBConstants.DEFAULT_GIOP_11_BUFFMGR;
  96. if (strategy == GROW)
  97. return new BufferManagerWriteGrow(size);
  98. else
  99. return new BufferManagerWriteCollect(size);
  100. case GIOPVersion.VERSION_1_2:
  101. if (orb != null)
  102. strategy = ((ORB)orb).getGIOPBuffMgrStrategy(version);
  103. else
  104. strategy = ORBConstants.DEFAULT_GIOP_12_BUFFMGR;
  105. if (strategy == GROW)
  106. return new BufferManagerWriteGrow(size);
  107. else
  108. if (strategy == COLLECT)
  109. return new BufferManagerWriteCollect(size);
  110. else
  111. return new BufferManagerWriteStream(size);
  112. default:
  113. // REVISIT - what is appropriate?
  114. throw new INTERNAL();
  115. }
  116. }
  117. public static BufferManagerWrite newBufferManagerWrite(GIOPVersion version,
  118. org.omg.CORBA.ORB orb)
  119. {
  120. int size;
  121. int strategy;
  122. switch (version.intValue())
  123. {
  124. case GIOPVersion.VERSION_1_0:
  125. if (orb != null)
  126. size = ((ORB)orb).getGIOPBufferSize();
  127. else
  128. size = ORBConstants.GIOP_DEFAULT_BUFFER_SIZE;
  129. return new BufferManagerWriteGrow(size);
  130. case GIOPVersion.VERSION_1_1:
  131. if (orb != null){
  132. size = ((ORB)orb).getGIOPFragmentSize();
  133. strategy = ((ORB)orb).getGIOPBuffMgrStrategy(version);
  134. }
  135. else {
  136. size = ORBConstants.GIOP_DEFAULT_FRAGMENT_SIZE;
  137. strategy = ORBConstants.DEFAULT_GIOP_11_BUFFMGR;
  138. }
  139. if (strategy == GROW) {
  140. return new BufferManagerWriteGrow(size); //"Fragment" size is initial size;
  141. }
  142. return new BufferManagerWriteCollect(size);
  143. case GIOPVersion.VERSION_1_2:
  144. if (orb != null){
  145. size = ((ORB)orb).getGIOPFragmentSize();
  146. strategy = ((ORB)orb).getGIOPBuffMgrStrategy(version);
  147. }
  148. else {
  149. size = ORBConstants.GIOP_DEFAULT_FRAGMENT_SIZE;
  150. strategy = ORBConstants.DEFAULT_GIOP_12_BUFFMGR;
  151. }
  152. if (strategy == GROW) {
  153. return new BufferManagerWriteGrow(size); //"Fragment" size is initial size;
  154. } if (strategy == COLLECT) {
  155. return new BufferManagerWriteCollect(size);
  156. }
  157. return new BufferManagerWriteStream(size);
  158. default:
  159. // REVISIT - what is appropriate?
  160. throw new INTERNAL();
  161. }
  162. }
  163. // The next two methods are used for non-fragmenting cases only
  164. // REVISIT - this downcasting is really bad. TypeCodeImpl passes an
  165. // ORBSingleton in here. We should have a different constructor on
  166. // CDR that takes one and just uses the constant buffer size.
  167. public static BufferManagerWrite defaultBufferManagerWrite(org.omg.CORBA.ORB orb) {
  168. if (orb == null || !(orb instanceof com.sun.corba.se.internal.corba.ORB))
  169. return new BufferManagerWriteGrow(ORBConstants.GIOP_DEFAULT_BUFFER_SIZE);
  170. else
  171. return new BufferManagerWriteGrow(((ORB)orb).getGIOPBufferSize());
  172. }
  173. public static BufferManagerRead defaultBufferManagerRead() {
  174. return new BufferManagerReadGrow();
  175. }
  176. /**
  177. * Case: Called from ReaderThread.
  178. * The BufferManagerRead instance is given to the
  179. * ServerRequest constructor.
  180. *
  181. * IIOPConnection.createInputStream
  182. *
  183. * newBufferManagerRead()
  184. * ClientResponseImpl(... BufferManagerRead ...)
  185. * IIOPInputStream constructor
  186. * CDRInputStream constructor
  187. *
  188. * Does:
  189. *
  190. * this.bufQ = new BufQ();
  191. *
  192. * This will return a different concrete instance
  193. * depending on the strategy: grow, collect or stream.
  194. */
  195. /*
  196. public static BufferManagerRead newBufferManagerRead (int strategy)
  197. {
  198. switch (strategy) {
  199. case GROW : return new BufferManagerReadGrow();
  200. default : throw new INTERNAL();
  201. }
  202. }
  203. */
  204. }