comparison idavoll/backend.py @ 44:bc7438476a67

Removed IPersistenceService, this is a feature of the storage facility. Moved implementation of backend services to their own class, matching the interfaces.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 03 Nov 2004 14:03:41 +0000
parents 9685b7e291ef
children 94e4ede2a357
comparison
equal deleted inserted replaced
43:9685b7e291ef 44:bc7438476a67
106 106
107 @return: a deferred that returns the list of all current affiliations 107 @return: a deferred that returns the list of all current affiliations
108 and subscriptions. 108 and subscriptions.
109 """ 109 """
110 110
111 class IPersistenceService(components.Interface):
112 """ A service for persisting published items """
113
114 def store_items(self, node_id, items, publisher):
115 """ Store items for a node, recording the publisher """
116
117 class IRetractionService(components.Interface): 111 class IRetractionService(components.Interface):
118 """ A service for retracting published items """ 112 """ A service for retracting published items """
119 113
120 def retract_item(self, node_id, item_id, requestor): 114 def retract_item(self, node_id, item_id, requestor):
121 """ Removes item in node from persistent storage """ 115 """ Removes item in node from persistent storage """
147 self.storage = storage 141 self.storage = storage
148 142
149 def get_supported_affiliations(self): 143 def get_supported_affiliations(self):
150 return ['none', 'owner', 'outcast', 'publisher'] 144 return ['none', 'owner', 'outcast', 'publisher']
151 145
146 class PublishService(service.Service):
147
148 __implements__ = IPublishService,
149
152 def publish(self, node_id, items, requestor): 150 def publish(self, node_id, items, requestor):
153 d1 = self.storage.get_node_configuration(node_id) 151 d1 = self.parent.storage.get_node_configuration(node_id)
154 d2 = self.storage.get_affiliation(node_id, requestor.full()) 152 d2 = self.parent.storage.get_affiliation(node_id, requestor.full())
155 d = defer.DeferredList([d1, d2], fireOnOneErrback=1) 153 d = defer.DeferredList([d1, d2], fireOnOneErrback=1)
156 d.addErrback(lambda x: x.value[0]) 154 d.addErrback(lambda x: x.value[0])
157 d.addCallback(self._do_publish, node_id, items, requestor) 155 d.addCallback(self._do_publish, node_id, items, requestor)
158 return d 156 return d
159 157
178 for item in items: 176 for item in items:
179 if item["id"] is None: 177 if item["id"] is None:
180 item["id"] = 'random' # FIXME 178 item["id"] = 'random' # FIXME
181 179
182 if persist_items: 180 if persist_items:
183 d = self.store_items(node_id, items, requestor.full()) 181 d = self.parent.storage.store_items(node_id, items,
182 requestor.full())
184 else: 183 else:
185 d = defer.succeed(None) 184 d = defer.succeed(None)
186 185
187 d.addCallback(self._do_notify, node_id, items, deliver_payloads) 186 d.addCallback(self._do_notify, node_id, items, deliver_payloads)
188 187
189 def _do_notify(self, result, node_id, items, deliver_payloads): 188 def _do_notify(self, result, node_id, items, deliver_payloads):
190 if items and not deliver_payloads: 189 if items and not deliver_payloads:
191 for item in items: 190 for item in items:
192 item.children = [] 191 item.children = []
193 192
194 self.dispatch({ 'items': items, 'node_id': node_id }, 193 self.parent.dispatch({ 'items': items, 'node_id': node_id },
195 '//event/pubsub/notify') 194 '//event/pubsub/notify')
195
196 class NotificationService(service.Service):
197
198 __implements__ = INotificationService,
196 199
197 def get_notification_list(self, node_id, items): 200 def get_notification_list(self, node_id, items):
198 d = self.storage.get_subscribers(node_id) 201 d = self.parent.storage.get_subscribers(node_id)
199 d.addCallback(self._magic_filter, node_id, items) 202 d.addCallback(self._magic_filter, node_id, items)
200 return d 203 return d
201 204
202 def _magic_filter(self, subscribers, node_id, items): 205 def _magic_filter(self, subscribers, node_id, items):
203 list = {} 206 list = {}
204 for subscriber in subscribers: 207 for subscriber in subscribers:
205 list[subscriber] = items 208 list[subscriber] = items
206 209
207 return list 210 return list
208 211
209 def store_items(self, node_id, items, publisher):
210 return self.storage.store_items(node_id, items, publisher)
211
212 class NotificationService(service.Service):
213
214 def register_notifier(self, observerfn, *args, **kwargs): 212 def register_notifier(self, observerfn, *args, **kwargs):
215 self.parent.addObserver('//event/pubsub/notify', observerfn, 213 self.parent.addObserver('//event/pubsub/notify', observerfn,
216 *args, **kwargs) 214 *args, **kwargs)