Debian Codegraph @

lib/ClusterShell/Event.py

raw symbols SCIP
1 #
2 # Copyright (C) 2007-2015 CEA/DAM
3 # Copyright (C) 2015-2022 Stephane Thiell <[email protected]>
4 #
5 # This file is part of ClusterShell.
6 #
7 # ClusterShell is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # ClusterShell is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with ClusterShell; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21 """
22 ClusterShell Event handling.
23
24 This module contains the base class :class:`.EventHandler` which defines
25 a simple interface to handle events generated by :class:`.Worker`,
26 :class:`.EngineTimer` and :class:`.EnginePort` objects.
27 """
28
29
30 class EventHandler(object):
31 """ClusterShell EventHandler interface.
32
33 Derived class should implement any of the following methods to listen for
34 :class:`.Worker`, :class:`.EnginePort` or :class:`.EngineTimer` events.
35 If not implemented, the default behavior is to do nothing.
36
37 NOTE: ``ev_timeout(self, worker)`` was removed from this class definition
38 in ClusterShell 1.9. For compatibility, it is still called if defined by
39 subclasses. Use ``ev_close()`` instead and check whether its argument
40 ``timedout`` is ``True``, which means that the :class:`.Worker` has timed
41 out.
42 """
43
44 ### Worker events
45
46 def ev_start(self, worker):
47 """
48 Called to indicate that a worker has just started.
49
50 :param worker: :class:`.Worker` derived object
51 """
52
53 def ev_pickup(self, worker, node):
54 """
55 Called for each node to indicate that a worker command for a
56 specific node (or key) has just started.
57
58 .. warning:: The signature of :meth:`EventHandler.ev_pickup` changed
59 in ClusterShell 1.8, please update your :class:`.EventHandler`
60 derived classes and add the node argument.
61
62 *New in version 1.7.*
63
64 *Changed in version 1.10:* in tree mode, ``ev_pickup`` now fires
65 only once a command can no longer be rerouted, so it fires at
66 most once per node.
67
68 :param worker: :class:`.Worker` derived object
69 :param node: node (or key)
70 """
71
72 def ev_read(self, worker, node, sname, msg):
73 """
74 Called to indicate that a worker has data to read from a specific
75 node (or key).
76
77 .. warning:: The signature of :meth:`EventHandler.ev_read` changed
78 in ClusterShell 1.8, please update your :class:`.EventHandler`
79 derived classes and add the node, sname and msg arguments.
80
81 :param worker: :class:`.Worker` derived object
82 :param node: node (or key)
83 :param sname: stream name
84 :param msg: message
85 """
86
87 def ev_error(self, worker):
88 """
89 Called to indicate that a worker has error to read on stderr from
90 a specific node (or key).
91
92 [DEPRECATED] use ev_read instead and test if sname is 'stderr'
93
94 :param worker: :class:`.Worker` object
95
96 Available worker attributes:
97 * :attr:`.Worker.current_node` - node (or key)
98 * :attr:`.Worker.current_errmsg` - read error message
99 """
100
101 def ev_written(self, worker, node, sname, size):
102 """
103 Called to indicate that some writing has been done by the worker to a
104 node on a given stream. This event is only generated when ``write()``
105 is previously called on the worker.
106
107 This handler may be called very often depending on the number of target
108 nodes, the amount of data to write and the block size used by the
109 worker.
110
111 *New in version 1.7.*
112
113 :param worker: :class:`.Worker` derived object
114 :param node: node (or) key
115 :param sname: stream name
116 :param size: amount of bytes that has just been written to node/stream
117 associated with this event
118 """
119
120 def ev_hup(self, worker, node, rc):
121 """
122 Called for each node to indicate that a worker command for a specific
123 node has just finished.
124
125 .. warning:: The signature of :meth:`EventHandler.ev_hup` changed
126 in ClusterShell 1.8, please update your :class:`.EventHandler`
127 derived classes to add the node and rc arguments.
128
129 :param worker: :class:`.Worker` derived object
130 :param node: node (or key)
131 :param rc: command return code (or None if the worker doesn't support
132 command return codes)
133 """
134
135 def ev_close(self, worker, timedout):
136 """
137 Called to indicate that a worker has just finished.
138
139 .. warning:: The signature of :meth:`EventHandler.ev_close` changed
140 in ClusterShell 1.8, please update your :class:`.EventHandler`
141 derived classes to add the timedout argument. Please use this
142 argument instead of the old method ``ev_timeout()``.
143
144 :param worker: :class:`.Worker` derived object
145 :param timedout: boolean set to True if the worker has timed out
146 """
147
148 def _ev_routing(self, worker, arg):
149 """
150 Routing event (private). Called to indicate that a (meta)worker has just
151 updated one of its route path. You can safely ignore this event.
152 """
153
154 ### EnginePort events
155
156 def ev_port_start(self, port):
157 """
158 Called to indicate that a :class:`.EnginePort` object has just started.
159
160 :param port: :class:`.EnginePort` derived object
161 """
162
163 def ev_msg(self, port, msg):
164 """
165 Called to indicate that a message has been received on an
166 :class:`.EnginePort`.
167
168 Used to deliver messages reliably between tasks.
169
170 :param port: :class:`.EnginePort` object on which a message has been
171 received
172 :param msg: the message object received
173 """
174
175 ### EngineTimer events
176
177 def ev_timer(self, timer):
178 """
179 Called to indicate that a timer is firing.
180
181 :param timer: :class:`.EngineTimer` object that is firing
182 """