00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * \file Event_Persistence_Factory.h 00006 * 00007 * Standard_Event_Persistence.h,v 1.7 2006/03/14 06:14:34 jtc Exp 00008 * 00009 * The standard implementation of Event_Persistence_Factory. 00010 * 00011 * \author Jonathan Pollack <pollack_j@ociweb.com> 00012 */ 00013 //============================================================================= 00014 00015 #ifndef STANDARD_EVENT_PERSISTENCE_H 00016 #define STANDARD_EVENT_PERSISTENCE_H 00017 #include /**/ "ace/pre.h" 00018 #include /**/ "ace/config-all.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 #pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "orbsvcs/Notify/Event_Persistence_Strategy.h" 00025 #include "orbsvcs/Notify/Event_Persistence_Factory.h" 00026 #include "orbsvcs/Notify/Persistent_File_Allocator.h" 00027 #include "orbsvcs/Notify/Routing_Slip_Persistence_Manager.h" 00028 #include <ace/SString.h> 00029 00030 00031 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00032 00033 namespace TAO_Notify 00034 { 00035 static const ACE_UINT32 ROUTING_SLIP_ROOT_BLOCK_NUMBER = 0; 00036 static const ACE_UINT64 ROUTING_SLIP_ROOT_SERIAL_NUMBER = 1; 00037 00038 /// \brief Standard (i.e. default) implementation of Event_Persistence_Factory interface 00039 class TAO_Notify_Serv_Export Standard_Event_Persistence_Factory : 00040 public Event_Persistence_Factory 00041 { 00042 public: 00043 /// Constructor 00044 Standard_Event_Persistence_Factory (); 00045 /// Destructor 00046 virtual ~Standard_Event_Persistence_Factory(); 00047 00048 /// Open persistence file and initialize. 00049 /// /param filename the fully qualified path/name of the file to contain 00050 /// persistent information. 00051 /// /param block_size the size of a physical block on the device containing 00052 /// the file. 00053 bool open (const ACE_TCHAR* filename, ACE_UINT32 block_size = 512); 00054 00055 ////////////////////////////////////////////////////// 00056 // Implement Event_Persistence_Factory virtual methods. 00057 virtual Routing_Slip_Persistence_Manager* 00058 create_routing_slip_persistence_manager(Persistent_Callback* callback); 00059 00060 virtual Routing_Slip_Persistence_Manager * first_reload_manager(); 00061 00062 /// reloading process complete. Where should the chain continue? 00063 void done_reloading( 00064 Persistent_Storage_Block * next_psb, 00065 ACE_UINT64 current_serial_number); 00066 00067 /// return current serial # and a psb containing current record# 00068 /// allocate new serial # and record number, and return those, too. 00069 void preallocate_next_record( 00070 ACE_UINT64& current_serial_number, 00071 Persistent_Storage_Block*& current_psb, 00072 ACE_UINT64& next_serial_number, 00073 ACE_UINT32& next_block_number); 00074 00075 // return block pointer info for the 00076 void get_preallocated_pointer( 00077 ACE_UINT64& next_serial_number, 00078 ACE_UINT32& next_block_number); 00079 00080 /// Accessor for file allocator. 00081 /// Intended for use only by the Routing Slip Persistence Manager 00082 Persistent_File_Allocator* allocator(); 00083 00084 /// Access root record. 00085 /// Intended for use only by the Routing Slip Persistence Manager 00086 Routing_Slip_Persistence_Manager & root(); 00087 00088 public: 00089 ACE_SYNCH_MUTEX lock; 00090 00091 private: 00092 Persistent_File_Allocator allocator_; 00093 Routing_Slip_Persistence_Manager root_; 00094 Persistent_Storage_Block* psb_; 00095 ACE_UINT64 serial_number_; 00096 bool is_reloading_; 00097 }; 00098 00099 /// \brief The standard implementation of the 00100 /// Event_Persistence_Strategy interface. 00101 class TAO_Notify_Serv_Export Standard_Event_Persistence : 00102 public Event_Persistence_Strategy 00103 { 00104 public : 00105 /// Constructor. 00106 Standard_Event_Persistence (); 00107 /// Destructor. 00108 virtual ~Standard_Event_Persistence (); 00109 ///////////////////////////////////////////// 00110 // Override Event_Persistent_Strategy methods 00111 // Parse arguments and initialize. 00112 virtual int init(int argc, ACE_TCHAR *argv[]); 00113 // Prepare for shutdown 00114 virtual int fini (); 00115 00116 // get the current factory, creating it if necessary 00117 virtual Event_Persistence_Factory * get_factory (); 00118 00119 private: 00120 // release the current factory so a new one can be created 00121 virtual void reset (); 00122 00123 ACE_TString filename_; // set via -file_path 00124 ACE_UINT32 block_size_; // set via -block_size 00125 Standard_Event_Persistence_Factory * factory_; 00126 }; 00127 } 00128 00129 TAO_END_VERSIONED_NAMESPACE_DECL 00130 00131 ACE_FACTORY_DECLARE (TAO_Notify_Serv, TAO_Notify_Standard_Event_Persistence) 00132 00133 #include /**/ "ace/post.h" 00134 #endif /* STANDARD_EVENT_PERSISTENCE_H */