comparison idavoll/backend.py @ 153:753b8432460f

Work towards JEP-0060 1.8 - Remove subscription information from <affiliations/> result. - Add handling of <subscriptions/> entity use case. - Make <subscribe/> return <subscription/> instead of <entity/>. - Move <purge/> and <delete/> to owner namespace. - Don't use 'self' in interfaces.
author Ralph Meijer <ralphm@ik.nu>
date Sat, 06 May 2006 19:47:53 +0000
parents 1c18759d2afb
children 5191ba7c4df8
comparison
equal deleted inserted replaced
152:ea8b4189ae3b 153:753b8432460f
32 msg = 'Bad configuration value' 32 msg = 'Bad configuration value'
33 33
34 class IBackendService(Interface): 34 class IBackendService(Interface):
35 """ Interface to a backend service of a pubsub service. """ 35 """ Interface to a backend service of a pubsub service. """
36 36
37 def __init__(self, storage): 37 def __init__(storage):
38 """ 38 """
39 @param storage: L{storage} object. 39 @param storage: L{storage} object.
40 """ 40 """
41 41
42 def supports_publisher_affiliation(self): 42 def supports_publisher_affiliation(self):
55 """ Reports if the backend supports persistent items. 55 """ Reports if the backend supports persistent items.
56 56
57 @rtype: C{bool} 57 @rtype: C{bool}
58 """ 58 """
59 59
60 def get_node_type(self, node_id): 60 def get_node_type(node_id):
61 """ Return type of a node. 61 """ Return type of a node.
62 62
63 @return: a deferred that returns either 'leaf' or 'collection' 63 @return: a deferred that returns either 'leaf' or 'collection'
64 """ 64 """
65 65
67 """ Returns list of all nodes. 67 """ Returns list of all nodes.
68 68
69 @return: a deferred that returns a C{list} of node ids. 69 @return: a deferred that returns a C{list} of node ids.
70 """ 70 """
71 71
72 def get_node_meta_data(self, node_id): 72 def get_node_meta_data(node_id):
73 """ Return meta data for a node. 73 """ Return meta data for a node.
74 74
75 @return: a deferred that returns a C{list} of C{dict}s with the 75 @return: a deferred that returns a C{list} of C{dict}s with the
76 metadata. 76 metadata.
77 """ 77 """
78 78
79 class INodeCreationService(Interface): 79 class INodeCreationService(Interface):
80 """ A service for creating nodes """ 80 """ A service for creating nodes """
81 81
82 def create_node(self, node_id, requestor): 82 def create_node(node_id, requestor):
83 """ Create a node. 83 """ Create a node.
84 84
85 @return: a deferred that fires when the node has been created. 85 @return: a deferred that fires when the node has been created.
86 """ 86 """
87 87
88 class INodeDeletionService(Interface): 88 class INodeDeletionService(Interface):
89 """ A service for deleting nodes. """ 89 """ A service for deleting nodes. """
90 90
91 def register_pre_delete(self, pre_delete_fn): 91 def register_pre_delete(pre_delete_fn):
92 """ Register a callback that is called just before a node deletion. 92 """ Register a callback that is called just before a node deletion.
93 93
94 The function C{pre_deleted_fn} is added to a list of functions 94 The function C{pre_deleted_fn} is added to a list of functions
95 to be called just before deletion of a node. The callback 95 to be called just before deletion of a node. The callback
96 C{pre_delete_fn} is called with the C{node_id} that is about to be 96 C{pre_delete_fn} is called with the C{node_id} that is about to be
105 C{pre_delete_fn} fetches the subscriber list and passes this 105 C{pre_delete_fn} fetches the subscriber list and passes this
106 list to a callback attached to a deferred that it sets up. This 106 list to a callback attached to a deferred that it sets up. This
107 deferred is returned in the list of deferreds. 107 deferred is returned in the list of deferreds.
108 """ 108 """
109 109
110 def get_subscribers(self, node_id): 110 def get_subscribers(node_id):
111 """ Get node subscriber list. 111 """ Get node subscriber list.
112 112
113 @return: a deferred that fires with the list of subscribers. 113 @return: a deferred that fires with the list of subscribers.
114 """ 114 """
115 115
116 def delete_node(self, node_id, requestor): 116 def delete_node(node_id, requestor):
117 """ Delete a node. 117 """ Delete a node.
118 118
119 @return: a deferred that fires when the node has been deleted. 119 @return: a deferred that fires when the node has been deleted.
120 """ 120 """
121 121
122 class IPublishService(Interface): 122 class IPublishService(Interface):
123 """ A service for publishing items to a node. """ 123 """ A service for publishing items to a node. """
124 124
125 def publish(self, node_id, items, requestor): 125 def publish(node_id, items, requestor):
126 """ Publish items to a pubsub node. 126 """ Publish items to a pubsub node.
127 127
128 @return: a deferred that fires when the items have been published. 128 @return: a deferred that fires when the items have been published.
129 """ 129 """
130 class INotificationService(Interface): 130 class INotificationService(Interface):
131 """ A service for notification of published items. """ 131 """ A service for notification of published items. """
132 132
133 def register_notifier(self, observerfn, *args, **kwargs): 133 def register_notifier(observerfn, *args, **kwargs):
134 """ Register callback which is called for notification. """ 134 """ Register callback which is called for notification. """
135 135
136 def get_notification_list(self, node_id, items): 136 def get_notification_list(node_id, items):
137 pass 137 pass
138 138
139 class ISubscriptionService(Interface): 139 class ISubscriptionService(Interface):
140 """ A service for managing subscriptions. """ 140 """ A service for managing subscriptions. """
141 141
142 def subscribe(self, node_id, subscriber, requestor): 142 def subscribe(node_id, subscriber, requestor):
143 """ Request the subscription of an entity to a pubsub node. 143 """ Request the subscription of an entity to a pubsub node.
144 144
145 Depending on the node's configuration and possible business rules, the 145 Depending on the node's configuration and possible business rules, the
146 C{subscriber} is added to the list of subscriptions of the node with id 146 C{subscriber} is added to the list of subscriptions of the node with id
147 C{node_id}. The C{subscriber} might be different from the C{requestor}, 147 C{node_id}. The C{subscriber} might be different from the C{requestor},
149 exception should be raised. 149 exception should be raised.
150 150
151 @return: a deferred that returns the subscription state 151 @return: a deferred that returns the subscription state
152 """ 152 """
153 153
154 def unsubscribe(self, node_id, subscriber, requestor): 154 def unsubscribe(node_id, subscriber, requestor):
155 """ Cancel the subscription of an entity to a pubsub node. 155 """ Cancel the subscription of an entity to a pubsub node.
156 156
157 The subscription of C{subscriber} is removed from the list of 157 The subscription of C{subscriber} is removed from the list of
158 subscriptions of the node with id C{node_id}. If the C{requestor} 158 subscriptions of the node with id C{node_id}. If the C{requestor}
159 is not allowed to unsubscribe C{subscriber}, an an exception should 159 is not allowed to unsubscribe C{subscriber}, an an exception should
160 be raised. 160 be raised.
161 161
162 @return: a deferred that fires when unsubscription is complete. 162 @return: a deferred that fires when unsubscription is complete.
163 """ 163 """
164 164
165 def get_subscriptions(entity):
166 """ Report the list of current subscriptions with this pubsub service.
167
168 Report the list of the current subscriptions with all nodes within this
169 pubsub service, for the C{entity}.
170
171 @return: a deferred that returns the list of all current subscriptions
172 as tuples C{(node_id, subscriber, subscription)}.
173 """
174
165 class IAffiliationsService(Interface): 175 class IAffiliationsService(Interface):
166 """ A service for retrieving the affiliations with this pubsub service. """ 176 """ A service for retrieving the affiliations with this pubsub service. """
167 177
168 def get_affiliations(self, entity): 178 def get_affiliations(entity):
169 """ Report the list of current affiliations with this pubsub service. 179 """ Report the list of current affiliations with this pubsub service.
170 180
171 Report the list of the current affiliations with all nodes within this 181 Report the list of the current affiliations with all nodes within this
172 pubsub service, along with subscriptions to such nodes, for the 182 pubsub service, for the C{entity}.
173 C{entity}.
174 183
175 @return: a deferred that returns the list of all current affiliations 184 @return: a deferred that returns the list of all current affiliations
176 and subscriptions. 185 as tuples C{(node_id, affiliation)}.
177 """ 186 """
178 187
179 class IRetractionService(Interface): 188 class IRetractionService(Interface):
180 """ A service for retracting published items """ 189 """ A service for retracting published items """
181 190
182 def retract_item(self, node_id, item_id, requestor): 191 def retract_item(node_id, item_id, requestor):
183 """ Removes item in node from persistent storage """ 192 """ Removes item in node from persistent storage """
184 193
185 def purge_node(self, node_id, requestor): 194 def purge_node(node_id, requestor):
186 """ Removes all items in node from persistent storage """ 195 """ Removes all items in node from persistent storage """
187 196
188 class IItemRetrievalService(Interface): 197 class IItemRetrievalService(Interface):
189 """ A service for retrieving previously published items. """ 198 """ A service for retrieving previously published items. """
190 199
191 def get_items(self, node_id, requestor, max_items=None, item_ids=[]): 200 def get_items(node_id, requestor, max_items=None, item_ids=[]):
192 """ Retrieve items from persistent storage 201 """ Retrieve items from persistent storage
193 202
194 If C{max_items} is given, return the C{max_items} last published 203 If C{max_items} is given, return the C{max_items} last published
195 items, else if C{item_ids} is not empty, return the items requested. 204 items, else if C{item_ids} is not empty, return the items requested.
196 If neither is given, return all items. 205 If neither is given, return all items.