Mercurial > libervia-pubsub
comparison idavoll/backend.py @ 29:d4fc29bb5381
Define interfaces of blocks of functionality.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Tue, 26 Oct 2004 16:25:59 +0000 |
parents | 4f3bbefc6fad |
children | b65b7ea5c992 |
comparison
equal
deleted
inserted
replaced
28:39d0c6fa027f | 29:d4fc29bb5381 |
---|---|
1 from twisted.python import components | 1 from twisted.python import components |
2 | 2 from twisted.application import service |
3 class IService(components.Interface): | 3 from twisted.xish import utility |
4 """ Interface to a backend service of a pubsub service """ | |
5 | |
6 def do_publish(self, node, publisher, item): | |
7 """ Returns a deferred that returns """ | |
8 | 4 |
9 class Error(Exception): | 5 class Error(Exception): |
10 msg = '' | 6 msg = '' |
11 | 7 |
12 def __str__(self): | 8 def __str__(self): |
13 return self.msg | 9 return self.msg |
14 | 10 |
15 class NodeNotFound(Error): | 11 class NodeNotFound(Error): |
16 msg = 'Node not found' | 12 msg = 'Node not found' |
17 | 13 |
18 class NotAuthorized(Error): | 14 class NotAuthorized(Error): |
19 pass | 15 pass |
20 | 16 |
21 class PayloadExpected(Error): | 17 class PayloadExpected(Error): |
22 msg = 'Payload expected' | 18 msg = 'Payload expected' |
23 | 19 |
24 class NoPayloadAllowed(Error): | 20 class NoPayloadAllowed(Error): |
25 msg = 'No payload allowed' | 21 msg = 'No payload allowed' |
26 | 22 |
27 class NoInstantNodes(Error): | 23 class NoInstantNodes(Error): |
28 pass | 24 pass |
29 | 25 |
30 class NodeExists(Error): | 26 class NodeExists(Error): |
31 pass | 27 pass |
28 | |
29 class NotImplemented(Error): | |
30 msg = 'Oops!' | |
31 | |
32 class IBackendService(components.Interface): | |
33 """ Interface to a backend service of a pubsub service. """ | |
34 | |
35 def get_supported_affiliations(self): | |
36 """ Reports the list of supported affiliation types. | |
37 | |
38 @return: a list of supported affiliation types. | |
39 """ | |
40 | |
41 class INodeCreationService(components.Interface): | |
42 """ A service for creating nodes """ | |
43 | |
44 def create_node(self, node_id, requestor): | |
45 """ Create a node. | |
46 | |
47 @return: a deferred that fires when the node has been created. | |
48 """ | |
49 | |
50 class IPublishService(components.Interface): | |
51 """ A service for publishing items to a node. """ | |
52 | |
53 def publish(self, node_id, items, requestor): | |
54 """ Publish items to a pubsub node. | |
55 | |
56 @return: a deferred that fires when the items have been published. | |
57 """ | |
58 class INotificationService(components.Interface): | |
59 """ A service for notification of published items. """ | |
60 | |
61 def register_notifier(self, observerfn, *args, **kwargs): | |
62 """ Register callback which is called for notification. """ | |
63 | |
64 def get_notification_list(self, node_id, items): | |
65 pass | |
66 | |
67 class ISubscriptionService(components.Interface): | |
68 """ A service for managing subscriptions. """ | |
69 | |
70 def subscribe(self, node_id, subscriber, requestor): | |
71 """ Request the subscription of an entity to a pubsub node. | |
72 | |
73 Depending on the node's configuration and possible business rules, the | |
74 C{subscriber} is added to the list of subscriptions of the node with id | |
75 C{node_id}. The C{subscriber} might be different from the C{requestor}, | |
76 and if the C{requestor} is not allowed to subscribe this entity an | |
77 exception should be raised. | |
78 | |
79 @return: a deferred that returns the subscription state | |
80 """ | |
81 | |
82 def unsubscribe(self, node_id, subscriber, requestor): | |
83 """ Cancel the subscription of an entity to a pubsub node. | |
84 | |
85 The subscription of C{subscriber} is removed from the list of | |
86 subscriptions of the node with id C{node_id}. If the C{requestor} | |
87 is not allowed to unsubscribe C{subscriber}, an an exception should | |
88 be raised. | |
89 | |
90 @return: a deferred that fires when unsubscription is complete. | |
91 """ | |
92 | |
93 class IAffiliationsService(components.Interface): | |
94 """ A service for retrieving the affiliations with this pubsub service. """ | |
95 | |
96 def get_affiliations(self, entity): | |
97 """ Report the list of current affiliations with this pubsub service. | |
98 | |
99 Report the list of the current affiliations with all nodes within this | |
100 pubsub service, along with subscriptions to such nodes, for the | |
101 C{entity}. | |
102 | |
103 @return: a deferred that returns the list of all current affiliations | |
104 and subscriptions. | |
105 """ | |
106 | |
107 class IPersistenceService(components.Interface): | |
108 """ A service for persisting published items """ | |
109 | |
110 def store_items(self, node_id, items, publisher): | |
111 """ Store items for a node, recording the publisher """ | |
112 | |
113 class IRetractionService(components.Interface): | |
114 """ A service for retracting published items """ | |
115 | |
116 def retract_item(self, node_id, item_id, requestor): | |
117 """ Removes item in node from persistent storage """ | |
118 | |
119 def purge_node(self, node_id, requestor): | |
120 """ Removes all items in node from persistent storage """ | |
121 | |
122 class IItemRetrievalService(components.Interface): | |
123 """ A service for retrieving previously published items. """ | |
124 | |
125 def get_items(self, node_id, max_items=None, item_ids=[], | |
126 requestor=None): | |
127 """ Retrieve items from persistent storage | |
128 | |
129 If C{max_items} is given, return the C{max_items} last published | |
130 items, else if C{item_ids} is not empty, return the items requested. | |
131 If neither is given, return all items. | |
132 | |
133 @return: a deferred that returns the requested items | |
134 """ | |
135 | |
136 class BackendService(service.MultiService, utility.EventDispatcher): | |
137 | |
138 __implements__ = IBackendService, | |
139 | |
140 def __init__(self): | |
141 service.MultiService.__init__(self) | |
142 utility.EventDispatcher.__init__(self) | |
143 | |
144 class NotificationService(service.Service): | |
145 | |
146 def register_notifier(self, observerfn, *args, **kwargs): | |
147 self.parent.addObserver('//event/pubsub/notify', observerfn, | |
148 *args, **kwargs) |