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