annotate idavoll/backend.py @ 161:d0dfc01f7638

Bring NEWS in line with previous commit.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 06 Sep 2006 12:43:10 +0000
parents 6fe78048baf9
children ef22e4150caa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 153
diff changeset
1 # Copyright (c) 2003-2006 Ralph Meijer
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 153
diff changeset
2 # See LICENSE for details.
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 153
diff changeset
3
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
4 from zope.interface import Interface
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
5 import storage
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
6
24
4f3bbefc6fad Moved memory backend to its own file.
Ralph Meijer <ralphm@ik.nu>
parents: 23
diff changeset
7 class Error(Exception):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
8 msg = ''
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
10 def __str__(self):
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
11 return self.msg
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
12
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
13 class Forbidden(Error):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
14 pass
20
eddea65d1032 Added two exceptions: NoInstantNodes and NodeExists.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
15
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
16 class ItemForbidden(Error):
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
17 pass
15
46cd13c68ac0 Redone memory storage of nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 5
diff changeset
18
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
19 class ItemRequired(Error):
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
20 pass
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
21
24
4f3bbefc6fad Moved memory backend to its own file.
Ralph Meijer <ralphm@ik.nu>
parents: 23
diff changeset
22 class NoInstantNodes(Error):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
23 pass
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 20
diff changeset
24
34
b65b7ea5c992 Remove nonsense message.
Ralph Meijer <ralphm@ik.nu>
parents: 29
diff changeset
25 class NotSubscribed(Error):
b65b7ea5c992 Remove nonsense message.
Ralph Meijer <ralphm@ik.nu>
parents: 29
diff changeset
26 pass
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
27
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
28 class InvalidConfigurationOption(Error):
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
29 msg = 'Invalid configuration option'
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
30
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
31 class InvalidConfigurationValue(Error):
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
32 msg = 'Bad configuration value'
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
33
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
34 class NodeNotPersistent(Error):
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
35 pass
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
36
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
37 class NoRootNode(Error):
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
38 pass
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
39
106
dc36882d2620 Also move from twisted.python.components to zope.interface.Interface
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
40 class IBackendService(Interface):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
41 """ Interface to a backend service of a pubsub service. """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
42
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
43 def __init__(storage):
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
44 """
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
45 @param storage: L{storage} object.
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
46 """
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
47
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
48 def supports_publisher_affiliation(self):
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
49 """ Reports if the backend supports the publisher affiliation.
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
50
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
51 @rtype: C{bool}
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
52 """
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
53
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
54 def supports_outcast_affiliation(self):
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
55 """ Reports if the backend supports the publisher affiliation.
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
56
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
57 @rtype: C{bool}
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
58 """
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
59
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
60 def supports_persistent_items(self):
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
61 """ Reports if the backend supports persistent items.
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
62
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
63 @rtype: C{bool}
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
64 """
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
65
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
66 def get_node_type(node_id):
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
67 """ Return type of a node.
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
68
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
69 @return: a deferred that returns either 'leaf' or 'collection'
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
70 """
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
71
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
72 def get_nodes(self):
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
73 """ Returns list of all nodes.
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
74
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
75 @return: a deferred that returns a C{list} of node ids.
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
76 """
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
77
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
78 def get_node_meta_data(node_id):
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
79 """ Return meta data for a node.
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
80
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
81 @return: a deferred that returns a C{list} of C{dict}s with the
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
82 metadata.
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
83 """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
84
106
dc36882d2620 Also move from twisted.python.components to zope.interface.Interface
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
85 class INodeCreationService(Interface):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
86 """ A service for creating nodes """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
87
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
88 def create_node(node_id, requestor):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
89 """ Create a node.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
90
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
91 @return: a deferred that fires when the node has been created.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
92 """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
93
106
dc36882d2620 Also move from twisted.python.components to zope.interface.Interface
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
94 class INodeDeletionService(Interface):
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
95 """ A service for deleting nodes. """
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
96
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
97 def register_pre_delete(pre_delete_fn):
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
98 """ Register a callback that is called just before a node deletion.
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
99
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
100 The function C{pre_deleted_fn} is added to a list of functions
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
101 to be called just before deletion of a node. The callback
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
102 C{pre_delete_fn} is called with the C{node_id} that is about to be
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
103 deleted and should return a deferred that returns a list of deferreds
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
104 that are to be fired after deletion. The backend collects the lists
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
105 from all these callbacks before actually deleting the node in question.
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
106 After deletion all collected deferreds are fired to do post-processing.
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
107
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
108 The idea is that you want to be able to collect data from the
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
109 node before deleting it, for example to get a list of subscribers
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
110 that have to be notified after the node has been deleted. To do this,
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
111 C{pre_delete_fn} fetches the subscriber list and passes this
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
112 list to a callback attached to a deferred that it sets up. This
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
113 deferred is returned in the list of deferreds.
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
114 """
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
115
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
116 def get_subscribers(node_id):
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
117 """ Get node subscriber list.
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
118
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
119 @return: a deferred that fires with the list of subscribers.
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
120 """
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
121
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
122 def delete_node(node_id, requestor):
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
123 """ Delete a node.
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
124
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
125 @return: a deferred that fires when the node has been deleted.
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
126 """
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
127
106
dc36882d2620 Also move from twisted.python.components to zope.interface.Interface
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
128 class IPublishService(Interface):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
129 """ A service for publishing items to a node. """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
130
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
131 def publish(node_id, items, requestor):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
132 """ Publish items to a pubsub node.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
133
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
134 @return: a deferred that fires when the items have been published.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
135 """
106
dc36882d2620 Also move from twisted.python.components to zope.interface.Interface
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
136 class INotificationService(Interface):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
137 """ A service for notification of published items. """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
138
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
139 def register_notifier(observerfn, *args, **kwargs):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
140 """ Register callback which is called for notification. """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
141
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
142 def get_notification_list(node_id, items):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
143 pass
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
144
106
dc36882d2620 Also move from twisted.python.components to zope.interface.Interface
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
145 class ISubscriptionService(Interface):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
146 """ A service for managing subscriptions. """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
147
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
148 def subscribe(node_id, subscriber, requestor):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
149 """ Request the subscription of an entity to a pubsub node.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
150
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
151 Depending on the node's configuration and possible business rules, the
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
152 C{subscriber} is added to the list of subscriptions of the node with id
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
153 C{node_id}. The C{subscriber} might be different from the C{requestor},
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
154 and if the C{requestor} is not allowed to subscribe this entity an
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
155 exception should be raised.
59
0fa161c00ed9 Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents: 53
diff changeset
156
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
157 @return: a deferred that returns the subscription state
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
158 """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
159
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
160 def unsubscribe(node_id, subscriber, requestor):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
161 """ Cancel the subscription of an entity to a pubsub node.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
162
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
163 The subscription of C{subscriber} is removed from the list of
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
164 subscriptions of the node with id C{node_id}. If the C{requestor}
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
165 is not allowed to unsubscribe C{subscriber}, an an exception should
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
166 be raised.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
167
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
168 @return: a deferred that fires when unsubscription is complete.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
169 """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
170
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
171 def get_subscriptions(entity):
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
172 """ Report the list of current subscriptions with this pubsub service.
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
173
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
174 Report the list of the current subscriptions with all nodes within this
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
175 pubsub service, for the C{entity}.
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
176
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
177 @return: a deferred that returns the list of all current subscriptions
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
178 as tuples C{(node_id, subscriber, subscription)}.
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
179 """
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
180
106
dc36882d2620 Also move from twisted.python.components to zope.interface.Interface
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
181 class IAffiliationsService(Interface):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
182 """ A service for retrieving the affiliations with this pubsub service. """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
183
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
184 def get_affiliations(entity):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
185 """ Report the list of current affiliations with this pubsub service.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
186
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
187 Report the list of the current affiliations with all nodes within this
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
188 pubsub service, for the C{entity}.
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
189
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
190 @return: a deferred that returns the list of all current affiliations
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
191 as tuples C{(node_id, affiliation)}.
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
192 """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
193
106
dc36882d2620 Also move from twisted.python.components to zope.interface.Interface
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
194 class IRetractionService(Interface):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
195 """ A service for retracting published items """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
196
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
197 def retract_item(node_id, item_id, requestor):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
198 """ Removes item in node from persistent storage """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
199
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
200 def purge_node(node_id, requestor):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
201 """ Removes all items in node from persistent storage """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
202
106
dc36882d2620 Also move from twisted.python.components to zope.interface.Interface
Ralph Meijer <ralphm@ik.nu>
parents: 105
diff changeset
203 class IItemRetrievalService(Interface):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
204 """ A service for retrieving previously published items. """
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
205
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
206 def get_items(node_id, requestor, max_items=None, item_ids=[]):
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
207 """ Retrieve items from persistent storage
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
208
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
209 If C{max_items} is given, return the C{max_items} last published
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
210 items, else if C{item_ids} is not empty, return the items requested.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
211 If neither is given, return all items.
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
212
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
213 @return: a deferred that returns the requested items
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
214 """