summaryrefslogtreecommitdiff
path: root/documentation/content/xdocs/Qpid Design - Framing.html
blob: 41a3250f131423c3bb95208e6f14395bfb6505d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<html>
    <head>
        <title>Apache Qpid : Qpid Design - Framing</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">	    
    </head>

    <body>
	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
		    <tr>
			    <td valign="top" class="pagebody">
				    <div class="pageheader">
					    <span class="pagetitle">
                            Apache Qpid : Qpid Design - Framing
                                                    </span>
				    </div>
				    <div class="pagesubheading">
					    This page last changed on Oct 19, 2006 by <font color="#0050B2">rgreig</font>.
				    </div>

				    <h3><a name="QpidDesign-Framing-FrameClasses"></a>Frame Classes</h3>

<p>The framing definition in the protocol specification maps quite nicely to an object-oriented representation. The class diagram is shown below:</p>

<p><img src="Qpid Design - Framing_attachments/FramingClassDiagram.gif" align="absmiddle" border="0" /></p>

<p>The <tt>AMQDataBlock</tt> at the root of the hierarchy defines a <tt>writePayload</tt> method that subclasses implement in order to be able to transform themselves into bytes. This is called by the encoder, documented below. The decoding (from bytes into objects) is slightly more complex since it involves factories for the instantiation of the correct objects (again documented below).</p>

<p>An <tt>AMQFrame</tt> is the basic unit transmitted over the network, and contains a body which is the real payload. There are numerous method frames, which are subclasses of <tt>AMQMethodBody</tt>. The method body subclasses are all code generated using XSLT from the protocol specification. The ContentHeaderBody can support different types of content properties or metadata (examples being file or stream in addition to <em>basic</em> which is standard JMS-style messaging).</p>

<p><tt>ContentBody</tt> is a lightweight wrapper for message data.</p>

<h3><a name="QpidDesign-Framing-Encoding"></a>Encoding</h3>

<p>Encoding is a straightforward process. The <tt>AMQDataBlock</tt> class has only two method: <tt>getSize()</tt> and <tt>writePayloadToBuffer(ByteBuffer)</tt>. The encoder simply needs to ask the data block its size, allocate a buffer of that size, then ask the data block to write itself into the buffer.</p>

<h3><a name="QpidDesign-Framing-Decoding"></a>Decoding</h3>

<p>The classes involved in decoding are illustrated in this UML class diagram:</p>

<p><img src="Qpid Design - Framing_attachments/DecodingClasses.gif" align="absmiddle" border="0" /></p>

<p>The <tt>AMQDataBlockDecoder</tt> has only two methods: <tt>decodable()</tt> in which it attempts to read enough information from the supplied buffer to determine whether it has all the data and whether it appears to represent a known data block. If it needs more data, it return false. If the frame appears to be invalid it throws an exception.</p>

<p>The decoder stores the factories for the known frame types in a hash table, keyed on type. Assuming the <tt>decodable()</tt> method return true, the decoder constructs an <tt>AMQFrame</tt>, looks up the body factory based on the body type read from the buffer and calls <tt>populateFromBuffer</tt> on the frame, passing in the factory. The result of that call is either a fully populated frame or an exception being thrown if data is invalid or inconsistent.</p>

<p>The <tt>MethodBodyDecoderRegistry</tt> is generated from the ASL version of the protocol specification. (ASL is simply an XML format for describing the protocol). Each method is registered by protocol class and protocol method and when looked up by the <tt>AMQMethodBodyFactory</tt> an instance of the appropriate method body is returned. The generated code for the methods handles the reading and writing of the bytes to and from ByteBuffers as well as calculation of the size of the populated method bodies.</p>

				    					    <br/>
                        <div class="tabletitle">
                            <a name="attachments">Attachments:</a>
                        </div>

                        <div class="greybox" align="left">
                                                            <img src="icons/bullet_blue.gif" height="8" width="8" alt=""/>
                                <a href="Qpid Design - Framing_attachments/FramingClassDiagram.gif">FramingClassDiagram.gif</a> (image/gif)
                                <br/>
                                                            <img src="icons/bullet_blue.gif" height="8" width="8" alt=""/>
                                <a href="Qpid Design - Framing_attachments/DecodingClasses.gif">DecodingClasses.gif</a> (image/gif)
                                <br/>
                                                    </div>
				    
                    			    </td>
		    </tr>
	    </table>
	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td>
			</tr>
		    <tr>
			    <td align="center"><font color="grey">Document generated by Confluence on Apr 22, 2008 02:47</font></td>
		    </tr>
	    </table>
    </body>
</html>