~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/messaging/interfaces.py

  • Committer: Steve Kowalik
  • Date: 2011-08-07 04:05:52 UTC
  • mto: This revision was merged to the branch mainline in revision 13626.
  • Revision ID: stevenk@ubuntu.com-20110807040552-mwnxo0flmhvl35e8
Correct the notification based on review comments, and remove request{,ed}
from the function names, switching to create{,d}.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
__metaclass__ = type
7
7
__all__ = [
 
8
    'EmptyQueueException',
 
9
    'IMessageProducer',
8
10
    'IMessageConsumer',
9
 
    'IMessageProducer',
10
 
    'IMessageSession',
11
 
    'MessagingException',
12
 
    'MessagingUnavailable',
13
 
    'QueueEmpty',
14
 
    'QueueNotFound',
15
11
    ]
16
12
 
17
13
 
18
14
from zope.interface import Interface
19
 
from zope.schema import Bool
20
 
 
21
 
 
22
 
class MessagingException(Exception):
23
 
    """Failure in messaging."""
24
 
 
25
 
 
26
 
class MessagingUnavailable(MessagingException):
27
 
    """Messaging systems are not available."""
28
 
 
29
 
 
30
 
class QueueNotFound(MessagingException):
31
 
    """Raised if the queue was not found."""
32
 
 
33
 
 
34
 
class QueueEmpty(MessagingException):
 
15
 
 
16
 
 
17
class EmptyQueueException(Exception):
35
18
    """Raised if there are no queued messages on a non-blocking read."""
36
 
 
37
 
 
38
 
class IMessageSession(Interface):
39
 
 
40
 
    is_connected = Bool(
41
 
        u"Whether the session is connected to the messaging system.")
42
 
 
43
 
    def connect():
44
 
        """Connect to the messaging system.
45
 
 
46
 
        If the session is already connected this should be a no-op.
47
 
        """
48
 
 
49
 
    def disconnect():
50
 
        """Disconnect from the messaging system.
51
 
 
52
 
        If the session is already disconnected this should be a no-op.
53
 
        """
54
 
 
55
 
    def flush():
56
 
        """Run deferred tasks."""
57
 
 
58
 
    def finish():
59
 
        """Flush the session and reset."""
60
 
 
61
 
    def reset():
62
 
        """Reset the session."""
63
 
 
64
 
    def defer(func, *args, **kwargs):
65
 
        """Schedule something to happen when this session is finished."""
66
 
 
67
 
    def getProducer(name):
68
 
        """Get a `IMessageProducer` associated with this session."""
69
 
 
70
 
    def getConsumer(name):
71
 
        """Get a `IMessageConsumer` associated with this session."""
 
19
    pass
72
20
 
73
21
 
74
22
class IMessageConsumer(Interface):
75
 
 
76
23
    def receive(blocking=True):
77
24
        """Receive data from the queue.
78
25
 
79
 
        :raises EmptyQueue: If non-blocking and the queue is empty.
 
26
        :raises EmptyQueueException: If non-blocking and the queue is empty.
80
27
        """
81
28
 
 
29
    def close():
 
30
        """Cleanup nicely."""
 
31
 
82
32
 
83
33
class IMessageProducer(Interface):
84
34
 
85
35
    def send(data):
86
36
        """Serialize `data` into JSON and send it to the queue on commit."""
87
37
 
88
 
    def sendNow(data):
 
38
    def send_now(data):
89
39
        """Serialize `data` into JSON and send it to the queue immediately."""
90
40
 
 
41
    def close():
 
42
        """Cleanup nicely."""
 
43
 
91
44
    def associateConsumer(consumer):
92
 
        """Make the consumer receive messages from this producer on commit.
93
 
 
94
 
        :param consumer: An `IMessageConsumer`
95
 
        """
96
 
 
97
 
    def associateConsumerNow(consumer):
98
45
        """Make the consumer receive messages from this producer.
99
46
 
100
47
        :param consumer: An `IMessageConsumer`
101
48
        """
 
49
 
 
50
    def disassociateConsumer(consumer):
 
51
        """Make the consumer stop receiving messages from this producer.
 
52
 
 
53
        :param consumer: An `IMessageConsumer`
 
54
        """