~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/srmv2-cache/cache-control.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # cache-control.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1998-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 
 31 import AnnounceListenManager URL_Get_Timer URL_Resp_Timer
 32 
 33 #
 34 # A control object for the web cache. It takes care of
 35 # communications amoung all caches in a multicast session.
 36 #
 37 Class SRMv2_CacheControl -superclass AnnounceListenManager
 38 
 39 #
 40 # The web cache control control. <i>netspec</i> is the multicast
 41 # address passed to the announce listen manager, and <i>wc</i> is
 42 # the web cache component.
 43 #
 44 SRMv2_CacheControl public init { netspec } {
 45         $self next $netspec
 46 
 47         # default random delay values
 48         $self set get_c1_ 1.0
 49         $self set get_c2_ 2.0
 50         $self set resp_hit_c1_ 1.0
 51         $self set resp_hit_c2_ 2.0
 52         $self set resp_miss_c1_ 2.0
 53         $self set resp_miss_c2_ 3.0
 54         $self set get_d_ 100.0
 55         $self set resp_hit_d_ 100.0
 56         $self set resp_miss_d_ 100.0
 57 }
 58 
 59 #
 60 # Create URL_Get_Timer for <i>url</i>.
 61 #
 62 SRMv2_CacheControl public create_get_timer { url } {
 63         $self instvar gettimer_table_ get_c1_ get_c2_ get_d_ wc_
 64 
 65         # create a URL_Get_Timer
 66         if ![info exists gettimer_table($url)] {
 67                 puts "wcc: create_get_timer $url"
 68                 set gettimer [new URL_Get_Timer $url $get_c1_ $get_c2_ $get_d_ $self]
 69                 set gettimer_table_($url) $gettimer
 70         }
 71 }
 72 
 73 #
 74 # Called when data arrived from the multicast session thereby
 75 # the get and response timers associated with the url need to
 76 # be canceled.
 77 #
 78 SRMv2_CacheControl public cancel_all_timers { url } {
 79         $self instvar wc_ gettimer_table_ resptimer_table_
 80 
 81         puts "wcc: cancel all timers $url"
 82 
 83         # cancel all timers and pending messages associated with the url
 84         if { [info exists gettimer_table_($url)] } {
 85                 $gettimer_table_($url) destroy
 86                 unset gettimer_table_($url)
 87         }
 88         if { [info exists resptimer_table_($url)] } {
 89                 $resptimer_table_($url) destroy
 90                 unset resptimer_table_($url)
 91         }
 92 }
 93 
 94 #
 95 SRMv2_CacheControl public win_resp_timer { url } {
 96         $self instvar wc_ gettimer_table_ resptimer_table_
 97 
 98         # cancel the URL_Resp_Timer
 99         if [info exists resptimer_table_($url)] {
100                 $resptimer_table_($url) destroy
101                 unset resptimer_table_($url)
102         }
103 
104         # backoff the URL_Get_Timer
105         if [info exists gettimer_table_($url)] {
106                 $gettimer_table_($url) backoff
107         }
108 
109         # send a reply pending message
110         $self send_announcement WC_RESP_PEND $url
111 
112         # ask the cache to send data associated with the url
113         $wc_ send_data $url
114 }
115 
116 #
117 # Send messages when timers expire. If a get message is
118 # being sent, this method also set a local resp timer. If
119 # a pending message is being sent, this method also cancel
120 # the assocaited resp timer.
121 #
122 SRMv2_CacheControl public send_announcement { type url { args "" } } {
123         $self instvar resptimer_table_ resp_miss_c1_ resp_miss_c2_ \
124                 resp_miss_d_
125 
126         switch -- $type {
127                 WC_URL_GET {
128                         puts "wcc: announce WC_URL_GET"
129                         $self announce "WC_URL_GET $url"
130 
131                         # should not create multiple get timers for the
132                         # same url. this is ok because we forget about
133                         # the timer in the array once the srm receiver
134                         # all the data.
135                         if ![info exists resptimer_table_($url)] {
136                                 set resptimer_table_($url) \
137                                         [new URL_Resp_Timer $url \
138                                         $resp_miss_c1_ $resp_miss_c2_ \
139                                         $resp_miss_d_ $self]
140                         }
141                 }
142                 WC_RESP_PEND {
143                         puts "wcc: announce WC_RESP_PEND"
144                         $self announce "WC_RESP_PEND $url"
145                 }
146         }
147 }
148 
149 #
150 # Receive messages from other caches. There are currently the
151 # following messages:
152 # WC_URL_GET means that another cache has won the timer war so
153 # this cache should backoff its get timer. At the same time,
154 # it initiates a response timer, which decides which cache will
155 # send the data back to the session.
156 # WC_RESP_PEND means that another cache has won the response
157 # timer war and is currently getting/sending the data. This
158 # cancels the response timer, and backoffs the get timer.
159 #
160 SRMv2_CacheControl public recv_announcement { addr mesg len } {
161         $self instvar gettimer_table_ resptimer_table_ wc_ \
162                 resp_hit_c1_ resp_hit_c2_ resp_miss_c1_ resp_miss_c2_ \
163                 resp_hit_d_ resp_miss_d_
164 
165         puts "wcc: recv $mesg"
166 
167         set type [lindex $mesg 0]
168         set url [lindex $mesg 1]
169 
170         switch -- $type {
171                 WC_URL_GET {
172                         # backoff its own URL_Get_Timer
173                         if [info exists gettimer_table_($url)] {
174                                 $gettimer_table_($url) backoff
175                         }
176 
177                         # check whether it has data in the local cache
178                         if { [$wc_ hit $url] != "" } {
179                                 set c1 $resp_hit_c1_
180                                 set c2 $resp_hit_c2_
181                                 set d $resp_hit_d_
182                         } else {
183                                 set c1 $resp_miss_c1_
184                                 set c2 $resp_miss_c2_
185                                 set d $resp_miss_d_
186                         }
187 
188                         # again, do not create multiple timers, because it
189                         # confuses the destroy timer operation.
190                         if ![info exists resptimer_table_($url)] {
191                                 set resptimer [new URL_Resp_Timer $url $c1 $c2 $d $self]
192                                 set resptimer_table_($url) $resptimer
193                         }
194                 }
195                 WC_RESP_PEND {
196                         # cancel its URL_Resp_Timer
197                         if [info exists resptimer_table_($url)] {
198                                 $resptimer_table_($url) destroy
199                                 unset resptimer_table_($url)
200                         }
201 
202                         # backoff the URL_Get_Timer
203                         if [info exists gettimer_table_($url)] {
204                                 $gettimer_table_($url) backoff
205                         }
206                 }
207         }
208 }
209 
210 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.