Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Public Attributes | Private Member Functions
arcom.store.cachedstringstore.CachedStringStore Class Reference
Inheritance diagram for arcom.store.cachedstringstore.CachedStringStore:
Inheritance graph
[legend]
Collaboration diagram for arcom.store.cachedstringstore.CachedStringStore:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def set
def list
def get
def lock
def unlock

Public Attributes

 store
 datadir
 non_existent_object
 llock

Private Member Functions

def _load_storage

Detailed Description

Class for storing object in a serialized python format. 

Definition at line 9 of file cachedstringstore.py.


Constructor & Destructor Documentation

def arcom.store.cachedstringstore.CachedStringStore.__init__ (   self,
  storecfg,
  non_existent_object = {} 
)
Constructor of CachedStringStore.

StringStore(storecfg)

'storecfg' is an XMLNode with a 'DataDir'
'non_existent_object' will be returned if an object not found

Reimplemented from arcom.store.cachedpicklestore.CachedPickleStore.

Definition at line 12 of file cachedstringstore.py.

00012 
00013     def __init__(self, storecfg, non_existent_object = {}):
00014         """ Constructor of CachedStringStore.
00015 
00016         StringStore(storecfg)
00017 
00018         'storecfg' is an XMLNode with a 'DataDir'
00019         'non_existent_object' will be returned if an object not found
00020         """
00021         CachedPickleStore.__init__(self, storecfg, non_existent_object)
00022         log.msg(arc.VERBOSE, "CachedStringStore constructor called")
00023         log.msg(arc.VERBOSE, "datadir:", self.datadir)
00024         self.store = {}
00025         self._load_storage()


Member Function Documentation

Reimplemented from arcom.store.cachedpicklestore.CachedPickleStore.

Definition at line 26 of file cachedstringstore.py.

00026 
00027     def _load_storage(self):
00028         filelist = self._list()
00029         for f in filelist:
00030             self.store[base64.b64decode(f)] = eval(file(os.path.join(self.datadir,f[:2],f), 'rb').read())

Here is the call graph for this function:

def arcom.store.cachedpicklestore.CachedPickleStore.get (   self,
  ID 
) [inherited]
Returns the object with the given ID.

get(ID)

'ID' is the ID of the requested object.
If there is no object with this ID, returns the given non_existent_object value.

Reimplemented from arcom.store.picklestore.PickleStore.

Definition at line 40 of file cachedpicklestore.py.

00040 
00041     def get(self, ID):
00042         """ Returns the object with the given ID.
00043 
00044         get(ID)
00045 
00046         'ID' is the ID of the requested object.
00047         If there is no object with this ID, returns the given non_existent_object value.
00048         """
00049         try:
00050             # return a copy of the in-memory stored object
00051             return copy.deepcopy(self.store[ID])
00052         except KeyError:
00053             # don't print 'KeyError' if there is no such ID
00054             pass
00055         except:
00056             # print whatever exception happened
00057             log.msg()
00058             log.msg(arc.ERROR, "ID", ID)
00059         # if there was an exception, return the given non_existent_object
00060         return copy.deepcopy(self.non_existent_object)

Here is the caller graph for this function:

List the IDs of the existing entries.

list()

Returns a list of IDs.

Reimplemented from arcom.store.picklestore.PickleStore.

Definition at line 31 of file cachedpicklestore.py.

00031 
00032     def list(self):
00033         """ List the IDs of the existing entries.
00034         
00035         list()
00036         
00037         Returns a list of IDs.
00038         """
00039         return self.store.keys()
            
def arcom.store.basestore.BaseStore.lock (   self,
  blocking = True 
) [inherited]
Acquire the lock.

lock(blocking = True)

'blocking': if blocking is True, then this only returns when the lock is acquired.
If it is False, then it returns immediately with False if the lock is not available,
or with True if it could be acquired.

Reimplemented in storage.ahash.replicatedahash.ReplicationStore.

Definition at line 27 of file basestore.py.

00027 
00028     def lock(self, blocking = True):
00029         """ Acquire the lock.
00030 
00031         lock(blocking = True)
00032 
00033         'blocking': if blocking is True, then this only returns when the lock is acquired.
00034         If it is False, then it returns immediately with False if the lock is not available,
00035         or with True if it could be acquired.
00036         """
00037         return self.llock.acquire(blocking)

Here is the caller graph for this function:

def arcom.store.cachedstringstore.CachedStringStore.set (   self,
  ID,
  object 
)
Stores an object with the given ID..

set(ID, object)

'ID' is the ID of the object
'object' is the object itself
If there is already an object with this ID it will be overwritten completely.

Reimplemented from arcom.store.cachedpicklestore.CachedPickleStore.

Definition at line 31 of file cachedstringstore.py.

00031 
00032     def set(self, ID, object):
00033         """ Stores an object with the given ID..
00034 
00035         set(ID, object)
00036 
00037         'ID' is the ID of the object
00038         'object' is the object itself
00039         If there is already an object with this ID it will be overwritten completely.
00040         """
00041         if not ID:
00042             raise Exception, 'ID is empty'
00043         try:
00044             # generates a filename from the ID
00045             fn = self._filename(ID)
00046             tmp_fn = self._tmpfilename(ID)
00047             # if 'object' is empty, don't make file
00048             if object:
00049                 # serialize the given list into tmp_fn
00050                 f = file(tmp_fn,'wb')
00051                 f.write(str(object))
00052                 f.close()
00053                 # try to rename the file
00054                 try:
00055                     os.rename(tmp_fn,fn)
00056                 except:
00057                     # try to create parent dir first, then rename the file
00058                     os.mkdir(os.path.dirname(fn))
00059                     os.rename(tmp_fn,fn)
00060                 self.store[ID] = object
00061             elif os.path.isfile(fn):
00062                 # object empty, file is not needed anymore
00063                 os.remove(fn)
00064                 del(self.store[ID])
00065         except:
00066             log.msg()

Here is the call graph for this function:

Here is the caller graph for this function:

def arcom.store.basestore.BaseStore.unlock (   self) [inherited]
Release the lock.

unlock()

Reimplemented in storage.ahash.replicatedahash.ReplicationStore.

Definition at line 38 of file basestore.py.

00038 
00039     def unlock(self):
00040         """ Release the lock.
00041 
00042         unlock()
00043         """
00044         self.llock.release()
        

Here is the caller graph for this function:


Member Data Documentation

Definition at line 18 of file basestore.py.

Definition at line 25 of file basestore.py.

Definition at line 20 of file basestore.py.

Reimplemented from arcom.store.cachedpicklestore.CachedPickleStore.

Definition at line 23 of file cachedstringstore.py.


The documentation for this class was generated from the following file: