1 # distrib_rec_agent.tcl --
2 #
3 # FIXME: This file needs a description here.
4 #
5 # Copyright (c) 1999-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/applications/pathfinder/distrib_rec_agent.tcl,v 1.4 2002/02/03 04:22:06 lim Exp $
32
33
34 import Rec_Agent ArchiveSystem/Record/Monitored Observer AnnounceListenManager/AS/Client/Aries
35
36 Class Rec_Agent/Distrib -superclass {Rec_Agent Observer}
37
38 # start a local recorder and requested distrib recorders
39 Rec_Agent/Distrib private start_recording { program } {
40
41 mtrace trcNet "-> Starting recorder"
42 $self instvar archive_ archive_array_ start_status_array_ \
43 module_array_ schedule_array_ active_platforms_
44
45 set key [get_key $program]
46
47 # Use a timestamp for the module name and add the module to the
48 # module_array_.
49 set module [string trim [clock clicks] -]
50 set module_array_($key) $module
51
52 # Use the ArchiveSystem/Record class for recording and write
53 # the SDP Program information to the catalog file.
54 set archive_sys [new ArchiveSystem/Record/Monitored]
55 $archive_sys attach_observer $self
56 $archive_sys open $archive_ $module
57 $archive_sys write_announcement $program
58
59 # Write relevant recording information to the catalog file
60 set current [$self readable_time [clock seconds]]
61 set info "record_start=$current"
62 $archive_sys write_info $info
63
64 # Request a notification if the recording quality falls below
65 # a threshold.
66 set drop_rate 5 ; # Threshold is a 5% drop rate
67 $archive_sys set_thresh $drop_rate
68
69 # Begin recording and add the archive_sys object to the
70 # archive_array_ so that the recording can later be stopped.
71 $archive_sys record_program $program $module
72 set archive_array_($key,local) $archive_sys
73
74 # start requested distributed recorders
75 if [info exists active_platforms_($key)] {
76 foreach p $active_platforms_($key) {
77
78 $self add_recorder $program $p
79
80 }
81 }
82
83 # Update the start-status array.
84 set start_status_array_($key) "Recording"
85
86 # Update the schedule array by deleting the entry for this
87 # program, if the entry exists.
88 # ???
89 set exists [array names schedule_array_ $key]
90 if { $exists != "" } {
91 # ???
92 }
93 }
94
95
96
97 #
98 Rec_Agent/Distrib public return_distrib_status { key } {
99 $self instvar active_platforms_ archive_array_
100
101 set status {}
102 if [info exists active_platforms_($key)] {
103 foreach p $active_platforms_($key) {
104 lappend status $archive_array_($key,$p)
105 }
106 }
107 return $status
108
109 }
110
111 # Called by ArchiveSystem to report an error rate above the threshold
112 # set by monitor_quality
113 Rec_Agent/Distrib public low_quality {program loc} {
114
115
116 if {[$self get_option allow_distrib] == "yes" } {
117 # Need to check that loc is valid
118 $self add_recorder $program $loc
119 }
120 }
121
122 # Called by ArchiveSystem to report an error rate below the threshold
123 # set by monitor_quality
124 Rec_Agent/Distrib public higher_quality {program loc} {
125
126 $self instvar active_platforms_ archive_array_
127
128 if {[$self get_option allow_distrib] == "yes" } {
129 set key [get_key $program]
130 if [info exists archive_array_($key,$loc)] {
131 delete $archive_array_($key,$loc)
132 unset archive_array_($key,$loc)
133 }
134 # remove loc from active_platforms list
135 set index [lsearch -exact $active_platforms_($key) $loc]
136 if {$index != -1} {
137 set active_platforms_($key) [lreplace $active_platforms_($key) $index $index]
138 }
139 if {[llength $active_platforms_($key)] == 0} {
140 unset active_platforms_($key)
141 }
142 }
143
144 }
145
146
147 # Add a distributed recorder
148 Rec_Agent/Distrib private add_recorder {program platform} {
149 $self instvar archive_ archive_array_ start_status_array_ \
150 schedule_array_ active_platforms_
151
152 set key [get_key $program]
153 if {[info exists archive_array_($key,$platform)]} {
154 return
155
156 } else {
157 mtrace trcNet "-> Starting another recorder"
158
159 lappend active_platforms_($key) $platform
160 set start_status $start_status_array_($key)
161 if [string match *Recording* $start_status] {
162 set archive_agent [new AnnounceListenManager/AS/Client/Aries $platform 20000 "urn:aries" [[$program base] obj2str]]
163 $archive_agent start
164 set archive_array_($key,$platform) $archive_agent
165 }
166 #after 1000 "$self begin_collection $key $platform"
167
168 }
169 }
170
171
172
173 #
174 # The stop_recording method stops the recording of the specified
175 # Program. If the recording has not yet begun, the scheduled recording
176 # is cancelled.
177 #
178 Rec_Agent/Distrib public stop_recording { program } {
179 $self instvar active_platforms_ archive_array_
180
181 $self next $program
182
183 # Stop the distrib recordings by deleting the archive_sys object.
184
185 set key [get_key $program]
186 if [info exists active_platforms_($key)] {
187 foreach p $active_platforms_($key) {
188 delete $archive_array_($key,$p)
189 unset archive_array_($key,$p)
190 }
191 unset active_platforms_($key)
192 }
193 }
194
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.