00001 #ifndef _XRC_URLSET_H 00002 #define _XRC_URLSET_H 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C l i e n t U r l S e t . h h */ 00006 /* */ 00007 /* Author: Fabrizio Furano (INFN Padova, 2004) */ 00008 /* Adapted from TXNetFile (root.cern.ch) originally done by */ 00009 /* Alvise Dorigo, Fabrizio Furano, INFN Padova, 2003 */ 00010 /* Revised by G. Ganis, CERN, June 2005 */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00034 // // 00035 // A container for multiple urls to be resolved through DNS aliases // 00036 // // 00038 00039 #include "XrdClient/XrdClientConst.hh" 00040 #include "XrdClient/XrdClientVector.hh" 00041 #include "XrdOuc/XrdOucString.hh" 00042 00043 using namespace std; 00044 00045 class XrdClientUrlInfo; 00046 00047 typedef XrdClientVector<XrdClientUrlInfo*> UrlArray; 00048 00049 // 00050 // Manages a set of XrdClientUrlInfo objects and provides a set 00051 // of utilities to resolve multiple addresses from the dns 00052 // and to pick urls sequentially and randomly an url 00053 // 00054 00055 class XrdClientUrlSet { 00056 private: 00057 UrlArray fUrlArray; 00058 UrlArray fTmpUrlArray; 00059 XrdOucString fPathName; 00060 00061 bool fIsValid; 00062 unsigned int fSeed; 00063 00064 void CheckPort(int &port); 00065 void ConvertDNSAlias(UrlArray& urls, XrdOucString proto, 00066 XrdOucString host, XrdOucString file); 00067 double GetRandom(int seed = 0); 00068 00069 public: 00070 XrdClientUrlSet(XrdOucString urls); 00071 ~XrdClientUrlSet(); 00072 00073 // Returns the final resolved list of servers 00074 XrdOucString GetServers(); 00075 00076 // Gets the subsequent Url, the one after the last given 00077 XrdClientUrlInfo *GetNextUrl(); 00078 00079 // From the remaining urls we pick a random one. Without reinsert. 00080 // i.e. while there are not considered urls, never pick an already seen one 00081 XrdClientUrlInfo *GetARandomUrl(); 00082 // Given a seed, use that to pick an url 00083 // the effect will be that, given the same list, the same seed will pick the same url 00084 XrdClientUrlInfo *GetARandomUrl(unsigned int seed); 00085 00086 void Rewind(); 00087 void ShowUrls(); 00088 void EraseUrl(XrdClientUrlInfo *url); 00089 00090 // Returns the number of urls 00091 int Size() { return fUrlArray.GetSize(); } 00092 00093 // Returns the pathfile extracted from the CTOR's argument 00094 XrdOucString GetFile() { return fPathName; } 00095 00096 bool IsValid() { return fIsValid; } // Spot malformations 00097 00098 }; 00099 #endif