00001 /* 00002 Copyright (c) 2000, The JAP-Team 00003 All rights reserved. 00004 Redistribution and use in source and binary forms, with or without modification, 00005 are permitted provided that the following conditions are met: 00006 00007 - Redistributions of source code must retain the above copyright notice, 00008 this list of conditions and the following disclaimer. 00009 00010 - Redistributions in binary form must reproduce the above copyright notice, 00011 this list of conditions and the following disclaimer in the documentation and/or 00012 other materials provided with the distribution. 00013 00014 - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 00015 may be used to endorse or promote products derived from this software without specific 00016 prior written permission. 00017 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00021 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 00022 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00025 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00027 */ 00028 #ifndef _CA_CACHE_LOAD_BALANCING 00029 #define _CA_CACHE_LOAD_BALANCING 00030 #include "CASocketAddrINet.hpp" 00031 #include "CAMutex.hpp" 00032 00033 struct t_cachelb_list 00034 { 00035 CASocketAddrINet* pAddr; 00036 struct t_cachelb_list* next; 00037 }; 00038 00039 typedef t_cachelb_list CACHE_LB_ENTRY; 00040 00045 class CACacheLoadBalancing 00046 { 00047 public: 00048 CACacheLoadBalancing() 00049 { 00050 m_ElementCount=0; 00051 pSelectedEntry=NULL; 00052 } 00053 ~CACacheLoadBalancing(){clean();} 00054 00056 SINT32 clean() 00057 { 00058 m_csLock.lock(); 00059 CACHE_LB_ENTRY* pEntry; 00060 CACHE_LB_ENTRY* pFirst=pSelectedEntry; 00061 while(pSelectedEntry!=NULL) 00062 { 00063 if(pSelectedEntry->next==pFirst) 00064 pEntry=NULL; 00065 else 00066 pEntry=pSelectedEntry->next; 00067 delete pSelectedEntry->pAddr; 00068 pSelectedEntry->pAddr = NULL; 00069 delete pSelectedEntry; 00070 pSelectedEntry = NULL; 00071 pSelectedEntry=pEntry; 00072 } 00073 m_ElementCount=0; 00074 m_csLock.unlock(); 00075 return E_SUCCESS; 00076 } 00077 00078 SINT32 add(CASocketAddr* const pAddr); 00079 00084 CASocketAddrINet* get() 00085 { 00086 m_csLock.lock(); 00087 if(pSelectedEntry==NULL) 00088 { 00089 m_csLock.unlock(); 00090 return NULL; 00091 } 00092 pSelectedEntry=pSelectedEntry->next; 00093 m_csLock.unlock(); 00094 return pSelectedEntry->pAddr; 00095 } 00096 00097 /* Gets the number of Addresses added. 00098 * @return number of added Addresses 00099 */ 00100 UINT32 getElementCount() 00101 { 00102 return m_ElementCount; 00103 } 00104 00105 private: 00106 CACHE_LB_ENTRY* pSelectedEntry; 00107 UINT32 m_ElementCount; 00108 CAMutex m_csLock; 00109 }; 00110 #endif
1.5.6