[ 
https://issues.apache.org/jira/browse/QPID-2451?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12847066#comment-12847066
 ] 

Alan Conway edited comment on QPID-2451 at 5/4/11 3:01 PM:
-----------------------------------------------------------

An alternative API proposal. This is slightly more low level but still should 
be easy to use, and it provides greater flexibility.  This doesn't directly 
support MessageListeners, but does support a thread pool polling a set of 
sessions and dispatching messages. A MessageListener solution like the one 
above can be implemented in terms of a SessionPoller.

Currently there is only one event type to poll for - session has messages. The 
interface reserves a set of flags to allow us to add support for multiple event 
types in a binary compatible way.
{noformat}
namespace qpid {
namespace messaging {

class Session;

struct PollerStopped : public Exception {
    QPID_CLIENT_EXTERN PollerStopped(const std::string&);
};

/**
 * Poll a group of sessions waiting for messages.
 *
 * Thread safe: can be used to implement a thread group dispatching a
 * set of sessions by starting multiple threads each calling wait() in
 * a loop.
 */
class SessionPoller {
  public:
    /**
     * Add a session for polling. A session may only be in one poller
     * at a time.
     *
     *@param session Session to be added.
     *@param flags Ignored, reserved for future use.
     *@exception PollerStopped The poller is stopped.
     */
    QPID_CLIENT_EXTERN void add(const Session& session, int flags=0);

    /** Remove a session from the poller. */
    QPID_CLIENT_EXTERN void remove(const Session&);
    
    /**
     * Wait up to timeout for a session with messages. The returned
     * session is automatically removed from the poller, call add() to
     * put it back.
     * 
     *@param session Out paramemter, set to the session.
     *@param timeout Maximum time to wait for a session before returning.
     *@return True if session has been set, false if the call timed out.
     *@exception PollerStopped The poller was stopped. 
     */
    QPID_CLIENT_EXTERN bool wait(Session& session, Duration 
timeout=INFINITE_DURATION);

    /**
     * Stop the poller. Threads blocked in wait() will be thrown PollerStopped.
     * Once stopped a poller cannot be re-started.
     */
    QPID_CLIENT_EXTERN void stop();
};

}} // qpid::messaging
#endif  /*!QPID_MESSAGING_SESSIONPOLLER_H*/
{noformat}


      was (Author: aconway):
    An alternative API proposal. This is slightly more low level but still 
should be easy to use, and it provides greater flexibility.  This doesn't 
directly support MessageListeners, but does support a thread pool polling a set 
of sessions and dispatching messages. A MessageListener solution like the one 
above can be implemented in terms of a SessionPoller.

Currently there is only one event type to poll for - session has messages. The 
interface reserves a set of flags to allow us to add support for multiple event 
types in a binary compatible way.

namespace qpid {
namespace messaging {

class Session;

struct PollerStopped : public Exception {
    QPID_CLIENT_EXTERN PollerStopped(const std::string&);
};

/**
 * Poll a group of sessions waiting for messages.
 *
 * Thread safe: can be used to implement a thread group dispatching a
 * set of sessions by starting multiple threads each calling wait() in
 * a loop.
 */
class SessionPoller {
  public:
    /**
     * Add a session for polling. A session may only be in one poller
     * at a time.
     *
     *@param session Session to be added.
     *@param flags Ignored, reserved for future use.
     *@exception PollerStopped The poller is stopped.
     */
    QPID_CLIENT_EXTERN void add(const Session& session, int flags=0);

    /** Remove a session from the poller. */
    QPID_CLIENT_EXTERN void remove(const Session&);
    
    /**
     * Wait up to timeout for a session with messages. The returned
     * session is automatically removed from the poller, call add() to
     * put it back.
     * 
     *@param session Out paramemter, set to the session.
     *@param timeout Maximum time to wait for a session before returning.
     *@return True if session has been set, false if the call timed out.
     *@exception PollerStopped The poller was stopped. 
     */
    QPID_CLIENT_EXTERN bool wait(Session& session, Duration 
timeout=INFINITE_DURATION);

    /**
     * Stop the poller. Threads blocked in wait() will be thrown PollerStopped.
     * Once stopped a poller cannot be re-started.
     */
    QPID_CLIENT_EXTERN void stop();
};

}} // qpid::messaging
#endif  /*!QPID_MESSAGING_SESSIONPOLLER_H*/

  
> Multi-threaded dispatch support for the new API.
> ------------------------------------------------
>
>                 Key: QPID-2451
>                 URL: https://issues.apache.org/jira/browse/QPID-2451
>             Project: Qpid
>          Issue Type: New Feature
>          Components: C++ Client
>            Reporter: Alan Conway
>            Assignee: Alan Conway
>            Priority: Minor
>
> The old C++ client API allows the use to register an object derived from  
> MessageListener as a callback to receive messages from the subscriptions 
> associated with a session. The user can start a thread for each session to 
> dispatch callbacks.
> We need a callback API for the new messaging API. The new API should allow 
> the user to create a thread pool to dispatch to any number of sessions rather 
> than requiring a thread per session. Note the pool model does also support 
> thread-per-session by creating a pool of size 1 for each session.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to