Back to index

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

List of all members.

Public Member Functions

def __init__
def list
def get
def set
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 10 of file cachedpicklestore.py.


Constructor & Destructor Documentation

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

CachedPickleStore(storecfg)

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

Reimplemented from arcom.store.picklestore.PickleStore.

Reimplemented in arcom.store.cachedstringstore.CachedStringStore.

Definition at line 13 of file cachedpicklestore.py.

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


Member Function Documentation

Reimplemented in arcom.store.cachedstringstore.CachedStringStore.

Definition at line 26 of file cachedpicklestore.py.

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

Here is the call graph for this function:

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.cachedpicklestore.CachedPickleStore.set (   self,
  ID,
  obj 
)
Stores an object with the given ID..

set(ID, obj)

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

Reimplemented from arcom.store.picklestore.PickleStore.

Reimplemented in arcom.store.cachedstringstore.CachedStringStore.

Definition at line 61 of file cachedpicklestore.py.

00061 
00062     def set(self, ID, obj):
00063         """ Stores an object with the given ID..
00064 
00065         set(ID, obj)
00066 
00067         'ID' is the ID of the object
00068         'obj' is the object itself
00069         If there is already an object with this ID it will be overwritten completely.
00070         """
00071         if not ID:
00072             raise Exception, 'ID is empty'
00073         try:
00074             # generates a filename from the ID
00075             fn = self._filename(ID)
00076             tmp_fn = self._tmpfilename(ID)
00077             # if 'obj' is empty, don't make file
00078             if obj:
00079                 # TODO: what if something happens between the disk write and the in-memory store update, and only the disk gets updated?
00080                 # serialize the given list into tmp_fn
00081                 pickle.dump(obj, file(tmp_fn,'wb'))
00082                 # try to rename the file
00083                 try:
00084                     os.rename(tmp_fn,fn)
00085                 except:
00086                     # try to create parent dir first, then rename the file
00087                     os.mkdir(os.path.dirname(fn))
00088                     os.rename(tmp_fn,fn)
00089                 # store a copy of the object
00090                 self.store[ID] = copy.deepcopy(obj)
00091             elif os.path.isfile(fn):
00092                 # object empty, file is not needed anymore
00093                 os.remove(fn)
00094                 del(self.store[ID])
00095         except:
00096             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 in arcom.store.cachedstringstore.CachedStringStore.

Definition at line 23 of file cachedpicklestore.py.


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