Go to the documentation of this file.00001
00002
00003 #include "orbsvcs/Notify/Standard_Event_Persistence.h"
00004 #include "orbsvcs/Notify/Persistent_File_Allocator.h"
00005 #include "tao/debug.h"
00006 #include "ace/Dynamic_Service.h"
00007 #include "ace/OS_NS_strings.h"
00008 #include "ace/Truncate.h"
00009
00010 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00011
00012 namespace TAO_Notify
00013 {
00014
00015 Standard_Event_Persistence::Standard_Event_Persistence ()
00016 : filename_ (ACE_TEXT ("__PERSISTENT_EVENT__.DB"))
00017 , block_size_ (512)
00018 , factory_ (0)
00019 {
00020 }
00021
00022 Standard_Event_Persistence::~Standard_Event_Persistence ()
00023 {
00024 }
00025
00026
00027 Event_Persistence_Factory *
00028 Standard_Event_Persistence::get_factory ()
00029 {
00030
00031 if (this->factory_ == 0)
00032 {
00033 ACE_NEW_NORETURN (
00034 this->factory_,
00035 Standard_Event_Persistence_Factory ()
00036 );
00037 if (this->factory_ != 0)
00038 {
00039 if (!this->factory_->open (this->filename_.c_str ()))
00040 {
00041 this->factory_ = 0;
00042 }
00043 }
00044 }
00045 return this->factory_;
00046 }
00047
00048
00049 void
00050 Standard_Event_Persistence::reset ()
00051 {
00052 delete this->factory_;
00053 this->factory_ = 0;
00054 }
00055
00056 int
00057 Standard_Event_Persistence::init (int argc, ACE_TCHAR *argv[])
00058 {
00059 int result = 0;
00060 bool verbose = false;
00061 for (int narg = 0; narg < argc; ++narg)
00062 {
00063 ACE_TCHAR * av = argv[narg];
00064 if (ACE_OS::strcasecmp (av, ACE_TEXT ("-v")) == 0)
00065 {
00066 verbose = true;
00067 ACE_DEBUG ((LM_DEBUG,
00068 ACE_TEXT ("(%P|%t) Standard_Event_Persistence: -verbose\n")
00069 ));
00070 }
00071 else if (ACE_OS::strcasecmp (av, ACE_TEXT ("-file_path")) == 0 && narg + 1 < argc)
00072 {
00073 this->filename_ = argv[narg + 1];
00074 if (TAO_debug_level > 0 || verbose)
00075 {
00076 ACE_DEBUG ((LM_DEBUG,
00077 ACE_TEXT ("(%P|%t) Standard_Event_Persistence: Setting -file_path: %s\n"),
00078 this->filename_.c_str ()
00079 ));
00080 }
00081 narg += 1;
00082 }
00083 else if (ACE_OS::strcasecmp (av, ACE_TEXT ("-block_size")) == 0 && narg + 1 < argc)
00084 {
00085 this->block_size_ = ACE_OS::atoi(argv[narg + 1]);
00086 if (TAO_debug_level > 0 || verbose)
00087 {
00088 ACE_DEBUG ((LM_DEBUG,
00089 ACE_TEXT ("(%P|%t) Standard_Event_Persistence: Setting -block_size: %d\n"),
00090 this->block_size_
00091 ));
00092 }
00093 narg += 1;
00094 }
00095 else
00096 {
00097 ACE_ERROR ((LM_ERROR,
00098 ACE_TEXT ("(%P|%t) Unknown parameter to Standard Event Persistence: %s\n"),
00099 argv[narg]
00100 ));
00101 result = -1;
00102 }
00103 }
00104 return result;
00105 }
00106
00107 int
00108 Standard_Event_Persistence::fini ()
00109 {
00110 delete this->factory_;
00111 this->factory_ = 0;
00112 return 0;
00113 }
00114
00115 Standard_Event_Persistence_Factory::Standard_Event_Persistence_Factory ()
00116 : allocator_()
00117 , root_(this)
00118 , psb_(0)
00119 , serial_number_(ROUTING_SLIP_ROOT_SERIAL_NUMBER + 1)
00120 , is_reloading_ (false)
00121 {
00122 }
00123
00124 bool
00125 Standard_Event_Persistence_Factory::open (const ACE_TCHAR* filename,
00126 ACE_UINT32 block_size)
00127 {
00128 bool result = false;
00129 if (allocator_.open (filename, block_size))
00130 {
00131 this->is_reloading_ = this->root_.load(ROUTING_SLIP_ROOT_BLOCK_NUMBER, ROUTING_SLIP_ROOT_SERIAL_NUMBER);
00132 if (! this->is_reloading_)
00133 {
00134 ACE_ASSERT (this->psb_ == 0);
00135
00136 this->root_.store_root();
00137 }
00138 result = true;
00139 }
00140 return result;
00141 }
00142
00143 Standard_Event_Persistence_Factory::~Standard_Event_Persistence_Factory()
00144 {
00145 if (TAO_debug_level > 0)
00146 {
00147 ACE_DEBUG ((LM_DEBUG,
00148 ACE_TEXT ("(%P|%t) Standard_Event_Persistence_Factory::~Standard_Event_Persistence_Factory\n")
00149 ));
00150 }
00151 this->root_.release_all ();
00152 delete this->psb_;
00153 this->psb_ = 0;
00154 this->allocator_.shutdown();
00155 }
00156
00157 Routing_Slip_Persistence_Manager*
00158 Standard_Event_Persistence_Factory::create_routing_slip_persistence_manager(
00159 Persistent_Callback* callback)
00160 {
00161 Routing_Slip_Persistence_Manager* rspm = 0;
00162 ACE_NEW_RETURN(rspm, Routing_Slip_Persistence_Manager(this), rspm);
00163 rspm->set_callback(callback);
00164 return rspm;
00165 }
00166
00167 Routing_Slip_Persistence_Manager *
00168 Standard_Event_Persistence_Factory::first_reload_manager()
00169 {
00170 Routing_Slip_Persistence_Manager * result = 0;
00171 if (this->is_reloading_)
00172 {
00173 result = this->root_.load_next();
00174 }
00175 return result;
00176 }
00177
00178 void
00179 Standard_Event_Persistence_Factory::done_reloading(
00180 Persistent_Storage_Block * next_psb,
00181 ACE_UINT64 current_serial_number)
00182 {
00183 ACE_ASSERT (this->psb_ == 0);
00184 this->psb_ = next_psb;
00185 this->serial_number_ = current_serial_number;
00186 this->is_reloading_ = false;
00187 }
00188
00189 void
00190 Standard_Event_Persistence_Factory::preallocate_next_record(
00191 ACE_UINT64& current_serial_number,
00192 Persistent_Storage_Block*& current_psb,
00193 ACE_UINT64& next_serial_number,
00194 ACE_UINT32& next_block_number)
00195 {
00196
00197
00198 current_serial_number = this->serial_number_;
00199 this->psb_->set_allocator_owns(false);
00200 this->psb_->set_sync();
00201 current_psb = this->psb_;
00202 this->get_preallocated_pointer (next_serial_number, next_block_number);
00203 }
00204
00205 void
00206 Standard_Event_Persistence_Factory::get_preallocated_pointer(
00207 ACE_UINT64& next_serial_number,
00208 ACE_UINT32& next_block_number)
00209 {
00210 ++this->serial_number_;
00211 this->psb_ = this->allocator_.allocate();
00212
00213 next_serial_number = this->serial_number_;
00214 next_block_number = ACE_Utils::truncate_cast<ACE_UINT32> (this->psb_->block_number());
00215 }
00216
00217 Persistent_File_Allocator*
00218 Standard_Event_Persistence_Factory::allocator()
00219 {
00220 return &this->allocator_;
00221 }
00222
00223 Routing_Slip_Persistence_Manager &
00224 Standard_Event_Persistence_Factory::root()
00225 {
00226 return this->root_;
00227 }
00228
00229 }
00230
00231 TAO_END_VERSIONED_NAMESPACE_DECL
00232
00233 ACE_FACTORY_NAMESPACE_DEFINE (TAO_Notify_Serv,
00234 TAO_Notify_Standard_Event_Persistence,
00235 TAO_Notify::Standard_Event_Persistence)