line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAS::Lib::POE::Session; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
823
|
use POE; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use XAS::Class |
8
|
1
|
|
|
|
|
17
|
debug => 0, |
9
|
|
|
|
|
|
|
version => $VERSION, |
10
|
|
|
|
|
|
|
base => 'XAS::Base', |
11
|
|
|
|
|
|
|
mixin => 'XAS::Lib::Mixins::Handlers', |
12
|
|
|
|
|
|
|
utils => 'weaken dotid', |
13
|
|
|
|
|
|
|
accessors => 'session', |
14
|
|
|
|
|
|
|
vars => { |
15
|
|
|
|
|
|
|
PARAMS => { |
16
|
|
|
|
|
|
|
-alias => { optional => 1, default => 'session' }, |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} |
19
|
1
|
|
|
1
|
|
235
|
; |
|
1
|
|
|
|
|
1
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
1169
|
use Data::Dumper; |
|
1
|
|
|
|
|
4648
|
|
|
1
|
|
|
|
|
709
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
# Public Events |
25
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
28
|
|
|
|
|
|
|
# Public Methods |
29
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub session_initialize { |
32
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$poe_kernel->sig(HUP => 'session_interrupt'); |
35
|
0
|
|
|
|
|
|
$poe_kernel->sig(INT => 'session_interrupt'); |
36
|
0
|
|
|
|
|
|
$poe_kernel->sig(TERM => 'session_interrupt'); |
37
|
0
|
|
|
|
|
|
$poe_kernel->sig(QUIT => 'session_interrupt'); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub session_startup { |
42
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub session_shutdown { |
47
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub session_reload { |
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$poe_kernel->sig_handled(); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub session_interrupt { |
59
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
60
|
0
|
|
|
|
|
|
my $signal = shift; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$self->log->debug("$alias: session_interrupt()"); |
65
|
0
|
|
|
|
|
|
$self->log->warn_msg('session_signaled', $alias, $signal); |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if ($signal eq 'HUP') { |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->session_reload(); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} else { |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$self->session_shutdown(); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub session_stop { |
80
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub session_exception { |
85
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
86
|
0
|
|
|
|
|
|
my $ex = shift; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->log->debug("$alias: session_exception() - session"); |
91
|
0
|
|
|
|
|
|
$self->error_handler($ex); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub run { |
96
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$poe_kernel->run(); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
103
|
|
|
|
|
|
|
# Private Methods |
104
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub init { |
107
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# walk the chain |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $self = $class->SUPER::init(@_); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# set up the session |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$self->{'session'} = POE::Session->create( |
116
|
|
|
|
|
|
|
object_states => [ |
117
|
|
|
|
|
|
|
$self => { |
118
|
|
|
|
|
|
|
_start => '_session_start', |
119
|
|
|
|
|
|
|
_stop => '_session_stop', |
120
|
|
|
|
|
|
|
session_init => '_session_init', |
121
|
|
|
|
|
|
|
session_reload => '_session_reload', |
122
|
|
|
|
|
|
|
session_startup => '_session_startup', |
123
|
|
|
|
|
|
|
session_shutdown => '_session_shutdown', |
124
|
|
|
|
|
|
|
session_interrupt => '_session_interrupt', |
125
|
|
|
|
|
|
|
session_exception => '_session_exception', |
126
|
|
|
|
|
|
|
}, |
127
|
|
|
|
|
|
|
] |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
weaken($self->{'session'}); |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return $self; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
137
|
|
|
|
|
|
|
# Private Events |
138
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub _session_start { |
141
|
0
|
|
|
0
|
|
|
my ($self) = $_[OBJECT]; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
$self->log->debug("$alias: _session_start()"); |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
|
if ((my $rc = $poe_kernel->alias_set($alias)) > 0) { |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$self->throw_msg( |
150
|
|
|
|
|
|
|
dotid($self->class) . '._session_start.noalias', |
151
|
|
|
|
|
|
|
'session_noalias', |
152
|
|
|
|
|
|
|
$alias |
153
|
|
|
|
|
|
|
); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
$poe_kernel->sig('DIE', 'session_exception'); |
158
|
0
|
|
|
|
|
|
$poe_kernel->post($alias, 'session_init'); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub _session_init { |
163
|
0
|
|
|
0
|
|
|
my ($self) = $_[OBJECT]; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
$self->log->debug("$alias: _session_init()"); |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
$self->session_initialize(); |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
$poe_kernel->post($alias, 'session_startup'); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _session_startup { |
176
|
0
|
|
|
0
|
|
|
my ($self) = $_[OBJECT]; |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
$self->log->debug("$alias: _session_startup()"); |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
$self->session_startup(); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub _session_shutdown { |
187
|
0
|
|
|
0
|
|
|
my ($self) = $_[OBJECT]; |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
$self->log->debug("$alias: _session_shutdown()"); |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
$self->session_shutdown(); |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub _session_reload { |
198
|
0
|
|
|
0
|
|
|
my ($self) = $_[OBJECT]; |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
$self->log->debug("$alias: _session_reload()"); |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
$self->session_reload(); |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub _session_stop { |
209
|
0
|
|
|
0
|
|
|
my ($self) = $_[OBJECT]; |
210
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
$self->log->debug("$alias: _session_stop()"); |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
$poe_kernel->sig('DIE'); |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
$self->session_stop(); |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
$poe_kernel->alias_remove($self->alias); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub _session_interrupt { |
224
|
0
|
|
|
0
|
|
|
my ($self, $signal) = @_[OBJECT,ARG0]; |
225
|
|
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
227
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
$self->log->debug("$alias: _session_interrupt()"); |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
$self->session_interrupt($signal); |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub _session_exception { |
235
|
0
|
|
|
0
|
|
|
my ($self, $sig, $ex) = @_[OBJECT,ARG0,ARG1]; |
236
|
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
$self->log->debug("$alias: _session_exception()"); |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
$poe_kernel->sig_handled(); |
242
|
|
|
|
|
|
|
|
243
|
0
|
0
|
|
|
|
|
if ($ex->{'source_session'} ne $_[SESSION]) { |
244
|
|
|
|
|
|
|
|
245
|
0
|
|
|
|
|
|
$self->log->debug(sprintf('%s: sending execption to: %s', $alias, $ex->{'source_session'})); |
246
|
0
|
|
|
|
|
|
$poe_kernel->post($ex->{'source_session'}, 'session_exception', $sig, $ex); |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
} else { |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
$self->log->debug(sprintf('%s: handling execption: %s', $alias, $ex->{'error_str'})); |
251
|
0
|
|
|
|
|
|
$self->session_exception($ex->{'error_str'}); |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
1; |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
__END__ |