• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

P_CacheHosting.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #ifndef __P_CACHE_HOSTING_H__
00025 #define __P_CACHE_HOSTING_H__
00026 #include "P_Cache.h"
00027 
00028 #define CACHE_MEM_FREE_TIMEOUT     HRTIME_SECONDS(1)
00029 
00030 struct Vol;
00031 struct CacheVol;
00032 
00033 struct CacheHostResult;
00034 struct Cache;
00035 
00036 struct CacheHostRecord
00037 {
00038   int Init(CacheType typ);
00039   int Init(matcher_line *line_info, CacheType typ);
00040   void UpdateMatch(CacheHostResult *r, char *rd);
00041   void Print();
00042   ~CacheHostRecord()
00043   {
00044     ats_free(vols);
00045     ats_free(vol_hash_table);
00046     ats_free(cp);
00047   }
00048 
00049   CacheType type;
00050   Vol **vols;
00051   volatile int good_num_vols;
00052   volatile int num_vols;
00053   int num_initialized;
00054   unsigned short *vol_hash_table;
00055   CacheVol **cp;
00056   int num_cachevols;
00057 
00058   CacheHostRecord():
00059     type(CACHE_NONE_TYPE), vols(NULL), good_num_vols(0), num_vols(0),
00060     num_initialized(0), vol_hash_table(0), cp(NULL), num_cachevols(0)
00061   { }
00062 
00063 };
00064 
00065 void build_vol_hash_table(CacheHostRecord *cp);
00066 
00067 struct CacheHostResult
00068 {
00069   CacheHostRecord *record;
00070 
00071   CacheHostResult()
00072     : record(NULL)
00073   { }
00074 };
00075 
00076 
00077 class CacheHostMatcher
00078 {
00079 public:
00080   CacheHostMatcher(const char * name, CacheType typ);
00081   ~CacheHostMatcher();
00082 
00083   void Match(char const* rdata, int rlen, CacheHostResult *result);
00084   void AllocateSpace(int num_entries);
00085   void NewEntry(matcher_line *line_info);
00086   void Print();
00087 
00088   int getNumElements() const { return num_el; }
00089   CacheHostRecord *getDataArray() const { return data_array; }
00090   HostLookup *getHLookup() const { return host_lookup; }
00091 
00092 private:
00093   static void PrintFunc(void *opaque_data);
00094   HostLookup *host_lookup;      // Data structure to do the lookups
00095   CacheHostRecord *data_array;  // array of all data items
00096   int array_len;                // the length of the arrays
00097   int num_el;                   // the number of itmems in the tree
00098   CacheType type;
00099 };
00100 
00101 class CacheHostTable
00102 {
00103 public:
00104   // Parameter name must not be deallocated before this
00105   //  object is
00106   CacheHostTable(Cache *c, CacheType typ);
00107    ~CacheHostTable();
00108   int BuildTable(const char * config_file_path);
00109   int BuildTableFromString(const char * config_file_path, char *str);
00110   void Match(char const* rdata, int rlen, CacheHostResult *result);
00111   void Print();
00112 
00113   int getEntryCount() const { return m_numEntries; }
00114   CacheHostMatcher *getHostMatcher() const { return hostMatch; }
00115 
00116   static int config_callback(const char *, RecDataT, RecData, void *);
00117 
00118   void register_config_callback(CacheHostTable ** p)
00119   {
00120     REC_RegisterConfigUpdateFunc("proxy.config.cache.hosting_filename", CacheHostTable::config_callback, (void *) p);
00121   }
00122 
00123   CacheType type;
00124   Cache *cache;
00125   int m_numEntries;
00126   CacheHostRecord gen_host_rec;
00127 
00128 private:
00129   CacheHostMatcher *hostMatch;
00130   const matcher_tags *config_tags;
00131   const char *matcher_name;     // Used for Debug/Warning/Error messages
00132 };
00133 
00134 struct CacheHostTableConfig;
00135 typedef int (CacheHostTableConfig::*CacheHostTabHandler) (int, void *);
00136 struct CacheHostTableConfig: public Continuation
00137 {
00138   CacheHostTable **ppt;
00139   CacheHostTableConfig(CacheHostTable ** appt)
00140     : Continuation(NULL), ppt(appt)
00141   {
00142     SET_HANDLER((CacheHostTabHandler) & CacheHostTableConfig::mainEvent);
00143   }
00144 
00145   int mainEvent(int event, Event *e)
00146   {
00147     (void) e;
00148     (void) event;
00149     CacheHostTable *t = new CacheHostTable((*ppt)->cache, (*ppt)->type);
00150     CacheHostTable *old = (CacheHostTable *) ink_atomic_swap(&t, *ppt);
00151     new_Deleter(old, CACHE_MEM_FREE_TIMEOUT);
00152     return EVENT_DONE;
00153   }
00154 };
00155 
00156 
00157 /* list of volumes in the volume.config file */
00158 struct ConfigVol
00159 {
00160   int number;
00161   CacheType scheme;
00162   off_t size;
00163   bool in_percent;
00164   int percent;
00165   CacheVol *cachep;
00166   LINK(ConfigVol, link);
00167 };
00168 
00169 struct ConfigVolumes
00170 {
00171   int num_volumes;
00172   int num_http_volumes;
00173   int num_stream_volumes;
00174   Queue<ConfigVol> cp_queue;
00175   void read_config_file();
00176   void BuildListFromString(char *config_file_path, char *file_buf);
00177 
00178   void clear_all(void)
00179   {
00180     // remove all the volumes from the queue
00181     for (int i = 0; i < num_volumes; i++) {
00182       cp_queue.pop();
00183     }
00184     // reset count variables
00185     num_volumes = 0;
00186     num_http_volumes = 0;
00187     num_stream_volumes = 0;
00188   }
00189 };
00190 
00191 #endif

Generated by  doxygen 1.7.1