BufferManagerFactory.java revision 608:7e06bf1dcb09
1/* 2 * Copyright (c) 2000, 2004, 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 26package com.sun.corba.se.impl.encoding; 27 28import com.sun.corba.se.impl.encoding.BufferManagerRead; 29import com.sun.corba.se.impl.encoding.BufferManagerReadGrow; 30import com.sun.corba.se.impl.encoding.BufferManagerReadStream; 31import com.sun.corba.se.impl.encoding.BufferManagerWrite; 32import com.sun.corba.se.impl.protocol.giopmsgheaders.Message; 33import com.sun.corba.se.impl.logging.ORBUtilSystemException; 34import com.sun.corba.se.spi.logging.CORBALogDomains; 35import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 36import com.sun.corba.se.spi.orb.ORB; 37 38import org.omg.CORBA.INTERNAL; 39 40/** 41 * Creates read/write buffer managers to handle over/under flow 42 * in CDR*putStream. 43 */ 44 45public class BufferManagerFactory 46{ 47 public static final int GROW = 0; 48 public static final int COLLECT = 1; 49 public static final int STREAM = 2; 50 51 // The next two methods allow creation of BufferManagers based on GIOP version. 52 // We may want more criteria to be involved in this decision. 53 // These are only used for sending messages (so could be fragmenting) 54 public static BufferManagerRead newBufferManagerRead( 55 GIOPVersion version, byte encodingVersion, ORB orb) { 56 57 // REVISIT - On the reading side, shouldn't we monitor the incoming 58 // fragments on a given connection to determine what fragment size 59 // they're using, then use that ourselves? 60 61 if (encodingVersion != Message.CDR_ENC_VERSION) { 62 return new BufferManagerReadGrow(orb); 63 } 64 65 switch (version.intValue()) 66 { 67 case GIOPVersion.VERSION_1_0: 68 return new BufferManagerReadGrow(orb); 69 case GIOPVersion.VERSION_1_1: 70 case GIOPVersion.VERSION_1_2: 71 // The stream reader can handle fragmented and 72 // non fragmented messages 73 return new BufferManagerReadStream(orb); 74 default: 75 // REVISIT - what is appropriate? 76 throw new INTERNAL("Unknown GIOP version: " 77 + version); 78 } 79 } 80 81 public static BufferManagerRead newBufferManagerRead( 82 int strategy, byte encodingVersion, ORB orb) { 83 84 if (encodingVersion != Message.CDR_ENC_VERSION) { 85 if (strategy != BufferManagerFactory.GROW) { 86 ORBUtilSystemException wrapper = 87 ORBUtilSystemException.get((ORB)orb, 88 CORBALogDomains.RPC_ENCODING); 89 throw wrapper.invalidBuffMgrStrategy("newBufferManagerRead"); 90 } 91 return new BufferManagerReadGrow(orb); 92 } 93 switch (strategy) { 94 case BufferManagerFactory.GROW: 95 return new BufferManagerReadGrow(orb); 96 case BufferManagerFactory.COLLECT: 97 throw new INTERNAL("Collect strategy invalid for reading"); 98 case BufferManagerFactory.STREAM: 99 return new BufferManagerReadStream(orb); 100 default: 101 throw new INTERNAL("Unknown buffer manager read strategy: " 102 + strategy); 103 } 104 } 105 106 public static BufferManagerWrite newBufferManagerWrite( 107 int strategy, byte encodingVersion, ORB orb) { 108 if (encodingVersion != Message.CDR_ENC_VERSION) { 109 if (strategy != BufferManagerFactory.GROW) { 110 ORBUtilSystemException wrapper = 111 ORBUtilSystemException.get((ORB)orb, 112 CORBALogDomains.RPC_ENCODING); 113 throw wrapper.invalidBuffMgrStrategy("newBufferManagerWrite"); 114 } 115 return new BufferManagerWriteGrow(orb); 116 } 117 switch (strategy) { 118 case BufferManagerFactory.GROW: 119 return new BufferManagerWriteGrow(orb); 120 case BufferManagerFactory.COLLECT: 121 return new BufferManagerWriteCollect(orb); 122 case BufferManagerFactory.STREAM: 123 return new BufferManagerWriteStream(orb); 124 default: 125 throw new INTERNAL("Unknown buffer manager write strategy: " 126 + strategy); 127 } 128 } 129 130 public static BufferManagerWrite newBufferManagerWrite( 131 GIOPVersion version, byte encodingVersion, ORB orb) { 132 if (encodingVersion != Message.CDR_ENC_VERSION) { 133 return new BufferManagerWriteGrow(orb); 134 } 135 return BufferManagerFactory.newBufferManagerWrite( 136 orb.getORBData().getGIOPBuffMgrStrategy(version), 137 encodingVersion, orb); 138 } 139 140 public static BufferManagerRead defaultBufferManagerRead(ORB orb) { 141 return new BufferManagerReadGrow(orb); 142 } 143} 144