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

HttpCacheSM.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 /****************************************************************************
00025 
00026    HttpCacheSM.h
00027 
00028    Description:
00029 
00030 
00031  ****************************************************************************/
00032 
00033 #ifndef _HTTP_CACHE_SM_H_
00034 #define _HTTP_CACHE_SM_H_
00035 
00036 #include "P_Cache.h"
00037 #include "StatSystem.h"
00038 #include "ProxyConfig.h"
00039 #include "URL.h"
00040 #include "HTTP.h"
00041 #include "HttpConfig.h"
00042 
00043 class HttpSM;
00044 class HttpCacheSM;
00045 class CacheLookupHttpConfig;
00046 
00047 struct HttpCacheAction:public Action
00048 {
00049   HttpCacheAction();
00050   virtual void cancel(Continuation * c = NULL);
00051   void init(HttpCacheSM * sm_arg)
00052   {
00053     sm = sm_arg;
00054   };
00055   HttpCacheSM *sm;
00056 };
00057 
00058 class HttpCacheSM:public Continuation
00059 {
00060 public:
00061   HttpCacheSM();
00062 
00063   void init(HttpSM * sm_arg, ProxyMutex * amutex)
00064   {
00065     master_sm = sm_arg;
00066     mutex = amutex;
00067     captive_action.init(this);
00068   }
00069 
00070   Action *open_read(URL * url, HTTPHdr * hdr, CacheLookupHttpConfig * params, time_t pin_in_cache);
00071 
00072   Action *open_write(URL * url,
00073                      HTTPHdr * request, CacheHTTPInfo * old_info, time_t pin_in_cache, bool retry, bool allow_multiple);
00074 
00075   CacheVConnection *cache_read_vc;
00076   CacheVConnection *cache_write_vc;
00077 
00078   bool read_locked;
00079   bool write_locked;
00080   // Flag to check whether read-while-write is in progress or not
00081   bool readwhilewrite_inprogress;
00082 
00083   HttpSM *master_sm;
00084   Action *pending_action;
00085 
00086   //Function to set readwhilewrite_inprogress flag
00087   inline void set_readwhilewrite_inprogress(bool value)
00088   {
00089     readwhilewrite_inprogress = value;
00090   }
00091 
00092   //Function to get the readwhilewrite_inprogress flag
00093   inline bool is_readwhilewrite_inprogress()
00094   {
00095     return readwhilewrite_inprogress;
00096   }
00097 
00098   inline void abort_read()
00099   {
00100     if (cache_read_vc) {
00101       HTTP_DECREMENT_DYN_STAT(http_current_cache_connections_stat);
00102       cache_read_vc->do_io(VIO::ABORT);
00103       cache_read_vc = NULL;
00104     }
00105   }
00106   inline void abort_write()
00107   {
00108     if (cache_write_vc) {
00109       HTTP_DECREMENT_DYN_STAT(http_current_cache_connections_stat);
00110       cache_write_vc->do_io(VIO::ABORT);
00111       cache_write_vc = NULL;
00112     }
00113   }
00114   inline void close_write()
00115   {
00116     if (cache_write_vc) {
00117       HTTP_DECREMENT_DYN_STAT(http_current_cache_connections_stat);
00118       cache_write_vc->do_io(VIO::CLOSE);
00119       cache_write_vc = NULL;
00120     }
00121   }
00122   inline void close_read()
00123   {
00124     if (cache_read_vc) {
00125       HTTP_DECREMENT_DYN_STAT(http_current_cache_connections_stat);
00126       cache_read_vc->do_io(VIO::CLOSE);
00127       cache_read_vc = NULL;
00128     }
00129   }
00130   inline void end_both()
00131   {
00132     // We close the read so that cache
00133     //   records its stats
00134     close_read();
00135     abort_write();
00136   }
00137   inline URL *get_lookup_url()
00138   {
00139     return lookup_url;
00140   }
00141   inline void set_lookup_url(URL * url)
00142   {
00143     lookup_url = url;
00144   }
00145 
00146 private:
00147 
00148   void do_schedule_in();
00149   Action *do_cache_open_read();
00150 
00151   int state_cache_open_read(int event, void *data);
00152   int state_cache_open_write(int event, void *data);
00153 
00154   HttpCacheAction captive_action;
00155   bool open_read_cb;
00156   bool open_write_cb;
00157 
00158   // Open read parameters
00159   int open_read_tries;
00160   HTTPHdr *read_request_hdr;
00161   CacheLookupHttpConfig *read_config;
00162   time_t read_pin_in_cache;
00163 
00164   // Open write parameters
00165   bool retry_write;
00166   int open_write_tries;
00167 
00168   // Common parameters
00169   URL *lookup_url;
00170 
00171   // to keep track of multiple cache lookups
00172   int lookup_max_recursive;
00173   int current_lookup_level;
00174 };
00175 
00176 #endif

Generated by  doxygen 1.7.1