qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Qpid > AMQP 1.0 JMS Client Requirements and Design
Date Wed, 05 Jun 2013 16:25:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/21/_/styles/combined.css?spaceKey=qpid&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/qpid/AMQP+1.0+JMS+Client+Requirements+and+Design">AMQP
1.0 JMS Client Requirements and Design</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~phil@philharveyonline.com">Phil
Harvey</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >*** Errors in collaboration logic
cause integration tests to fail. <br>** Most (if not all) of our integration tests should
run in-process. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">**
The official JMS 2 TCK tests will also be run against the client. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h5. Integration tests <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>This page describes the requirements and initial design of the new Qpid JMS
Client that supports AMQP 1.0 (simply referred to as the "Qpid JMS Client" below).</p>

<div>
<ul>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Requirements'>Requirements</a></li>
<ul>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Functionalrequirements'>Functional
requirements</a></li>
<ul>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Phase0'>Phase 0</a></li>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Phase1'>Phase 1</a></li>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Phase2'>Phase 2</a></li>
</ul>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Nonfunctionalrequirements'>Non-functional
requirements</a></li>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Outofscope'>Out of scope</a></li>
</ul>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Design'>Design</a></li>
<ul>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Layers'>Layers</a></li>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-PublicAPI'>Public API</a></li>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Locking'>Locking</a></li>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-I%2FOlayer'>I/O layer</a></li>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Logging'>Logging</a></li>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Testingstrategy'>Testing
strategy</a></li>
<ul>
    <li><a href='#AMQP1.0JMSClientRequirementsandDesign-Integrationtests'>Integration
tests</a></li>
</ul>
</ul>
</ul></div>

<h3><a name="AMQP1.0JMSClientRequirementsandDesign-Requirements"></a>Requirements</h3>

<h4><a name="AMQP1.0JMSClientRequirementsandDesign-Functionalrequirements"></a>Functional
requirements</h4>

<ul>
	<li>AMQP 1.0</li>
	<li>JMS 2
	<ul>
		<li>JMS 1.1 support will be added in the future if demand requires.</li>
	</ul>
	</li>
	<li>ONGOING: Contribute to the JMS mapping work within the OASIS AMQP Binding &amp;
Mappings TC</li>
</ul>


<p>The following sub-sections allocate the functional requirements to several sequential
project phases. </p>

<h5><a name="AMQP1.0JMSClientRequirementsandDesign-Phase0"></a>Phase 0</h5>

<p>This is the initial set-up of the basics. </p>

<ul>
	<li>Open and close a connection. Includes writing automated tests.</li>
</ul>


<p>This will implicitly require work on:</p>

<ul>
	<li>Project folder structure</li>
	<li>Build tool configuration</li>
	<li>CI server job</li>
	<li>Automated HTML documentation generation.</li>
</ul>


<h5><a name="AMQP1.0JMSClientRequirementsandDesign-Phase1"></a>Phase 1</h5>

<ul>
	<li>Synchronous, Auto-Ack style 'simple client'</li>
	<li>Main operations on JMS Connections, Sessions, Consumers, Producers, Queues, Message
(Text?).
	<ul>
		<li>Include closing/stopping/deleting where applicable.</li>
	</ul>
	</li>
	<li>Configuration
	<ul>
		<li>Ability to configure settings such as pre-fetch etc
		<ul>
			<li>TODO per connection or per consumer or both? If the latter then not sure how
to pass this setting in (address options?), given that JMS API doesn't offer an obvious way
to do it.</li>
		</ul>
		</li>
		<li>TODO define how JNDI configuration will work</li>
	</ul>
	</li>
	<li>SASL</li>
	<li>Correct handling of non-happy path scenarios, namely:
	<ul>
		<li>Unexpected errors</li>
		<li>Failures that are nevertheless AMQP-compliant, e.g. the Broker spontaneously sends
a Close or End frame.</li>
		<li>Timeouts due to connectivity failure etc. Necessary because of the asynchronous
nature of AMQP.</li>
		<li>Interruption of application-owned threads.</li>
	</ul>
	</li>
</ul>


<h5><a name="AMQP1.0JMSClientRequirementsandDesign-Phase2"></a>Phase 2</h5>

<ul>
	<li>SSL</li>
	<li>Transactions</li>
	<li>Client Ack</li>
	<li>Selectors</li>
	<li>JNDI</li>
	<li>MessageListener.onMessage()</li>
	<li>Durable Subscriptions</li>
	<li>JMS 2.0 features:
	<ul>
		<li>Asynchronous send</li>
		<li>Shared Topic Subscriptions</li>
	</ul>
	</li>
</ul>


<h4><a name="AMQP1.0JMSClientRequirementsandDesign-Nonfunctionalrequirements"></a>Non-functional
requirements</h4>

<ul>
	<li>Logging
	<ul>
		<li>Should play nicely with application logging, e.g. allow the application to plug
in its choice of third party logging framework (which would also be passed through to Proton
if possible).</li>
		<li>Should allow control of logging thresholds for categories including:
		<ul>
			<li>A specific object, e.g. a Connection</li>
			<li>A logical function, e.g. network I/O</li>
		</ul>
		</li>
	</ul>
	</li>
	<li>Initially will only run on Java 1.7 (because some JMS 2 features require Java 1.7).</li>
</ul>




<h4><a name="AMQP1.0JMSClientRequirementsandDesign-Outofscope"></a>Out of
scope</h4>

<ul>
	<li>AMQP 0-x</li>
	<li>ADDR and BURL addressing formats</li>
	<li>Failover. Instead, this will be implemented in the future either entirely below
or entirely above the client code.</li>
	<li>Accepting legacy system properties (unelss they happen to match what we would choose
now).</li>
</ul>



<h3><a name="AMQP1.0JMSClientRequirementsandDesign-Design"></a>Design</h3>

<h4><a name="AMQP1.0JMSClientRequirementsandDesign-Layers"></a>Layers</h4>

<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>+================================+
|
| JMS
|
| Implementations of javax.jms
|
+================================+
               |
               |
              \|/
+================================+
|
| AMQP
|
| Wrappers around Proton's engine
| classes, primarily to add locking
|
+================================+
            |                 |
            |                 |
           \|/                |
+======================+      |
|       Proton         |      |
|                      |      |
| Message |  Engine    |      |
|         |            |      |
+=========+============+      |
                    /|\       |
                     |        |
                     |       \|/
                   +====================
                   |
                   | JMS Driver interface
                   |
                   +=====================
                            /|\
                             |
                        +--------------+
                        |              |
                        |              |
                        |              |
                  +===========+        +==============
                  |                    |
                  |  Socket            |
                  |  driver            | Another driver,
                  |  (might use        | e.g. in-VM
                  |  Proton's Driver)  |
                  |                    |
                  +===========+        +==============
                    |
                    | TCP/IP
                    |
                   \|/
+================================+
|
| Broker
|
+================================+

</pre>
</div></div>

<h4><a name="AMQP1.0JMSClientRequirementsandDesign-PublicAPI"></a>Public
API</h4>

<ul>
	<li>Goals:
	<ul>
		<li>Minimal public API</li>
		<li>Possible to write JMS applications that have a compile-time dependency on the
javax.jms interfaces and not on Qpid-specific classes.</li>
		<li>Minor releases maintain backwards compatibility between minor releases.</li>
	</ul>
	</li>
</ul>


<p>The public API consists of:</p>
<ul>
	<li>The JMS interfaces (probably provided by a third party library such as <a href="http://mvnrepository.com/artifact/geronimo-spec/geronimo-spec-jms"
class="external-link" rel="nofollow">Geronomio Spec</a>).</li>
	<li>The constructor(s) for Qpid's implementation of javax.jms.ConnectionFactory and
its sub-interfaces.</li>
	<li>Qpid's javax.naming.spi.InitialContextFactory implementation.</li>
</ul>


<p><b>Note that the logging output and logging category names also constitute
a public interface</b>.</p>

<p>In the future, the public API may need to be extended or more precisely specified
(e.g. to include details of the mapping between JMS and AMQP when using MapMessage and ObjectMessage
etc).</p>


<h4><a name="AMQP1.0JMSClientRequirementsandDesign-Locking"></a>Locking</h4>

<ul>
	<li>Goals:
	<ul>
		<li>Minimise the number of locks</li>
		<li>Define the correct locking order</li>
	</ul>
	</li>
</ul>


<p>Threads fall into two categories:</p>
<ol>
	<li>Application threads using the JMS API. Only use the top half of the Proton API.</li>
	<li>One or more driver threads for I/O. Managed by the JMS client. Only use the bottom
half of the Proton API.</li>
</ol>


<p>For a given connection:</p>

<ol>
	<li>State shared by multiple application threads (namely the state of the objects in
the JMS layer) is guarded by the JMS ConnectionLock.</li>
	<li>State shared by the application and driver threads is guarded by the AmqpConnection
lock. This shared state is:
	<ol>
		<li>A small number of flags the application and driver threads use to indicate to
each other that "something has changed".</li>
		<li>The Proton objects. This sharing occurs inside Proton but needs to be guarded
by the JMS client because Proton itself is not thread-safe.</li>
	</ol>
	</li>
</ol>


<p>Synchronous operations must follow the locking scheme indicated by the following
pseudo-code:</p>

<ul>
	<li>jmsObject.doStuff
	<ul>
		<li>obtain <b>ConnectionLock</b></li>
		<li>amqpObject.doAmqpStuff
		<ul>
			<li>obtain <em>amqpConnection lock</em></li>
			<li>protonObject.doProtonStuff</li>
			<li>release <em>amqpConnection lock</em></li>
		</ul>
		</li>
		<li>JmsConnection.stateChanged (event notification, e.g. to wake up the driver so
that I/O occurs)</li>
		<li>release <b>ConnectionLock</b></li>
	</ul>
	</li>
</ul>


<p>Where operations need to wait for a "remote" operation to complete, they must follow
the scheme indicated by the following pseudo-code:</p>

<ul>
	<li>jmsObject.doRemoteStuff
	<ul>
		<li>obtain <b>ConnectionLock</b></li>
		<li>...</li>
		<li>JmsConnection.waitUntil(predicateObject)
		<ul>
			<li>obtain <em>amqConnection lock</em></li>
			<li>amqConnection.wait() (the Driver thread calls amqConnection.notifyAll())</li>
			<li>...</li>
			<li>evaluate predicate</li>
			<li>...</li>
			<li>release <em>amqConnection lock</em></li>
		</ul>
		</li>
		<li>release <b>ConnectionLock</b></li>
	</ul>
	</li>
</ul>


<p>This ensures that when the predicate object is invoked the thread will already possess
both the JmsConnection lock and the AmqpConnection lock.</p>

<h4><a name="AMQP1.0JMSClientRequirementsandDesign-I%2FOlayer"></a>I/O layer</h4>

<ul>
	<li>Goals:
	<ul>
		<li>Encapsulate any 3rd party library as much as possible</li>
		<li>Allow transport to be easily swapped out to allow, for example:
		<ul>
			<li>in-VM operation</li>
			<li>WebSockets</li>
			<li>SCTP</li>
			<li>Accepting Connection. Useful if the client is behind a firewall that forbids
outbound connections.</li>
		</ul>
		</li>
	</ul>
	</li>
</ul>


<p>TODO - design I/O<br/>
Use Netty?</p>

<h4><a name="AMQP1.0JMSClientRequirementsandDesign-Logging"></a>Logging</h4>

<ul>
	<li>Goals:
	<ul>
		<li>Consistent use of logging levels</li>
		<li>TODO more...</li>
	</ul>
	</li>
</ul>


<p>TODO</p>

<h4><a name="AMQP1.0JMSClientRequirementsandDesign-Testingstrategy"></a>Testing
strategy</h4>

<ul>
	<li>Goals:
	<ul>
		<li>Running all the tests should be fast (it should be exceptional for a test to take
more than five seconds).</li>
		<li>Tests operate at the correct level. Specifically:
		<ul>
			<li>Simple logic bugs cause unit tests to fail.</li>
			<li>Errors in collaboration logic cause integration tests to fail.</li>
		</ul>
		</li>
		<li>Most (if not all) of our integration tests should run in-process.</li>
		<li>The official JMS 2 TCK tests will also be run against the client.</li>
	</ul>
	</li>
</ul>


<h5><a name="AMQP1.0JMSClientRequirementsandDesign-Integrationtests"></a>Integration
tests</h5>

<p>For each test, our main choice is which layer to designate as the boundary for our
tests. Everything "below" this boundary will be replaced with a mock implementation ("mock"
is defined in a broad sense - it does not assume a imply the use of a mocking framework).</p>

<p>Our options are listed below in increasing system boundary extent. As the extent
increases, the usual trade-offs apply:</p>
<ul>
	<li>More layers of the real JMS client will be exercised, thereby increasing the confidence
that our tests give us.</li>
	<li>We get less control over the tests, both in terms of their inputs and the assertions
we can test.</li>
	<li>Tests become harder to debug.</li>
</ul>


<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Layer to mock </th>
<th class='confluenceTh'> Comments </th>
</tr>
<tr>
<td class='confluenceTd'> <b>Proton</b> </td>
<td class='confluenceTd'> <b>Simple,</b> in that our mock layer can be implemented
in terms of Proton model objects without worrying about streams of bytes. This should also
make it easier to debug tests.<br class="atl-forced-newline" />
 <br class="atl-forced-newline" />
<b>Will not catch Proton bugs</b>. <br class="atl-forced-newline" />
  <br class="atl-forced-newline" />
 <b>Hard to ensure that our mock Proton behaves consistently</b> with respect
to the real thing.<br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <b>Proton encoder and decoder</b>. <br class="atl-forced-newline"
/>
For simplicity, the mock encoder and decoder would produce and consume FrameBody objects respectively,
rather than bytes.<br class="atl-forced-newline" />
 <br class="atl-forced-newline" />
On a test-by-test basis, the mock encoder could be configured to apply assertions to allow
us to check that a particular JMS operation caused the right frame(s) to be generated. Similarly,
the mock decoder could generate <em>FrameBody</em>s to simulate the Broker's behaviour.&nbsp;
This would allow us to replace Proton's Transport layer with a no-op implementation.<br
class="atl-forced-newline" />
 <br class="atl-forced-newline" />
Alternatively, the the assertions and mock behaviour (for output and input respectively) could
be applied to the Transport rather than the encoder/decoder.<br class="atl-forced-newline"
/> </td>
<td class='confluenceTd'> Gives us <b>full control</b>, i.e. we can check
exactly which frames were produced.&nbsp; Can also control which frames are sent to the
client to a greater extent than if a Proton peer was generating them.&nbsp; This doesn't
just apply to simulating error scenarios - some valid sequences of happy-path frames are impossible
to generate using Proton.<br class="atl-forced-newline" />
 <br class="atl-forced-newline" />
However, writing tests in terms of frames is <b>less intuitive</b> than expressing
them in terms of Proton model objects.&nbsp; The former is a sequence of state transitions
whereas the latter represents the actual state of the system.<br class="atl-forced-newline"
/>
 <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <b>The broker (in-process)</b>. <br class="atl-forced-newline"
/>
We would modify Driver to produce output in-process rather than requiring a Socket. <br
class="atl-forced-newline" />
The bytes would be exchanged with a mock Broker which would be a thin wrapper round Proton.&nbsp;
The mock Broker would use test-specific logic to: <br class="atl-forced-newline" />
&#45; Assert the expected state of its local Proton model objects <br class="atl-forced-newline"
/>
&#45; Simulate a real Broker's output <br class="atl-forced-newline" />
 <br class="atl-forced-newline" />
Tests using this option would be run against both proton-j and proton-jni. <br class="atl-forced-newline"
/>
<br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> This option should still run acceptably fast despite containing
almost all the layers of the real JMS client.<br class="atl-forced-newline" />
 <br class="atl-forced-newline" />
Cannot simulate all scenarios we want to test, e.g. server redirect, or certain error cases.
<br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> <b>The broker (out-of-process)</b>. <br class="atl-forced-newline"
/>
We would either write a simple broker or use the existing one. <br class="atl-forced-newline"
/> The client test would more closely resemble a conventional application than a JUnit
test. </td>
<td class='confluenceTd'> Useful for testing multi-threaded behaviour </td>
</tr>
</tbody></table>
</div>



<p>We expect all of the above mocking options to be used at some point. <b>Initially
we will favour mocking the broker in-process where possible</b>. This is because:</p>
<ol>
	<li>It is easy to set up, with minimal changes to Proton.</li>
	<li>This is very nearly an end-to-end test, which will give us useful reasssurance
particularly in the early stages of the project.</li>
</ol>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/qpid/AMQP+1.0+JMS+Client+Requirements+and+Design">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=31823684&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/qpid/AMQP+1.0+JMS+Client+Requirements+and+Design?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message