qpid-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Conway <acon...@redhat.com>
Subject C++ sync/async client API (was Re: sync needed in fanout example?)
Date Fri, 23 May 2008 14:59:23 GMT
Change of plan, requesting feedback:

MOTIVATION: as per Andrews comment on the bugzilla, sync and async
versions of a command should have _different return values_. A sync
command should return void or a result object.  An async command must
return a Future object (Completion or TypedResult) that allows the
caller to wait for the command to complete. The current API returns
futures regardless, which makes the sync API needlessly clumsy.

The follow proposal is
  - just as conveneient as an optional async parameter for bot mostly-sync and 
mostly-async users.
  - requires no more example changes than an async param.
  - sync API has normal C++ return values, not Futures.
  - slightly asymmetric (favouring sync), hard to use async commands by accident.

// Summary of API:

class Session {
   void executionSync();
   MessageAcquireResult messageAcquire(const SequenceSet& transfers=SequenceSet());
   // ... sync ops.

   AsyncSession& async;

class AsyncSession {
   Completion executionSync();
   TypedResult<MessageAcquireResult> messageAcquire(const SequenceSet& 

   Session& sync;

// === Example, mostly sync:

Session s ...;
ExchangeQueryResult ex = s.exchangeQuery(...);
for (lots of messages) {
// Now we know all messages are sent.

// === Example mostly async:

Session s ...;
AsyncSession as = s.async;
Completion bind = as.bind(); // allow waiting for specific command
TypedResult<ExchangeQueryResult> ex = as.exchangeQuery(...);
bind.wait(); // Wait for bind command
ExchangeQueryResult ex = ex.get(); // Waits for query to return

View raw message