This class facilitates implementation of Persistent Service. Helps perform the bind and find to the hash_map. More...
#include <PSDL_Datastore.h>
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_Allocator * | allocator (void) |
Return allocator. | |
Private Member Functions | |
int | recreate_all (void) |
int | create_index (void) |
Helper for the <open> method. | |
int | create_index_helper (void *buffer) |
Private Attributes | |
TAO_SYNCH_MUTEX | lock_ |
ALLOCATOR * | allocator_ |
NAME_OBJ_REF_MAP * | obj_ref_map_ |
Hash map where we keep entries for all Persistent entries. | |
const ACE_TCHAR * | index_file_ |
Name of the memory-mapped file used by <allocator_>. | |
void * | base_address_ |
Base address for the memory-mapped file. |
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.
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.
TAO_PSDL_Datastore::TAO_PSDL_Datastore | ( | ) |
Constructor.
Definition at line 16 of file PSDL_Datastore.cpp.
: allocator_ (0), obj_ref_map_ (0), index_file_ ("Data_Store"), base_address_ (ACE_DEFAULT_BASE_ADDR) { this->open (this->index_file_, this->base_address_); }
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.
{ // delete allocator_; // ACE_OS::free (const_cast<ACE_TCHAR *> (this->index_file_)); }
ACE_Allocator * TAO_PSDL_Datastore::allocator | ( | void | ) |
int TAO_PSDL_Datastore::bind | ( | const char * | name, | |
const CORBA::OctetSeq & | octetseq | |||
) |
Definition at line 48 of file PSDL_Datastore.cpp.
{ int result = -1; TAO_PSDL_OctetSeq psdl_octet_seq (this->allocator_); psdl_octet_seq = octet_seq; TAO_PSDL_String psdl_string (this->allocator_); psdl_string = name; ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, -1); // Do a normal bind. This will fail if there's already an // entry with the same name result = this->obj_ref_map_->bind (psdl_string, psdl_octet_seq, this->allocator_); // if (result == 1): Entry already exists. // if (result == -1): Bind failed. // if (result == 0) success. return result; }
int TAO_PSDL_Datastore::create_index | ( | void | ) | [private] |
Helper for the <open> method.
Definition at line 125 of file PSDL_Datastore.cpp.
{ // Make sure that the file name is of the legal length. if (ACE_OS::strlen (this->index_file_) >= MAXNAMELEN + MAXPATHLEN) { errno = ENAMETOOLONG; return -1; } #if !defined (CHORUS) ACE_MMAP_Memory_Pool::OPTIONS options (this->base_address_); #else // Use base address == 0, don't use a fixed address. ACE_MMAP_Memory_Pool::OPTIONS options (0, 0, 0, ACE_CHORUS_LOCAL_NAME_SPACE_T_SIZE); #endif /* CHORUS */ // Create the allocator with the appropriate options. The name used // for the lock is the same as one used for the file. ACE_NEW_RETURN (this->allocator_, ALLOCATOR (this->index_file_, this->index_file_, &options), -1); #if !defined (ACE_LACKS_ACCESS) // Now check if the backing store has been created successfully. if (ACE_OS::access (this->index_file_, F_OK) != 0) ACE_ERROR_RETURN ((LM_ERROR, "create_index\n"), -1); #endif /* ACE_LACKS_ACCESS */ void *name_obj_map = 0; // This is the easy case since if we find hash table in the // memory-mapped file we know it's already initialized. if (this->allocator_->find (TAO_PERSISTENT_NAME_OBJ_MAP, name_obj_map) == 0) { this->obj_ref_map_ = static_cast<NAME_OBJ_REF_MAP *> (name_obj_map); } else { // Create a new <name_obj_map_> (because we've just created a new // memory-mapped file). size_t index_size = sizeof (NAME_OBJ_REF_MAP); name_obj_map = this->allocator_->malloc (index_size); if (name_obj_map == 0 || create_index_helper (name_obj_map) == -1 || this->allocator_->bind (TAO_PERSISTENT_NAME_OBJ_MAP, name_obj_map) == -1) { // Attempt to clean up. ACE_ERROR ((LM_ERROR, "create_index\n")); this->allocator_->remove (); return -1; } } return 0; }
int TAO_PSDL_Datastore::create_index_helper | ( | void * | buffer | ) | [private] |
Helper for <create_index> method: places hash table into an allocated space.
Definition at line 192 of file PSDL_Datastore.cpp.
{ this->obj_ref_map_ = new(buffer) NAME_OBJ_REF_MAP(this->allocator_) ; return 0; }
int TAO_PSDL_Datastore::find | ( | const char * | name, | |
CORBA::OctetSeq & | octet_seq | |||
) |
Definition at line 76 of file PSDL_Datastore.cpp.
{ TAO_PSDL_OctetSeq psdl_seq; TAO_PSDL_String psdl_string (this->allocator_); psdl_string = CORBA::string_dup (name); int result = this->obj_ref_map_->find (psdl_string, psdl_seq, this->allocator_); if (result == 0) { octet_seq.replace (psdl_seq.length_, psdl_seq.length_, psdl_seq.buffer_); } else { ACE_DEBUG ((LM_ERROR, "Couldnt find the entry in the Database. stopping", -1)); } return result; }
int TAO_PSDL_Datastore::init | ( | size_t | context_size | ) |
If <index_> contains no entries (i.e., was just created), create a root Persistent servant with table of size <context_size>, and make an entry for it in the <index_>. If <index_> 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 <index_>. Return 0 on success or -1 on failure.
Definition at line 112 of file PSDL_Datastore.cpp.
{ this->base_address_ = base_address; this->index_file_ = ACE_OS::strdup (file_name); if (this->index_file_ == 0) return -1; return create_index (); }
int TAO_PSDL_Datastore::recreate_all | ( | void | ) | [private] |
Helper for the <init> method. Iterates over <index_>, and creates a servant for each entry.
int TAO_PSDL_Datastore::unbind | ( | const char * | name | ) |
Definition at line 33 of file PSDL_Datastore.cpp.
{ ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, -1); TAO_PSDL_String psdl_string (this->allocator_); psdl_string = name; if (this->obj_ref_map_->unbind (psdl_string, this->allocator_) != 0) return -1; return 0; }
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 <allocator_>.
Definition at line 128 of file PSDL_Datastore.h.
TAO_SYNCH_MUTEX TAO_PSDL_Datastore::lock_ [private] |
Lock to prevent multiple threads from modifying entries in the <index_> 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.