KickJava   Java API By Example, From Geeks To Geeks.

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


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
8 package com.sun.corba.se.impl.encoding;
9
10 import com.sun.corba.se.spi.logging.CORBALogDomains;
11
12 import com.sun.corba.se.spi.orb.ORB;
13
14 import com.sun.corba.se.impl.encoding.ByteBufferWithInfo;
15
16 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
17
18 /**
19  * Defines the contract between the BufferManager and
20  * CDR stream on the writing side. The CDR stream
21  * calls back to the BufferManagerWrite when it needs
22  * more room in the output buffer to continue. The
23  * BufferManager can then grow the output buffer or
24  * use some kind of fragmentation technique.
25  */

26 public abstract class BufferManagerWrite
27 {
28     protected ORB orb ;
29     protected ORBUtilSystemException wrapper ;
30
31     BufferManagerWrite( ORB orb )
32     {
33     this.orb = orb ;
34     this.wrapper = ORBUtilSystemException.get( orb,
35         CORBALogDomains.RPC_ENCODING ) ;
36     }
37
38     /**
39      * Has the stream sent out any fragments so far?
40      */

41     public abstract boolean sentFragment();
42
43     /**
44      * Has the entire message been sent? (Has
45      * sendMessage been called?)
46      */

47     public boolean sentFullMessage() {
48         return sentFullMessage;
49     }
50
51     /**
52      * Returns the correct buffer size for this type of
53      * buffer manager as set in the ORB.
54      */

55     public abstract int getBufferSize();
56
57     /*
58      * Called from CDROutputStream.grow.
59      *
60      * bbwi.buf contains a byte array which needs to grow by bbwi.needed bytes.
61      *
62      * This can be handled in several ways:
63      *
64      * 1. Resize the bbwi.buf like the current implementation of
65      * CDROutputStream.grow.
66      *
67      * 2. Collect the buffer for a later send:
68      * this.bufQ.put(bbwi);
69      * return new ByteBufferWithInfo(bbwi.length);
70      *
71      * 3. Send buffer as fragment:
72      * Backpatch fragment size field in bbwi.buf.
73      * Set more fragments bit in bbwi.buf.
74      * this.connection.send(bbwi);
75      * return reinitialized bbwi.buf with fragment header
76      *
77      * All cases should adjust the returned bbwi.* appropriately.
78      *
79      * Should set the bbwi.fragmented flag to true only in cases 2 and 3.
80      */

81
82     public abstract void overflow (ByteBufferWithInfo bbwi);
83
84     /**
85      * Called after Stub._invoke (i.e., before complete message has been sent).
86      *
87      * IIOPOutputStream.writeTo called from IIOPOutputStream.invoke
88      *
89      * Case: overflow was never called (bbwi.buf contains complete message).
90      * Backpatch size field.
91      * If growing or collecting:
92      * this.bufQ.put(bbwi).
93      * this.bufQ.iterate // However, see comment in getBufferQ
94      * this.connection.send(fragment)
95      * If streaming:
96      * this.connection.send(bbwi).
97      *
98      * Case: overflow was called N times (bbwi.buf contains last buffer).
99      * If growing or collecting:
100      * this.bufQ.put(bbwi).
101      * backpatch size field in first buffer.
102      * this.bufQ.iterate // However, see comment in getBufferQ
103      * this.connection.send(fragment)
104      * If streaming:
105      * backpatch fragment size field in bbwi.buf.
106      * Set no more fragments bit.
107      * this.connection.send(bbwi).
108      */

109
110     public abstract void sendMessage ();
111     
112     /**
113      * A reference to the connection level stream will be required when
114      * sending fragments.
115      */

116     public void setOutputObject(Object JavaDoc outputObject) {
117         this.outputObject = outputObject;
118     }
119
120     /**
121      * Close the BufferManagerWrite and do any outstanding cleanup.
122      */

123      abstract public void close();
124
125
126     // XREVISIT - Currently a java.lang.Object during
127
// the rip-int-generic transition. Should eventually
128
// become a GIOPOutputObject.
129
protected Object JavaDoc outputObject;
130
131     protected boolean sentFullMessage = false;
132 }
133
134
Popular Tags