Changeset ef252e9
- Timestamp:
- Feb 28, 2010 12:24:51 PM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 2761484
- Parents:
- 358e0b8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/synch_store.py
r358e0b8 ref252e9 16 16 # Thrown if a non-existant key is deleted 17 17 class BadDeletionError(Exception): pass 18 19 # Thrown if a key is specified with a white space 20 class BadKeyError(Exception): pass 18 21 19 22 # A value in the dict. Each has its own condition (and lock) for threads … … 37 40 # Set the value in the dict. If threads are waiting, wake them. 38 41 def set_value(self, key, value): 42 if key.find(' ') != -1: 43 raise self.BadKeyError("Whitespace is not allowed in keys") 44 39 45 self.main_lock.acquire() 40 46 if self.values.has_key(key): … … 88 94 self.main_lock.release() 89 95 raise synch_store.BadDeletionError("%s does not exist yet" % key) 96 97 def all_keys(self): 98 self.main_lock.acquire() 99 rv = [ k for k in self.values.keys()] 100 self.main_lock.release() 101 return rv 102 103 # Save the store contents to a file in a simple way 104 def save(self, filename): 105 self.main_lock.acquire() 106 f = open(filename, 'w') 107 for k, v in self.values.items(): 108 self.values[k].condition.acquire() 109 if self.values[k].value is not None: 110 print >> f, "%s %s" % ( k, str(self.values[k].value)) 111 else: 112 print >> f, "%s" % k 113 self.values[k].condition.release() 114 self.main_lock.release() 115 f.close() 116 117 # Load the store contents from a file 118 def load(self, filename): 119 self.main_lock.acquire() 120 self.values = { } 121 f = open(filename, 'r') 122 for l in f: 123 i = l.find(' ') 124 if i != -1: self.values[l[:i]] = synch_store.synch_value(l[i+1:]) 125 else: self.values[l] = synch_store.synch_value() 126 f.close() 127 self.main_lock.release() 90 128 91 129 # A debugging representation
Note: See TracChangeset
for help on using the changeset viewer.