1
2
3
4
5
6
7
8
9
10
11
12 """
13 Request tracker classes.
14 """
15
16 from threading import RLock
17
18 from gofer import Singleton, synchronized
22 """
23 Request tracker used to track information about
24 active RMI requests.
25 @ivar __all: All known requests by serial number.
26 @type __all: set
27 @ivar __cancelled: Cancelled requests.
28 @type __cancelled: set
29 @ivar __mutex: The object mutex.
30 @type __mutex: RLock
31 """
32
33 __metaclass__ = Singleton
34
36 self.__all = dict()
37 self.__cancelled = set()
38 self.__mutex = RLock()
39
40 @synchronized
41 - def add(self, sn, locator):
42 """
43 Add a serial number (make know) for tracking.
44 @param sn: An RMI serial number.
45 @type sn: str
46 @param locator: The object used by find() to match
47 on RMI requests.
48 @type locator: object
49 """
50 self.__all[sn] = locator
51
52 @synchronized
53 - def find(self, criteria):
54 """
55 Find serial numbers matching user defined (any) data.
56 @param criteria: The object used to match RMI requests.
57 @type criteria: L{gofer.rmi.criteria.Criteria}
58 @return: The list of matching serial numbers.
59 @rtype: list
60 """
61 matched = []
62 for sn, locator in self.__all.items():
63 if criteria.match(locator):
64 matched.append(sn)
65 return matched
66
67 @synchronized
69 """
70 Notify the tracker that an RMI request has been cancelled.
71 @param sn: An RMI serial number.
72 @type sn: str
73 @return: The cancelled serial number (if not already cancelled).
74 @rtype: str
75 """
76 if sn in self.__all:
77 if sn not in self.__cancelled:
78 self.__cancelled.add(sn)
79 return sn
80 else:
81 raise Exception, 'serial number (%s), not-found' % sn
82
83 @synchronized
85 """
86 Get whether an RMI request has been cancelled.
87 @param sn: An RMI serial number.
88 @type sn: str
89 @return: True if cancelled.
90 @rtype: bool
91 """
92 return sn in self.__cancelled
93
94 @synchronized
96 """
97 Discontinue tracking an RMI request.
98 @param sn: An RMI serial number.
99 @type sn: str
100 """
101 self.__all.pop(sn)
102 if sn in self.__cancelled:
103 self.__cancelled.remove(sn)
104