ResourcePoolOptions.hh

00001 //********************************************************************
00002 //*** ResourcePool/ResourcePoolOptions.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: ResourcePoolOptions.hh,v 1.23 2009-03-18 14:16:10 mws Exp $
00005 //********************************************************************
00006 /*
00007 This file is part of ResourcePool.
00008 
00009 ResourcePool is free software; you can redistribute it
00010 and/or modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2 of 
00012 the License, or (at your option) any later version.
00013 
00014 ResourcePool is distributed in the hope that it will be
00015 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00016 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with ResourcePool; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00022 02111-1307  USA */
00023 
00024 #ifndef RESOURCEPOOL_RESOURCEPOOLOPTIONS_HH
00025 #define RESOURCEPOOL_RESOURCEPOOLOPTIONS_HH
00026 
00027 #ifndef POSIX_TIME_HH
00028 #include "POSIX/time.hh"
00029 #endif
00030 
00031 #ifndef INCLUDED_EXCEPTIONS_HH
00032 #include "Exceptions/Exception.hh"
00033 #endif
00034 
00035 #ifndef INCLUDED_THREAD_LOCK_HH
00036 #include "Thread/Lock.hh"
00037 #endif
00038 
00039 #include <vector>
00040 #include <string>
00041 
00042 namespace fatalmind {
00046 class ResourcePoolOptions {
00047         typedef POSIX::timespec<SingleThreadedModel<> > timespec_t;
00048         typedef std::vector<POSIX::timespec<SingleThreadedModel<> > >         SleepOnFail_t;
00049 
00050         SleepOnFail_t _SleepOnFail;
00051         int           _Max;
00052         int           _MaxTry;
00053         int           _MaxExecTry;
00054         int           _PreCreate;
00055         timespec_t    _wait;    
00056 
00057     public:
00058         ResourcePoolOptions();  
00059         ~ResourcePoolOptions() {
00060         }
00061 
00067         void setMax(const int a_Max);
00068 
00079         void setMaxTry(const int a_MaxTry);
00080 
00087         void setMaxExecTry(const int a_MaxExecTry);
00088 
00096         void setPreCreate(const int a_PreCreate);
00097 
00138         void setSleepOnFail(const SleepOnFail_t&);
00139         void setSleepOnFail(const float
00140             , const float = -1
00141             , const float = -1
00142             , const float = -1
00143         );
00144         void setWait();
00145         void setWait(const float);
00146 
00147         inline int getPreCreate() const {
00148             return _PreCreate;
00149         }
00150 
00151         inline int getMaxTry() const {
00152             return _MaxTry;
00153         }
00154 
00155         inline int getMaxExecTry() const {
00156             return _MaxExecTry;
00157         }
00158 
00159         inline int getMax() const {
00160             return _Max;
00161         }
00162 
00163         void SleepOnFail(const int) const;
00164 
00165         POSIX::timespec<SingleThreadedModel<> > getSleepOnFail(int tryno) const;
00166 
00167         const timespec_t* getWait() const {
00168             return &_wait;
00169         }
00170 
00171         class IllegalArgumentException: public fatalmind::Exception {
00172             public:
00173                 IllegalArgumentException(const std::string& msg)
00174                 : fatalmind::Exception(msg)
00175                 {
00176                 };
00177         };
00178 
00179         static const ResourcePoolOptions defaultOptions;
00180 };
00181         
00182 } // namespace fatalmind
00183 
00184 #endif

Generated on Mon Nov 9 16:21:24 2009 for ResourcePool by  doxygen 1.5.3