You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by Alan Conway <ac...@redhat.com> on 2009/10/26 14:07:54 UTC
Threading in the new API.
Here's a propsoal for threading in the new API. It is fully decoupled from the
rest of the API and supports thread pools and select/poll integration.
/** A group of sessions that can be dispatched by a common set of threads. */
class SessionDispatcher {
void add(Session);
void remove(Session);
class InterruptedException ...;
/**
* Dispatch messages to message listeners on all session in the group.
* Thread safe: dispatch can be called concurrently by multiple threads,
* message listeners on the same session will be dispatched sequentially.
*
*@param timeout Dispatch for up to the timeout.
*@throws InterruptedException if dispatching is interrupted.
**/
bool dispatch(Duration timeout);
/**
* Throw InterruptedException to all threads in dispatch()
*/
bool interrupt();
// Unix only, windows would return a WaitableObject or somesuch.
/**
* Returned fd will become readable when there is work to be dispatched.
*/
int getFd();
};
Now you can trivialy create a thread pool to service a group of sessions:
- create a SessionsDispatcher, add your sessions to it.
- start N threads calling SessionsDispatcher::dispatch(INFINITE).
- when you want to stop, call SessionsDispatcher::interrupt() and join your
threads.
For select/poll integration:
- add SessionsDispatcher::getFd() to your select set.
- When it becomes readable do SessionDispatcher::dispatch(0)
Thoughts?
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org