1 # imgr-service.tcl --
2 #
3 # An encapsulation of a remote service.
4 #
5 # Copyright (c) 1996-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/indiva/imgr/imgr-servent.tcl,v 1.1 2002/07/22 21:14:57 weitsang Exp $
32
33 #--------------------------------------------------------------------------
34 # Class:
35 # IMgrServent
36 #
37 # Description:
38 # IMgrServent encapsulates a service inside Indiva Domain. Each
39 # IMgrServent is uniquely identified by a $service_instance, contains
40 # an RPC socket to the remote service, a MashRemoteObject to
41 # remote service, and an ASCP object that runs ASCP protocol between
42 # imgr and the service.
43 #
44 # IMgr objects are created during service registration and is deleted
45 # when service is deregistered.
46 #
47 # Members:
48 # rpc_ -- RPC socket to service.
49 # ctrl_ -- MashRemoteObject of a remote service object (instance of
50 # a IndivaServent subclass.)
51 # ascp_ -- instance of IMgrASCP subclass, responsible for running
52 # ASCP protocol. Restarts service when timeout occurs.
53 #--------------------------------------------------------------------------
54 import MashRemoteObject
55
56 Class IMgrServent
57
58 IMgrServent public init {si sock app} {
59 $self set rpc_ $sock
60 $self set id_ $si
61 $self set app_ $app
62
63 # Servents usually register themselves before create a service object.
64 # Therefore, at this point, they probably do not have a service object
65 # yet. We cannot RMI get_service here.
66 $self set ctrl_ ""
67 }
68
69 IMgrServent public destroy {} {
70 $self instvar ctrl_
71 if {$ctrl_ != ""} {
72 delete $ctrl_
73 }
74 }
75
76 IMgrServent public socket {} {
77 return [$self set rpc_]
78 }
79
80 IMgrServent public instance {} {
81 return [$self set id_]
82 }
83
84 IMgrServent public control {} {
85 MashLog warn "$class $proc deprecated"
86 uplevel {MashLog warn "called from $class $proc"}
87 $self instvar ctrl_ rpc_ id_ app_
88 if {$ctrl_ == ""} {
89 set ctrl_ [new MashRemoteObject $rpc_ eval $app_ get_service $id_]
90 }
91 return $ctrl_
92 }
93
94 IMgrServent public create_service {} {
95 $self instvar rpc_ id_ app_ services_
96 set service [new MashRemoteObject $rpc_ eval $app_ new_service]
97 lappend services_ $service
98 return $service
99 }
100
101 IMgrServent public delete_service {service} {
102 $self instvar services_
103 set pos [lsearch $services_ $service]
104 if {$pos != -1} {
105 set services_ [lreplace $services_ $pos $pos]
106 }
107 }
108
109
110 IMgrServent public num_of_services {} {
111 $self instvar services_
112 return [llength $services_]
113 }
114
115 IMgrServent public ascp {args} {
116 if {$args == ""} {
117 return [$self set ascp_]
118 } else {
119 $self set ascp_ $args
120 }
121 }
122
123 IMgrServent public is_alive {} {
124 $self instvar rpc_
125 if {[catch {eof $rpc_} err]} {
126 MashLog warn "socket to remote service is dead: $err"
127 return 0
128 } else {
129 return 1
130 }
131 }
132
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.