1 # cache-timer.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 Timer/Adaptive
32
33 #
34 # A binary exponential backoff timer.
35 #
36 Class Timer/Adaptive/Backoff -superclass Timer/Adaptive
37
38 #
39 # The binary exponential backoff timer constructor. The arguments
40 # <i>c1</i>, <i>c2</i> and <d> control the backoff like this:
41 # [c1*d, (c1+c2)*d].
42 #
43 Timer/Adaptive/Backoff public init { c1 c2 d app } {
44 $self instvar c1_ c2_ d_ app_ i_
45
46 set c1_ $c1
47 set c2_ $c2
48 set d_ $d
49 set app_ $app
50 set i_ 0
51
52 $self next
53 $self start
54 }
55
56 #
57 # Do a binary exponential backoff of the current timer value.
58 #
59 Timer/Adaptive/Backoff private adapt { interval } {
60 $self instvar id_ c1_ c2_ d_ i_
61
62 set t [expr pow(2,$i_) * ([random]/double(0x7fffffff) * ($c2_*$d_) + ($c1_*$d_))]
63 incr i_
64 return $t
65 }
66
67 #
68 # Called when need to backoff the current timer.
69 #
70 Timer/Adaptive/Backoff public backoff { } {
71 $self instvar i_
72
73 # schedule the next backoff, and start implicitly call cancel
74 # if required
75 incr i_
76 $self start
77 }
78
79 #
80 # A url get timer which is backoff exponentially.
81 #
82 Class URL_Get_Timer -superclass Timer/Adaptive/Backoff
83
84 #
85 # The url get timer constructor.
86 #
87 URL_Get_Timer public init { url c1 c2 d app } {
88 $self instvar url_
89 set url_ $url
90
91 $self next $c1 $c2 $d $app
92 }
93
94 #
95 # Called when the timer timeouts. This first does a callback
96 # to the web cache control so it can notify other caches that
97 # it has won the get timer war, and then backoff the get timer.
98 #
99 URL_Get_Timer public timeout { } {
100 $self instvar url_ app_
101
102 # do a callback to the application
103 $app_ send_announcement WC_URL_GET $url_
104 }
105
106 #
107 # A url response timer which is backoff exponentially.
108 #
109 Class URL_Resp_Timer -superclass Timer/Adaptive/Backoff
110
111 #
112 # The url response timer constructor.
113 #
114 URL_Resp_Timer public init { url c1 c2 d app } {
115 $self instvar url_
116 set url_ $url
117
118 $self next $c1 $c2 $d $app
119 }
120
121 URL_Resp_Timer public destroy { } {
122 $self instvar url_
123 #puts "destroy URL_Resp_Timer $url_ $self"
124 $self next
125 }
126
127 #
128 # Called when the timer timeouts. This does a callback to
129 # the web cache control so it can notify other caches that
130 # it is going to send the contents of the url to the session.
131 #
132 URL_Resp_Timer public timeout { } {
133 $self instvar url_ app_
134
135 #puts "wcc: win_resp_timer $url_ $self"
136
137 # send out the data or do a HTTP request to the origin server
138 $app_ win_resp_timer $url_
139 }
140
141
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.