transaction.h

00001 /***************************************************************
00002  *
00003  * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
00004  * University of Wisconsin-Madison, WI.
00005  * 
00006  * Licensed under the Apache License, Version 2.0 (the "License"); you
00007  * may not use this file except in compliance with the License.  You may
00008  * obtain a copy of the License at
00009  * 
00010  *    http://www.apache.org/licenses/LICENSE-2.0
00011  * 
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  *
00018  ***************************************************************/
00019 
00020 
00021 #ifndef __CLASSAD_TRANSACTION_H__
00022 #define __CLASSAD_TRANSACTION_H__
00023 
00024 #include <list>
00025 #include <string>
00026 #include "classad/sink.h"
00027 #include "classad/view.h"
00028 
00029 class Sock;
00030 
00031 BEGIN_NAMESPACE( classad )
00032 
00033 class ClassAd;
00034 class ClassAdCollection;
00035     
00036 class XactionRecord {
00037 public:
00038     XactionRecord( ) { op = -1; key = ""; rec = 0; }
00039     bool operator==( const XactionRecord & ) const { return false; }
00040     bool operator< ( const XactionRecord & ) const { return false; }
00041 
00042     int     op;
00043     std::string key;
00044     ClassAd *rec;
00045     ClassAd *backup;
00046 };
00047 
00048 typedef std::list<XactionRecord> CollectionOpList;
00049 
00050 class ServerTransaction {
00051 public:
00052     ServerTransaction( );
00053     ~ServerTransaction( );
00054 
00055     inline void SetCollectionServer( ClassAdCollection *c ) { server=c; }
00056     inline void GetCollectionServer( ClassAdCollection *&c ){ c=server; } 
00057     inline void SetXactionName( const std::string &n ) { xactionName = n; }
00058     inline void GetXactionName(std::string &n ) const { n = xactionName; }
00059     inline void SetLocalXaction( bool l ) { local = l; }
00060     inline bool GetLocalXaction( ) const { return( local ); }
00061 
00062     void ClearRecords( );
00063     void AppendRecord( int, const std::string &, ClassAd * );
00064     bool Commit( );
00065     bool Log( FILE *fp, ClassAdUnParser *unp );
00066     ClassAd *ExtractErrorCause( );
00067 
00068     enum { ABSENT, ACTIVE, COMMITTED };
00069 
00070 private:
00071     std::string             xactionName;
00072     bool                    local;
00073     ClassAdCollection       *server;
00074     CollectionOpList        opList;
00075 
00076     int                     xactionErrno;
00077     std::string             xactionErrMsg;
00078     ClassAd                 *xactionErrCause;
00079 };
00080 
00081 
00082 class ClientTransaction {
00083 public:
00084     ClientTransaction( );
00085     ~ClientTransaction( );
00086 
00087     inline void SetServerAddr( const std::string &a, int p ) { addr=a; port=p; }
00088     inline void GetServerAddr( std::string &a, int &p ) const { a=addr; p=port; }
00089     inline void SetXactionName( const std::string &n ) { xactionName = n; }
00090     inline void GetXactionName( std::string &n ) const { n = xactionName; }
00091     inline void SetXactionState( char s ) { state = s; }
00092     inline char GetXactionState( ) const { return( state ); }
00093 
00094     bool LogCommit( FILE *, ClassAdUnParser *unp );
00095     bool LogAckCommit( FILE *, ClassAdUnParser *unp );
00096     bool LogAbort( FILE *, ClassAdUnParser *unp );
00097 
00098     enum { ACTIVE, PENDING };
00099 
00100 private:
00101     std::string xactionName, addr;
00102     int     port;
00103     char    state;
00104 };
00105 
00106 
00107 END_NAMESPACE
00108 
00109 #endif /* __CLASSAD_TRANSACTION_H__ */
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends