Main Page | Class Hierarchy | Class List | File List | Class Members

transaction.h

00001 /*********************************************************************
00002  *
00003  * Condor ClassAd library
00004  * Copyright (C) 1990-2003, Condor Team, Computer Sciences Department,
00005  * University of Wisconsin-Madison, WI and Rajesh Raman.
00006  *
00007  * This source code is covered by the Condor Public License, which can
00008  * be found in the accompanying LICENSE file, or online at
00009  * www.condorproject.org.
00010  *
00011  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00012  * AND THE UNIVERSITY OF WISCONSIN-MADISON "AS IS" AND ANY EXPRESS OR
00013  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00014  * WARRANTIES OF MERCHANTABILITY, OF SATISFACTORY QUALITY, AND FITNESS
00015  * FOR A PARTICULAR PURPOSE OR USE ARE DISCLAIMED. THE COPYRIGHT
00016  * HOLDERS AND CONTRIBUTORS AND THE UNIVERSITY OF WISCONSIN-MADISON
00017  * MAKE NO MAKE NO REPRESENTATION THAT THE SOFTWARE, MODIFICATIONS,
00018  * ENHANCEMENTS OR DERIVATIVE WORKS THEREOF, WILL NOT INFRINGE ANY
00019  * PATENT, COPYRIGHT, TRADEMARK, TRADE SECRET OR OTHER PROPRIETARY
00020  * RIGHT.
00021  *
00022  *********************************************************************/
00023 
00024 #ifndef __XACTION_H__
00025 #define __XACTION_H__
00026 
00027 #include <list>
00028 #include <string>
00029 #include "sink.h"
00030 #include "view.h"
00031 
00032 BEGIN_NAMESPACE( classad )
00033 
00034 class ClassAd;
00035 class ClassAdCollection;
00036         
00037 class XactionRecord {
00038 public:
00039         XactionRecord( ) { op = -1; key = ""; rec = 0; }
00040         bool operator==( const XactionRecord &xrec ) { return false; }
00041         bool operator< ( const XactionRecord &xrec ) { return false; }
00042 
00043         int     op;
00044         std::string     key;
00045         ClassAd *rec;
00046         ClassAd *backup;
00047 };
00048 
00049 typedef std::list<XactionRecord> CollectionOpList;
00050 
00051 class ServerTransaction {
00052 public:
00053         ServerTransaction( );
00054         ~ServerTransaction( );
00055 
00056         inline void SetCollectionServer( ClassAdCollection *c ) { server=c; }
00057         inline void GetCollectionServer( ClassAdCollection *&c ){ c=server; } 
00058         inline void SetXactionName( const std::string &n ) { xactionName = n; }
00059         inline void GetXactionName(std::string &n ) const { n = xactionName; }
00060         inline void SetLocalXaction( bool l ) { local = l; }
00061         inline bool GetLocalXaction( ) const { return( local ); }
00062 
00063         void ClearRecords( );
00064         void AppendRecord( int, const std::string &, ClassAd * );
00065         bool Commit( );
00066         bool Log( FILE *fp, ClassAdUnParser *unp );
00067         ClassAd *ExtractErrorCause( );
00068 
00069         enum { ABSENT, ACTIVE, COMMITTED };
00070 
00071 private:
00072         std::string                             xactionName;
00073         bool                                    local;
00074         ClassAdCollection       *server;
00075         CollectionOpList                opList;
00076 
00077         int                                             xactionErrno;
00078         std::string                             xactionErrMsg;
00079         ClassAd                                 *xactionErrCause;
00080 };
00081 
00082 
00083 class Sock;
00084 
00085 class ClientTransaction {
00086 public:
00087         ClientTransaction( );
00088         ~ClientTransaction( );
00089 
00090         inline void SetServerAddr( const std::string &a, int p ) { addr=a; port=p; }
00091         inline void GetServerAddr( std::string &a, int &p ) const { a=addr; p=port; }
00092         inline void SetXactionName( const std::string &n ) { xactionName = n; }
00093         inline void GetXactionName( std::string &n ) const { n = xactionName; }
00094         inline void SetXactionState( char s ) { state = s; }
00095         inline char GetXactionState( ) const { return( state ); }
00096 
00097         bool LogCommit( FILE *, ClassAdUnParser *unp );
00098         bool LogAckCommit( FILE *, ClassAdUnParser *unp );
00099         bool LogAbort( FILE *, ClassAdUnParser *unp );
00100 
00101         enum { ACTIVE, PENDING };
00102 
00103 private:
00104         std::string     xactionName, addr;
00105         int             port;
00106         char    state;
00107 };
00108 
00109 
00110 END_NAMESPACE
00111 
00112 #endif /* __XACTION_H__ */