The asynchronous interface to the SDK is a work in progress, and is currently intended to be used by integrators into higher level async wrappers. See the txcouchbase package for an example.
This document largely explains the current internals of how the Couchbase async module works in a lower level. For a higher level overview, see: http://blog.couchbase.com/python-sdk-and-twisted
The Key-Value interface of the async subsystem functions as closely as possible like its synchronous counterpart. The primary difference is that where the synchronous interface would return an instance of a Result or a MultiResult, the asynchronous interface returns an AsyncResult object.
The AsyncResult object contains fields for two callbacks which are invoked when the result is ready. One is the callback field which is called with a Result or MultiResult upon success, and the other is the errback field which is invoked with an exception object upon error.
The semantics of when an exception is passed follows the rules of the quiet parameter just like the synchronous API.
Callback to be invoked with this result
Callback to be invoked with any errors
Create a new Async connection. An async connection is an object which functions like a normal synchronous connection, except that it returns future objects (i.e. AsyncResult objects) instead of Result. These objects are actually MultiResult objects which are empty upon retun. As operations complete, this object becomes populated with the relevant data.
Note that the AsyncResult object must currently have valid callback and errback fields initialized after they are returned from the API methods. If this is not the case then an exception will be raised when the callbacks are about to arrive. This behavior is the primary reason why this interface isn’t public, too :)
Parameters: |
|
---|
Reimplemented from base class. This method does not add additional functionality of the base class` query() method (all the functionality is encapsulated in the view class anyway). However it does require one additional keyword argument
Parameters: | itercls (class) – A class used for instantiating the view object. This should be a subclass of AsyncViewBase. |
---|
Different from the key-value interface, the synchronous view API returns a View object which is itself an iterator which yields results. Because this is a synchronous API, the iterator interface must be replaced with a class interface which must be subclassed by a user.
Initialize a new AsyncViewBase object. This is intended to be subclassed in order to implement the require methods to be invoked on error, data, and row events.
Usage of this class is not as a standalone, but rather as an itercls parameter to the query() method of the connection object.
Called when there are more processed views.
Parameters: | rowiter (iterable) – An iterable which will yield results as defined by the RowProcessor implementation |
---|
This method must be implemented in a subclass
Called when there is a failure with the response data
Parameters: | ex (Exception) – The exception caught. |
---|
This must be implemented in a subclass
The async API is divided into several sections. In order to have an async client which interacts with other async libraries and frameworks, it is necessary to make the Couchbase extension aware of that environment. To this end, the IOPS interface is provided. The IOPS API is entirely separate from the key-value API and should be treated as belonging to a different library. It is simply the extension’s I/O abstraction.
This class represents an Event. This concept should be familiar to the intended audience, who should be familiar with event loops and their terminology. It represents a certain event in the future, which shall be triggered either by something happening or by the passage of time.
When said event takes place, the object should be signalled via the ready() method.
Called when an event is ready
A subclass of Event, this represents a socket. Events applied to this socket are triggered when the socket becomes available for reading or writing.
Called for read events. This is the efficient form of ready(LCB_READ_EVENT)
Called for write events. This is equivalent to ready(LCB_WRITE_EVENT)
Called for rw events. This is equivalent to ready(LCB_READ_EVENT|LCB_WRITE_EVENT)
The IOPS class is intended as an efficient and multiplexing manager of one or more Event objects.
As this represents an interface with methods only, there is no required behavior in the constructor of this object
This method shall perform an action modifying an event.
Parameters: |
|
---|
If the action is to watch the event for readability or writeability, the IOPS implementation shall schedule the underlying event system to call one of the ready_r, ready_w or ready_rw methods (for readbility, writeability or both readability and writability respectively) at such a time when the underlying reactor/event loop implementation has signalled it being so.
Event watchers are non-repeatable. This means that once the event has been delivered, the IOEvent object shall be removed from a watching state. The extension shall call this method again for each time an event is requested.
This method must be implemented
This method shall schedule or unschedule a timer.
Parameters: |
|
---|
This method follows the same semantics as update_event(), except that there is no file.
When the underlying event system shall invoke the timer, the TimerEvent ready method shall be called with 0 as its argument.
Like IOEvents, TimerEvents are non-repeatable.
This method must be implemented
Called by the extension when all scheduled IO events have been submitted. Depending on the I/O model, this method can either drive the event loop until stop_watching() is called, or do nothing.
This method must be implemented
Called by the extension when it no longer needs to wait for events. Its function is to undo anything which was done in the start_watching() method
This method must be implemented
Returns a new instance of IOEvent.
This method is optional, and is useful in case an implementation wishes to utilize its own subclass of IOEvent.
As with most Python subclasses, the user should ensure that the base implementation’s __init__ is called.
Returns a new instance of TimerEvent. Like the io_event_factory(), this is optional
Action indicating the specific event should be added to the event loop’s “watcher” list, and should be have its ready() method called when the IO implementation has detected the specific event is ready
Action indicating that the specific object should not be notified when the IO state changes. This is typically done by removing it from the watcher list
Action to permanently erase any references to this event
IO Flag indicating that this event should be notified on file readbility
IO flag indicating that this event should be notified on file writeability
Equivalent to LCB_READ_EVENT|LCB_WRITE_EVENT