TAO_PSDL_Datastore Class Reference

This class facilitates implementation of Persistent Service. Helps perform the bind and find to the hash_map. More...

#include <PSDL_Datastore.h>

Collaboration diagram for TAO_PSDL_Datastore:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_Hash_Map_With_Allocator<
TAO_PSDL_String, TAO_PSDL_OctetSeq
NAME_OBJ_REF_MAP
 Hash map used by Persistent Naming Context to keep its state.

typedef ACE_Hash_Map_Entry<
TAO_PSDL_String, TAO_PSDL_OctetSeq
NAME_OBJ_REF_ENTRY
typedef ACE_Allocator_Adapter<
ACE_Malloc< ACE_MMAP_MEMORY_POOL,
TAO_SYNCH_MUTEX > > 
ALLOCATOR
 Allocator we will be using to make the Naming Service persistent.


Public Member Functions

 TAO_PSDL_Datastore ()
 Constructor.

int open (const ACE_TCHAR *file_name, void *base_address=ACE_DEFAULT_BASE_ADDR)
int init (size_t context_size)
 ~TAO_PSDL_Datastore (void)
int bind (const char *name, const CORBA::OctetSeq &octetseq)
int unbind (const char *name)
int find (const char *name, CORBA::OctetSeq &octet_seq)
ACE_Allocatorallocator (void)
 Return allocator.


Private Member Functions

int recreate_all (void)
int create_index (void)
 Helper for the method.

int create_index_helper (void *buffer)

Private Attributes

TAO_SYNCH_MUTEX lock_
ALLOCATORallocator_
NAME_OBJ_REF_MAPobj_ref_map_
 Hash map where we keep entries for all Persistent entries.

const ACE_TCHARindex_file_
 Name of the memory-mapped file used by .

void * base_address_
 Base address for the memory-mapped file.


Detailed Description

This class facilitates implementation of Persistent Service. Helps perform the bind and find to the hash_map.

Definition at line 44 of file PSDL_Datastore.h.


Member Typedef Documentation

typedef ACE_Allocator_Adapter<ACE_Malloc <ACE_MMAP_MEMORY_POOL, TAO_SYNCH_MUTEX> > TAO_PSDL_Datastore::ALLOCATOR
 

Allocator we will be using to make the Naming Service persistent.

Definition at line 56 of file PSDL_Datastore.h.

typedef ACE_Hash_Map_Entry<TAO_PSDL_String, TAO_PSDL_OctetSeq> TAO_PSDL_Datastore::NAME_OBJ_REF_ENTRY
 

Definition at line 52 of file PSDL_Datastore.h.

typedef ACE_Hash_Map_With_Allocator<TAO_PSDL_String, TAO_PSDL_OctetSeq> TAO_PSDL_Datastore::NAME_OBJ_REF_MAP
 

Hash map used by Persistent Naming Context to keep its state.

Definition at line 50 of file PSDL_Datastore.h.

Referenced by create_index(), and create_index_helper().


Constructor & Destructor Documentation

TAO_PSDL_Datastore::TAO_PSDL_Datastore  ) 
 

Constructor.

Definition at line 16 of file PSDL_Datastore.cpp.

References ACE_DEFAULT_BASE_ADDR, and open().

00017   : allocator_ (0),
00018     obj_ref_map_ (0),
00019     index_file_ ("Data_Store"),
00020     base_address_ (ACE_DEFAULT_BASE_ADDR)
00021 {
00022   this->open (this->index_file_,
00023               this->base_address_);
00024 }

TAO_PSDL_Datastore::~TAO_PSDL_Datastore void   ) 
 

Destructor. The memory mapped file that was opened/created is not deleted, since we want it to keep the state of the Database until the next run.

Definition at line 26 of file PSDL_Datastore.cpp.

00027 {
00028   // delete allocator_;
00029   // ACE_OS::free (const_cast<ACE_TCHAR *> (this->index_file_));
00030 }


Member Function Documentation

ACE_Allocator * TAO_PSDL_Datastore::allocator void   ) 
 

Return allocator.

Definition at line 106 of file PSDL_Datastore.cpp.

00107 {
00108   return allocator_;
00109 }

int TAO_PSDL_Datastore::bind const char *  name,
const CORBA::OctetSeq octetseq
 

Definition at line 48 of file PSDL_Datastore.cpp.

References ACE_GUARD_RETURN, TAO_PSDL_OctetSeq::allocator_, ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::bind(), obj_ref_map_, and TAO_SYNCH_MUTEX.

00050 {
00051   int result = -1;
00052 
00053   TAO_PSDL_OctetSeq psdl_octet_seq (this->allocator_);
00054 
00055   psdl_octet_seq = octet_seq;
00056 
00057   TAO_PSDL_String psdl_string (this->allocator_);
00058 
00059   psdl_string = name;
00060 
00061   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, -1);
00062 
00063   // Do a normal bind.  This will fail if there's already an
00064   // entry with the same name
00065   result = this->obj_ref_map_->bind (psdl_string,
00066                                      psdl_octet_seq,
00067                                      this->allocator_);
00068 
00069   // if (result == 1): Entry already exists.
00070   // if (result == -1): Bind failed.
00071   // if (result == 0) success.
00072   return result;
00073 }

int TAO_PSDL_Datastore::create_index void   )  [private]
 

Helper for the method.

Definition at line 125 of file PSDL_Datastore.cpp.

References ACE_OS::access(), ACE_ERROR, ACE_ERROR_RETURN, ACE_NEW_RETURN, create_index_helper(), F_OK, LM_ERROR, MAXNAMELEN, MAXPATHLEN, NAME_OBJ_REF_MAP, obj_ref_map_, ACE_OS::strlen(), and TAO_PERSISTENT_NAME_OBJ_MAP.

Referenced by open().

00126 {
00127   // Make sure that the file name is of the legal length.
00128   if (ACE_OS::strlen (this->index_file_) >= MAXNAMELEN + MAXPATHLEN)
00129     {
00130       errno = ENAMETOOLONG;
00131       return -1;
00132     }
00133 
00134 #if !defined (CHORUS)
00135   ACE_MMAP_Memory_Pool::OPTIONS options (this->base_address_);
00136 #else
00137   // Use base address == 0, don't use a fixed address.
00138   ACE_MMAP_Memory_Pool::OPTIONS options (0,
00139                                          0,
00140                                          0,
00141                                          ACE_CHORUS_LOCAL_NAME_SPACE_T_SIZE);
00142 #endif /* CHORUS */
00143 
00144   // Create the allocator with the appropriate options.  The name used
00145   // for  the lock is the same as one used for the file.
00146   ACE_NEW_RETURN (this->allocator_,
00147                   ALLOCATOR (this->index_file_,
00148                              this->index_file_,
00149                              &options),
00150                   -1);
00151 
00152 #if !defined (ACE_LACKS_ACCESS)
00153   // Now check if the backing store has been created successfully.
00154   if (ACE_OS::access (this->index_file_, F_OK) != 0)
00155     ACE_ERROR_RETURN ((LM_ERROR,
00156                        "create_index\n"),
00157                       -1);
00158 #endif /* ACE_LACKS_ACCESS */
00159 
00160   void *name_obj_map = 0;
00161 
00162   // This is the easy case since if we find hash table in the
00163   // memory-mapped file we know it's already initialized.
00164   if (this->allocator_->find (TAO_PERSISTENT_NAME_OBJ_MAP, name_obj_map) == 0)
00165     {
00166       this->obj_ref_map_ = static_cast<NAME_OBJ_REF_MAP *> (name_obj_map);
00167     }
00168   else
00169     {
00170       // Create a new <name_obj_map_> (because we've just created a new
00171       // memory-mapped file).
00172 
00173       size_t index_size = sizeof (NAME_OBJ_REF_MAP);
00174       name_obj_map = this->allocator_->malloc (index_size);
00175 
00176       if (name_obj_map == 0
00177           || create_index_helper (name_obj_map) == -1
00178           || this->allocator_->bind (TAO_PERSISTENT_NAME_OBJ_MAP,
00179                                      name_obj_map) == -1)
00180         {
00181           // Attempt to clean up.
00182           ACE_ERROR ((LM_ERROR,
00183                       "create_index\n"));
00184           this->allocator_->remove ();
00185           return -1;
00186         }
00187     }
00188   return 0;
00189 }

int TAO_PSDL_Datastore::create_index_helper void *  buffer  )  [private]
 

Helper for method: places hash table into an allocated space.

Definition at line 192 of file PSDL_Datastore.cpp.

References NAME_OBJ_REF_MAP, and obj_ref_map_.

Referenced by create_index().

00193 {
00194   this->obj_ref_map_ = new(buffer) NAME_OBJ_REF_MAP(this->allocator_) ;
00195   return 0;
00196 }

int TAO_PSDL_Datastore::find const char *  name,
CORBA::OctetSeq octet_seq
 

Definition at line 76 of file PSDL_Datastore.cpp.

References ACE_DEBUG, TAO_PSDL_OctetSeq::allocator_, TAO_PSDL_OctetSeq::buffer_, ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), TAO_PSDL_OctetSeq::length_, LM_ERROR, obj_ref_map_, TAO::unbounded_value_sequence< T >::replace(), and CORBA::string_dup().

00078 {
00079   TAO_PSDL_OctetSeq psdl_seq;
00080 
00081   TAO_PSDL_String psdl_string (this->allocator_);
00082 
00083   psdl_string = CORBA::string_dup (name);
00084 
00085   int result = this->obj_ref_map_->find (psdl_string,
00086                                          psdl_seq,
00087                                          this->allocator_);
00088 
00089   if (result == 0)
00090     {
00091       octet_seq.replace (psdl_seq.length_,
00092                          psdl_seq.length_,
00093                          psdl_seq.buffer_);
00094     }
00095   else
00096     {
00097       ACE_DEBUG ((LM_ERROR,
00098                   "Couldnt find the entry in the Database. stopping",
00099                   -1));
00100     }
00101 
00102   return result;
00103 }

int TAO_PSDL_Datastore::init size_t  context_size  ) 
 

If contains no entries (i.e., was just created), create a root Persistent servant with table of size , and make an entry for it in the . If contains entries, create a Persistent servant for each entry. Return 0 on success and -1 on failure.

int TAO_PSDL_Datastore::open const ACE_TCHAR file_name,
void *  base_address = ACE_DEFAULT_BASE_ADDR
 

Create ACE_Allocator, open/create memory-mapped file with the specified file name/base address. Find or allocate . Return 0 on success or -1 on failure.

Definition at line 112 of file PSDL_Datastore.cpp.

References create_index(), index_file_, and ACE_OS::strdup().

Referenced by TAO_PSDL_Datastore().

00114 {
00115   this->base_address_ = base_address;
00116 
00117   this->index_file_ = ACE_OS::strdup (file_name);
00118   if (this->index_file_ == 0)
00119     return -1;
00120 
00121   return create_index ();
00122 }

int TAO_PSDL_Datastore::recreate_all void   )  [private]
 

Helper for the method. Iterates over , and creates a servant for each entry.

int TAO_PSDL_Datastore::unbind const char *  name  ) 
 

Definition at line 33 of file PSDL_Datastore.cpp.

References ACE_GUARD_RETURN, TAO_PSDL_String::allocator_, obj_ref_map_, TAO_SYNCH_MUTEX, and ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::unbind().

00034 {
00035   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, -1);
00036 
00037   TAO_PSDL_String psdl_string (this->allocator_);
00038 
00039   psdl_string = name;
00040 
00041   if (this->obj_ref_map_->unbind (psdl_string, this->allocator_) != 0)
00042     return -1;
00043 
00044   return 0;
00045 }


Member Data Documentation

ALLOCATOR* TAO_PSDL_Datastore::allocator_ [private]
 

Allocator that deals out memory from a memory-mapped file. We use it whenever we deal with data that should be kept in persistent store.

Definition at line 122 of file PSDL_Datastore.h.

void* TAO_PSDL_Datastore::base_address_ [private]
 

Base address for the memory-mapped file.

Definition at line 131 of file PSDL_Datastore.h.

const ACE_TCHAR* TAO_PSDL_Datastore::index_file_ [private]
 

Name of the memory-mapped file used by .

Definition at line 128 of file PSDL_Datastore.h.

Referenced by open().

TAO_SYNCH_MUTEX TAO_PSDL_Datastore::lock_ [private]
 

Lock to prevent multiple threads from modifying entries in the simultanneously.

Definition at line 115 of file PSDL_Datastore.h.

NAME_OBJ_REF_MAP* TAO_PSDL_Datastore::obj_ref_map_ [private]
 

Hash map where we keep entries for all Persistent entries.

Definition at line 125 of file PSDL_Datastore.h.

Referenced by bind(), create_index(), create_index_helper(), find(), and unbind().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 14:08:45 2006 for TAO_PSS by doxygen 1.3.6