1 # al-hm.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 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/as/al-hm.tcl,v 1.9 2002/02/03 04:25:20 lim Exp $
32
33
34 import AnnounceListenManager/AS
35
36 # Announce listen manager for the host manager (part of AS1)
37 # Author: Elan Amir
38 Class AnnounceListenManager/AS/HM -superclass AnnounceListenManager/AS
39
40 AnnounceListenManager/AS/HM instproc init { agent spec bw } {
41 $self next $spec $bw hm
42 $self set agent_ $agent
43
44 [$self get_timer] threshold 10000
45 }
46
47 AnnounceListenManager/AS/HM instproc recv_msg { atype aspec addr srv_name srv_loc srv_inst ssg_port msg } {
48 $self instvar agent_
49 #$agent_ log ""
50 #$agent_ log "$agent_ hm:recv {$msg}"
51 #$agent_ log ""
52 switch $atype {
53 srv {
54 # nothing
55 }
56 hm {
57 # sname holds the type of the message
58 $self handle_hm_msg $aspec $msg $addr $srv_name $srv_inst
59 }
60 client {
61 set load [HMAgent get_load]
62 set hiload [$self get_option highLoad]
63 if { [$self get_option noLoad] == "" && $load >= $hiload } {
64 $agent_ log "HI LOAD load=$load $hiload"
65 } else {
66 # Wait a couple seconds to prevent any race conditions
67 # between gateway announcement prompted by client
68 # message and hm check.
69 after 2000 $self "handle_client_msg $srv_name \
70 $srv_loc $srv_inst {$msg} [gettimeofday]"
71 }
72 }
73 }
74 }
75
76 AnnounceListenManager/AS/HM instproc duphm { name } {
77 # A duplicate hm - break the tie with pids.
78 if { [string compare $name [$self agent_instance]] < 0 } {
79 $self instvar agent_
80 $agent_ log "duplicate hm: $name [$self agent_instance] - exiting."
81 $agent_ doexit
82 }
83 }
84
85 AnnounceListenManager/AS/HM instproc handle_hm_msg { aspec msg addr srv_name srv_inst } {
86 $self instvar agent_
87 #$agent_ log "hm:recv $srv_name from $addr"
88 switch $srv_name {
89 update {
90 # Check if there's another hm on this host
91 if { $addr == [localaddr] } {
92 $self duphm $aspec
93 }
94 }
95 launch {
96 $agent_ suppress_timer $srv_inst
97 }
98 }
99 }
100
101 AnnounceListenManager/AS/HM instproc handle_client_msg { srv_name srv_loc srv_inst msg ts } {
102 $self instvar agent_
103 if [$agent_ pending_timer $srv_inst] {
104 #$agent_ log "pending"
105 return
106 }
107
108 # If we don't have a record of a gateway for this session,
109 # launch one.
110 $self instvar agentbytype_ agenttab_ lastann_
111 set srvlist $agentbytype_(srv)
112 foreach srvspec $srvlist {
113 set srv $agenttab_($srvspec)
114 set inst [lindex $srv 4]
115 if { $inst == $srv_inst } {
116 set lastann $lastann_($srvspec,abs)
117 #$agent_ log "$lastann [expr $ts - 1]"
118 if { $lastann < $ts - 1 } {
119 #$agent_ log "$self delete_agent $gwspec"
120 $self delete_agent $srvspec
121 break
122 }
123 return
124 }
125 }
126
127 # Can't find a service record. Set launch timer.
128 $agent_ sched_launch $srv_name $srv_loc $srv_inst $msg
129 }
130
131 AnnounceListenManager/AS/HM instproc register { atype aspec addr srv_name srv_inst msg } {
132 $self instvar agent_
133 if { $addr != [localaddr] || $atype != "srv" } {
134 return
135 }
136 $agent_ cancel_timer $srv_inst
137 }
138
139 AnnounceListenManager/AS/HM instproc unregister { atype aspec addr srv_name srv_inst ad } {
140 $self instvar agent_
141 if { $addr != [localaddr] || $atype != "srv" } {
142 return
143 }
144 $agent_ unregister $aspec $ad
145 }
146
147 #
148 # This is really just an optimization since the gateways will kill each
149 # other off - but we must do this or performance will be very bad.
150 #
151 AnnounceListenManager/AS/HM instproc announce_launch { srv_inst } {
152
153 set o "ASCP v[AnnounceListenManager/AS version]"
154 set n hm
155 set o $o\n$n
156 set n [$self agent_instance]
157 set o $o\n$n
158 set n launch
159 set o $o\n$n
160 set n -
161 set o $o\n$n
162 set n $srv_inst
163 set o $o\n$n
164 set n -
165 set o $o\n$n
166
167 $self announce $o
168 }
169
170 #
171 # We build a simple message since we only use this to announce
172 # our presence.
173 AnnounceListenManager/AS/HM instproc send_announcement {} {
174 $self instvar id1_ id2_
175
176 set o "ASCP v[AnnounceListenManager/AS version]"
177 set n hm
178 set o $o\n$n
179 set n [$self agent_instance]
180 set o $o\n$n
181 set n update
182 set o $o\n$n
183 set n -
184 set o $o\n$n
185 set n -
186 set o $o\n$n
187 set n -
188 set o $o\n$n
189
190 $self announce $o
191 }
192
193 AnnounceListenManager/AS/HM instproc hmnum {} {
194 return [llength [$self hmaddrs]]
195 }
196
197 AnnounceListenManager/AS/HM instproc hmaddrs {} {
198 $self instvar agenttab_
199 set aspecs [array names agenttab_]
200
201 foreach aspec $aspecs {
202 set addr [lindex $agenttab_($aspec) 0]
203 # remove duplicate entries
204 set d($addr) 1
205 }
206 return [array names d]
207 }
208
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.