Package gofer :: Package rmi :: Module tracker
[hide private]
[frames] | no frames]

Source Code for Module gofer.rmi.tracker

  1  # Copyright (c) 2012 Red Hat, Inc. 
  2  # 
  3  # This software is licensed to you under the GNU General Public 
  4  # License as published by the Free Software Foundation; either version 
  5  # 2 of the License (GPLv2) or (at your option) any later version. 
  6  # There is NO WARRANTY for this software, express or implied, 
  7  # including the implied warranties of MERCHANTABILITY, 
  8  # NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should 
  9  # have received a copy of GPLv2 along with this software; if not, see 
 10  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 11   
 12  """ 
 13  Request tracker classes. 
 14  """ 
 15   
 16  from threading import RLock 
 17   
 18  from gofer import Singleton, synchronized 
19 20 21 -class Tracker:
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
35 - def __init__(self):
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
68 - def cancel(self, sn):
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
84 - def cancelled(self, sn):
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
95 - def remove(self, sn):
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