Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbBdbObjectVisitorUserAction.hh

Go to the documentation of this file.
00001 #ifndef CDBBDB_OBJECT_VISITOR_USER_ACTION_HH
00002 #define CDBBDB_OBJECT_VISITOR_USER_ACTION_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbBdbObjectVisitorUserAction.hh,v 1.3 2004/10/21 20:35:51 gapon Exp $
00006 
00007 #include "CdbBase/CdbCommon.hh"
00008 
00009 #include <oo.h>     // ooRef(ooObj), ooHandle(ooObj)
00010 
00011 #include <string>
00012 #include <vector>
00013 #include <map>
00014 #include <list>
00015 
00016 class CdbBdbObjectVisitorContext;
00017 
00018 /// The base class for user defined actions
00019 /**
00020   * This base class has to implemented by users willing to control
00021   * the "visitor" navigation in complex graphs.
00022   * 
00023   * IMPLEMENTATION NOTES:
00024   *
00025   *   (1) This class violates CDB API convention on the inclusion
00026   *       of "CdbBase/CdbCommon.hh" header file to avoid STD namespace
00027   *       conflicts of the kind described above.
00028   */
00029 class CdbBdbObjectVisitorUserAction {
00030 
00031 public:
00032 
00033   /// These values will be used to indicate the user's response
00034 
00035     typedef enum { ACTION_PROCEED,
00036                    ACTION_STOP,
00037                    ACTION_ERROR } ActionType;
00038 
00039   /// Total number of databases in a federation
00040   /**
00041     * This value defined the limits [0..MAX_DATABASE] for certain
00042     * operations involving database iderntifiers.
00043     */
00044     enum { MAX_DATABASE = 0xFFFF };
00045 
00046 public:
00047 
00048   /// The constructor
00049   /**
00050     * An optional file with a list of "known" patterns to be ignored/suppressed
00051     * may be passed to the constructor. The file (if present) would be analysed
00052     * and loaded into intyernal data structures. If something wrong happends during
00053     * the file's translation then a run time assertion would happen.
00054     *
00055     * It's also possible to specify a list of DBID-s to be avoided. These databases
00056     * (if any) would not be checked for validity.
00057     */
00058     CdbBdbObjectVisitorUserAction(                const char* theSupressFile = 0,
00059                                    const std::list<d_UShort>* theDatabasesToIgnore = 0,
00060                                              bool verboseMode = false,
00061                                                bool debugMode = false );
00062 
00063   /// The destructor
00064   /**
00065     * Moe details...
00066     */
00067     virtual ~CdbBdbObjectVisitorUserAction( );
00068 
00069   /// Let a user to make a decision on what has to be done next
00070   /**
00071     * This wrapper method takes the "about-to-be-visited" link on the input. Ths link
00072     * is evaluated by the method to report what's the next action should be.
00073     *
00074     * The second parameter passed town to the operation is the current context
00075     * description in which the link has to be evaluated.
00076     *
00077     * Here is the explanation of possible responses:
00078     *
00079     *   ACTION_PROCEED : a caller has to proceed and visit this node.
00080     *
00081     *   ACTION_STOP    : a caller should stop and not to propagate along this link.
00082     *
00083     *   ACTION_ERROR   : an error has happened inside the method. Normally the caller
00084     *                    should stop visiting any further links.
00085     *
00086     * HOW IT WORKS:
00087     *
00088     *   - first of all this method will verify if the passed object is valid and take
00089     *     the following actions if it's not:
00090     *
00091     *     -- check if the object's context matches one of the known patterns (if any).
00092     *        and if not then print diagnostic message (in verbose/debug modes)
00093     *        and update internal statistics for missing/corrupted databases.
00094     *        The action returned in this case would be ACTION_ERROR.
00095     *
00096     *     -- otherwise the internal statistics would not be updated (although
00097     *        an informational message in verbose mode saying that the problem
00098     *        of the missing objects has been ignored due to known pattern would be
00099     *        still printed.) and the method would return ACTION_STOP.
00100     *
00101     *   - in the end if the passed object is valid then a user defined "userAction"
00102     *     application's object will be called to let a user to proceed with his/her
00103     *     decision in a specific context.
00104     *
00105     * @see CdbBdbObjectVisitorUserAction::userAction()
00106     * @see class CdbBdbObjectVisitorContext
00107     */
00108     ActionType action(            const ooHandle(ooObj)& theInputH,
00109                        const CdbBdbObjectVisitorContext* theContext );
00110 
00111 
00112   /// Print the internal counters and table onto the Standard Output
00113   /**
00114     * This method will print all statistics information accumulated by
00115     * the current user object onto the Standard Output. This includes a list
00116     * of missing databases and their clients.
00117     *
00118     * This method can be overriden by a subclass to add up extra information
00119     * accumulated by the subclass.
00120     */
00121     virtual void print_statistics( ) const;
00122 
00123   /// Get the total number of objects visited
00124 
00125     unsigned long totalObjects( ) const { return _totalObjects; }
00126 
00127   /// Get the number of invalid objects found
00128 
00129     unsigned long invalidObjects( ) const { return _invalidObjects; }
00130 
00131 
00132   /// Get the number of times the specified database was found missing
00133   /**
00134     * The number returned by this method would be either 0 or a positive number.
00135     * Returning 0 does not mean that specified databases exsists, it just means
00136     * that the databases has not been found missing (noone attempted to use it).
00137     *
00138     * The database identifier must be a in the valid range [0..64k]. Otherwise
00139     * a run time assertion would occure.
00140     */
00141     unsigned int missedCounters( d_UShort theDatabaseId ) const;
00142 
00143   /// Get clients of specified missing database
00144   /**
00145     * The result of this procedure would be either a 0 pointer or a const pointer
00146     * onto a map with DBID-s and system names of clients. The map object itself
00147     * would be located at a a user action object.
00148     *
00149     * WARNING: This method does not return the ownership of teh map object.
00150     *
00151     * The database identifier must be a in the valid range [0..64k]. Otherwise
00152     * a run time assertion would occure.
00153     */
00154     const std::map<d_UShort,std::string>* missedDatabaseClients( d_UShort theDatabaseId ) const;
00155 
00156 protected:
00157 
00158   /// Let a user to make a decision on what has to be done next (ACTUAL USER ACTION)
00159   /**
00160     * This method gets called only for valid objects.
00161     *
00162     * IMPLEMENTATION NOTE: In its default implementation this method would always
00163     *                      return ACTION_PROCEED. This behaviour can be overriten
00164     *                      by specific subclasses.
00165     *
00166     * @see CdbBdbObjectVisitorUserAction::action()
00167     * @see class CdbBdbObjectVisitorContext
00168     */
00169     virtual ActionType userAction(            const ooHandle(ooObj)& theInputH,
00170                                    const CdbBdbObjectVisitorContext* theContext );
00171 
00172 private:
00173 
00174   /// Update a list of clients (databases) reffering a missing one
00175   /**
00176     * Each client is represented as pair of <DBID> <DATBASE SYSTEM NAME>.
00177     *
00178     * The algorithm also uses an object-scope dictionary to avoid
00179     * multiple translations of the DBID.
00180     */
00181     bool update_missing_database_clients_list(  std::map<d_UShort,std::string>*& theClients,
00182                                                const CdbBdbObjectVisitorContext* theContext );
00183 
00184 private:
00185 
00186   // Parameters
00187 
00188     bool _verboseMode;
00189     bool _debugMode;
00190 
00191     std::vector<CdbBdbObjectVisitorContext*> _patternsToIgnore;
00192     bool                                     _databasesToIgnore[MAX_DATABASE + 1];
00193 
00194   // Statisticts
00195 
00196     unsigned long _totalObjects;
00197     unsigned long _invalidObjects;
00198 
00199     unsigned int                    _missingDatabase         [MAX_DATABASE + 1];
00200     std::map<d_UShort,std::string>* _clientsOfMissingDatabase[MAX_DATABASE + 1];
00201 
00202   // A dictionary meant to translate DBID-s of existing databases into
00203   // their name.
00204 
00205     std::string _dbidToName[MAX_DATABASE + 1];
00206 };
00207 
00208 #endif  // CDBBDB_OBJECT_VISITOR_USER_ACTION_HH

Generated on Mon Dec 5 18:22:00 2005 for CDB by doxygen1.3-rc3