line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAS::Lib::Stomp::POE::Client; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
737
|
use POE; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
219
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
7
|
1
|
|
|
1
|
|
378
|
use XAS::Lib::Stomp::Utils; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
8
|
1
|
|
|
1
|
|
351
|
use XAS::Lib::Stomp::POE::Filter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use XAS::Class |
11
|
1
|
|
|
|
|
10
|
debug => 0, |
12
|
|
|
|
|
|
|
version => $VERSION, |
13
|
|
|
|
|
|
|
base => 'XAS::Lib::Net::POE::Client', |
14
|
|
|
|
|
|
|
mixins => 'XAS::Lib::Mixins::Keepalive', |
15
|
|
|
|
|
|
|
utils => 'trim', |
16
|
|
|
|
|
|
|
accessors => 'stomp', |
17
|
|
|
|
|
|
|
vars => { |
18
|
|
|
|
|
|
|
PARAMS => { |
19
|
|
|
|
|
|
|
-host => { optional => 1, default => undef }, |
20
|
|
|
|
|
|
|
-port => { optional => 1, default => undef }, |
21
|
|
|
|
|
|
|
-alias => { optional => 1, default => 'stomp-client' }, |
22
|
|
|
|
|
|
|
-login => { optional => 1, default => 'guest' }, |
23
|
|
|
|
|
|
|
-passcode => { optional => 1, default => 'guest' }, |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
1
|
|
|
1
|
|
5
|
; |
|
1
|
|
|
|
|
1
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#use Data::Dumper; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
31
|
|
|
|
|
|
|
# Public Events |
32
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
35
|
|
|
|
|
|
|
# Public Methods |
36
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub session_initialize { |
39
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->log->debug("$alias: session_initialize()"); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# public events |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->log->debug("$alias: doing public events"); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$poe_kernel->state('handle_noop', $self); |
50
|
0
|
|
|
|
|
|
$poe_kernel->state('handle_error', $self); |
51
|
0
|
|
|
|
|
|
$poe_kernel->state('handle_message', $self); |
52
|
0
|
|
|
|
|
|
$poe_kernel->state('handle_receipt', $self); |
53
|
0
|
|
|
|
|
|
$poe_kernel->state('handle_connected', $self); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# walk the chain |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$self->SUPER::session_initialize(); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->log->debug("$alias: leaving session_initialize()"); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub session_shutdown { |
64
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
67
|
0
|
|
|
|
|
|
my $frame = $self->stomp->disconnect( |
68
|
|
|
|
|
|
|
-receipt => 'disconnecting' |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->log->debug("$alias: entering session_shutdown()"); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$poe_kernel->call($alias, 'write_data', $frame); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# walk the chain |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$self->SUPER::session_shutdown(); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$self->log->debug("$alias: leaving session_shutdown()"); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
84
|
|
|
|
|
|
|
# Public Events |
85
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub handle_connection { |
88
|
0
|
|
|
0
|
1
|
|
my ($self) = $_[OBJECT]; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
91
|
0
|
|
|
|
|
|
my $frame = $self->stomp->connect( |
92
|
|
|
|
|
|
|
-login => $self->login, |
93
|
|
|
|
|
|
|
-passcode => $self->passcode |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$self->log->debug("$alias: entering handle_connection()"); |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$poe_kernel->post($alias, 'write_data', $frame); |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$self->log->debug("$alias: leaving handle_connection()"); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub handle_connected { |
105
|
0
|
|
|
0
|
1
|
|
my ($self, $frame) = @_[OBJECT, ARG0]; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$self->log->debug("$alias: entering handle_connected()"); |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
if ($self->tcp_keepalive) { |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$self->log->info_msg('tcp_keepalive_enabled', $alias); |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$self->init_keepalive(); |
116
|
0
|
|
|
|
|
|
$self->enable_keepalive($self->socket); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$self->log->info_msg('net_server_connected', $alias, $self->host, $self->port); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$poe_kernel->post($alias, 'connection_up'); |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$self->log->debug("$alias: leaving handle_connected()"); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub handle_message { |
129
|
0
|
|
|
0
|
1
|
|
my ($self, $frame) = @_[OBJECT, ARG0]; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub handle_receipt { |
134
|
0
|
|
|
0
|
1
|
|
my ($self, $frame) = @_[OBJECT, ARG0]; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub handle_error { |
139
|
0
|
|
|
0
|
1
|
|
my ($self, $frame) = @_[OBJECT, ARG0]; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $message = ''; |
142
|
0
|
|
|
|
|
|
my $message_id = ''; |
143
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
144
|
|
|
|
|
|
|
|
145
|
0
|
0
|
|
|
|
|
if ($frame->header->methods->has('message_id')) { |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$message_id = $frame->header->message_id; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
if ($frame->header->methods->has('message')) { |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
$message = $frame->header->message; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
$self->log->error_msg('stomp_errors', |
158
|
|
|
|
|
|
|
$alias, |
159
|
|
|
|
|
|
|
trim($message_id), |
160
|
|
|
|
|
|
|
trim($message), |
161
|
|
|
|
|
|
|
trim($frame->body) |
162
|
|
|
|
|
|
|
); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub handle_noop { |
167
|
0
|
|
|
0
|
1
|
|
my ($self, $frame) = @_[OBJECT, ARG0]; |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
$self->log->debug("$alias: handle_noop()"); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
176
|
|
|
|
|
|
|
# Private Events |
177
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub _server_message { |
180
|
0
|
|
|
0
|
|
|
my ($self, $frame, $wheel_id) = @_[OBJECT, ARG0, ARG1]; |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
my $alias = $self->alias; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
$self->log->debug("$alias: entering _server_message()"); |
185
|
|
|
|
|
|
|
|
186
|
0
|
0
|
|
|
|
|
if ($frame->command eq 'CONNECTED') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
$self->log->debug("$alias: received a \"CONNECTED\" message"); |
189
|
0
|
|
|
|
|
|
$poe_kernel->post($alias, 'handle_connected', $frame); |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
} elsif ($frame->command eq 'MESSAGE') { |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
$self->log->debug("$alias: received a \"MESSAGE\" message"); |
194
|
0
|
|
|
|
|
|
$poe_kernel->post($alias, 'handle_message', $frame); |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
} elsif ($frame->command eq 'RECEIPT') { |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
$self->log->debug("$alias: received a \"RECEIPT\" message"); |
199
|
0
|
|
|
|
|
|
$poe_kernel->post($alias, 'handle_receipt', $frame); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
} elsif ($frame->command eq 'ERROR') { |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
$self->log->debug("$alias: received an \"ERROR\" message"); |
204
|
0
|
|
|
|
|
|
$poe_kernel->post($alias, 'handle_error', $frame); |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} elsif ($frame->command eq 'NOOP') { |
207
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
$self->log->debug("$alias: received an \"NOOP\" message"); |
209
|
0
|
|
|
|
|
|
$poe_kernel->post($alias, 'handle_noop', $frame); |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
} else { |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
$self->log->warn_msg('stomp_unknown_type', $alias, $frame->command); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
$self->log->debug("$alias: leaving _server_message()"); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
222
|
|
|
|
|
|
|
# Private Methods |
223
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub init { |
226
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
227
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
my $self = $class->SUPER::init(@_); |
229
|
|
|
|
|
|
|
|
230
|
0
|
0
|
|
|
|
|
unless (defined($self->{'host'})) { |
231
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
$self->{'host'} = $self->env->mqserver; |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
0
|
0
|
|
|
|
|
unless (defined($self->{'port'})) { |
237
|
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
$self->{'port'} = $self->env->mqport; |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
0
|
|
|
|
|
|
$self->{'stomp'} = XAS::Lib::Stomp::Utils->new(); |
243
|
0
|
|
|
|
|
|
$self->{'filter'} = XAS::Lib::Stomp::POE::Filter->new(); |
244
|
|
|
|
|
|
|
|
245
|
0
|
|
|
|
|
|
return $self; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
1; |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
__END__ |