KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > encoding > BufferManagerFactory


1 /*
2  * @(#)BufferManagerFactory.java 1.15 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.encoding;
9
10 import com.sun.corba.se.impl.encoding.BufferManagerRead;
11 import com.sun.corba.se.impl.encoding.BufferManagerReadGrow;
12 import com.sun.corba.se.impl.encoding.BufferManagerReadStream;
13 import com.sun.corba.se.impl.encoding.BufferManagerWrite;
14 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
15 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
16 import com.sun.corba.se.spi.logging.CORBALogDomains;
17 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
18 import com.sun.corba.se.spi.orb.ORB;
19
20 import org.omg.CORBA.INTERNAL JavaDoc;
21
22 /**
23  * Creates read/write buffer managers to handle over/under flow
24  * in CDR*putStream.
25  */

26
27 public class BufferManagerFactory
28 {
29     public static final int GROW = 0;
30     public static final int COLLECT = 1;
31     public static final int STREAM = 2;
32
33     // The next two methods allow creation of BufferManagers based on GIOP version.
34
// We may want more criteria to be involved in this decision.
35
// These are only used for sending messages (so could be fragmenting)
36
public static BufferManagerRead newBufferManagerRead(
37             GIOPVersion version, byte encodingVersion, ORB orb) {
38
39         // REVISIT - On the reading side, shouldn't we monitor the incoming
40
// fragments on a given connection to determine what fragment size
41
// they're using, then use that ourselves?
42

43     if (encodingVersion != Message.CDR_ENC_VERSION) {
44         return new BufferManagerReadGrow(orb);
45     }
46
47         switch (version.intValue())
48         {
49             case GIOPVersion.VERSION_1_0:
50                 return new BufferManagerReadGrow(orb);
51             case GIOPVersion.VERSION_1_1:
52             case GIOPVersion.VERSION_1_2:
53                 // The stream reader can handle fragmented and
54
// non fragmented messages
55
return new BufferManagerReadStream(orb);
56             default:
57                 // REVISIT - what is appropriate?
58
throw new INTERNAL JavaDoc("Unknown GIOP version: "
59                                    + version);
60         }
61     }
62
63     public static BufferManagerRead newBufferManagerRead(
64             int strategy, byte encodingVersion, ORB orb) {
65
66     if (encodingVersion != Message.CDR_ENC_VERSION) {
67         if (strategy != BufferManagerFactory.GROW) {
68         ORBUtilSystemException wrapper =
69             ORBUtilSystemException.get((ORB)orb,
70                            CORBALogDomains.RPC_ENCODING);
71         throw wrapper.invalidBuffMgrStrategy("newBufferManagerRead");
72         }
73         return new BufferManagerReadGrow(orb);
74     }
75         switch (strategy) {
76             case BufferManagerFactory.GROW:
77                 return new BufferManagerReadGrow(orb);
78             case BufferManagerFactory.COLLECT:
79                 throw new INTERNAL JavaDoc("Collect strategy invalid for reading");
80             case BufferManagerFactory.STREAM:
81                 return new BufferManagerReadStream(orb);
82             default:
83                 throw new INTERNAL JavaDoc("Unknown buffer manager read strategy: "
84                                    + strategy);
85         }
86     }
87
88     public static BufferManagerWrite newBufferManagerWrite(
89             int strategy, byte encodingVersion, ORB orb) {
90     if (encodingVersion != Message.CDR_ENC_VERSION) {
91         if (strategy != BufferManagerFactory.GROW) {
92         ORBUtilSystemException wrapper =
93             ORBUtilSystemException.get((ORB)orb,
94                            CORBALogDomains.RPC_ENCODING);
95         throw wrapper.invalidBuffMgrStrategy("newBufferManagerWrite");
96         }
97         return new BufferManagerWriteGrow(orb);
98     }
99         switch (strategy) {
100             case BufferManagerFactory.GROW:
101                 return new BufferManagerWriteGrow(orb);
102             case BufferManagerFactory.COLLECT:
103                 return new BufferManagerWriteCollect(orb);
104             case BufferManagerFactory.STREAM:
105                 return new BufferManagerWriteStream(orb);
106             default:
107                 throw new INTERNAL JavaDoc("Unknown buffer manager write strategy: "
108                                    + strategy);
109         }
110     }
111
112     public static BufferManagerWrite newBufferManagerWrite(
113         GIOPVersion version, byte encodingVersion, ORB orb) {
114     if (encodingVersion != Message.CDR_ENC_VERSION) {
115         return new BufferManagerWriteGrow(orb);
116     }
117         return BufferManagerFactory.newBufferManagerWrite(
118         orb.getORBData().getGIOPBuffMgrStrategy(version),
119         encodingVersion, orb);
120     }
121
122     public static BufferManagerRead defaultBufferManagerRead(ORB orb) {
123         return new BufferManagerReadGrow(orb);
124     }
125 }
126
Popular Tags