Back to index

nordugrid-arc-nox  1.1.0~rc6
IntraProcessCounter.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 // IntraProcessCounter.h
00004 
00005 #ifndef __IntraProcessCounter__
00006 #define __IntraProcessCounter__
00007 
00008 #include <map>
00009 #include <queue>
00010 
00011 #include <arc/Thread.h>
00012 
00013 #include "Counter.h"
00014 
00015 namespace Arc {
00016 
00018 
00022   class IntraProcessCounter
00023     : public Counter {
00024 
00025   public:
00026 
00028 
00035     IntraProcessCounter(int limit, int excess);
00036 
00038 
00041     virtual ~IntraProcessCounter();
00042 
00044 
00049     virtual int getLimit();
00050 
00052 
00056     virtual int setLimit(int newLimit);
00057 
00059 
00064     virtual int changeLimit(int amount);
00065 
00066 
00068 
00072     virtual int getExcess();
00073 
00075 
00079     virtual int setExcess(int newExcess);
00080 
00082 
00087     virtual int changeExcess(int amount);
00088 
00090 
00099     virtual int getValue();
00100 
00102 
00116     virtual CounterTicket reserve(int amount = 1,
00117                                   Glib::TimeVal duration = ETERNAL,
00118                                   bool prioritized = false,
00119                                   Glib::TimeVal timeOut = ETERNAL);
00120 
00121   protected:
00122 
00123 
00125 
00130     virtual void cancel(IDType reservationID);
00131 
00133 
00146     virtual void extend(IDType& reservationID,
00147                         Glib::TimeVal& expiryTime,
00148                         Glib::TimeVal duration = ETERNAL);
00149 
00150   private:
00151 
00153 
00157     IntraProcessCounter(const IntraProcessCounter& unique);
00158 
00160 
00165     void operator=(const IntraProcessCounter& unique);
00166 
00168 
00174     int unsafeGetValue();
00175 
00177 
00187     int unsafeCancel(IDType reservationID);
00188 
00190 
00201     IDType unsafeReserve(int amount, Glib::TimeVal duration);
00202 
00204 
00209     Glib::TimeVal unsafeGetNextExpiration();
00210 
00212 
00215     int limit;
00216 
00218 
00221     int excess;
00222 
00224 
00227     int value;
00228 
00230 
00236     IDType nextReservationID;
00237 
00239 
00242     std::map<IDType, int> reservations;
00243 
00245 
00249     std::priority_queue<ExpirationReminder> selfExpiringReservations;
00250 
00252 
00256     Glib::Mutex synchMutex;
00257 
00259 
00263     Glib::Cond synchCond;
00264 
00265   };
00266 
00267 }
00268 
00269 #endif