| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# Copyright 2007-2010 David Snopek <dsnopek@gmail.com> |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify |
|
5
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
|
6
|
|
|
|
|
|
|
# the Free Software Foundation, either version 2 of the License, or |
|
7
|
|
|
|
|
|
|
# (at your option) any later version. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
|
10
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
|
|
|
|
# GNU General Public License for more details. |
|
13
|
|
|
|
|
|
|
# |
|
14
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
|
15
|
|
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
|
|
|
|
# |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package POE::Component::MessageQueue::Message; |
|
19
|
2
|
|
|
2
|
|
26046
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Net::Stomp::Frame; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has id => ( |
|
23
|
|
|
|
|
|
|
is => 'ro', |
|
24
|
|
|
|
|
|
|
isa => 'Str', |
|
25
|
|
|
|
|
|
|
required => 1, |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has destination => ( |
|
29
|
|
|
|
|
|
|
is => 'ro', |
|
30
|
|
|
|
|
|
|
isa => 'Str', |
|
31
|
|
|
|
|
|
|
required => 1, |
|
32
|
|
|
|
|
|
|
); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has body => ( |
|
35
|
|
|
|
|
|
|
is => 'rw', |
|
36
|
|
|
|
|
|
|
clearer => 'delete_body', |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has persistent => ( |
|
40
|
|
|
|
|
|
|
is => 'ro', |
|
41
|
|
|
|
|
|
|
isa => 'Bool', |
|
42
|
|
|
|
|
|
|
required => 1, |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has expire_at => ( |
|
46
|
|
|
|
|
|
|
is => 'rw', |
|
47
|
|
|
|
|
|
|
isa => 'Num', |
|
48
|
|
|
|
|
|
|
predicate => 'has_expiration', |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has 'deliver_at' => ( |
|
52
|
|
|
|
|
|
|
is => 'rw', |
|
53
|
|
|
|
|
|
|
isa => 'Num', |
|
54
|
|
|
|
|
|
|
predicate => 'has_delay', |
|
55
|
|
|
|
|
|
|
clearer => 'clear_delay', |
|
56
|
|
|
|
|
|
|
); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
has claimant => ( |
|
59
|
|
|
|
|
|
|
is => 'rw', |
|
60
|
|
|
|
|
|
|
isa => 'Maybe[Int]', |
|
61
|
|
|
|
|
|
|
writer => 'claim', |
|
62
|
|
|
|
|
|
|
predicate => 'claimed', |
|
63
|
|
|
|
|
|
|
clearer => 'disown', |
|
64
|
|
|
|
|
|
|
); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has 'size' => ( |
|
67
|
|
|
|
|
|
|
is => 'ro', |
|
68
|
|
|
|
|
|
|
isa => 'Num', |
|
69
|
|
|
|
|
|
|
lazy => 1, |
|
70
|
|
|
|
|
|
|
default => sub { |
|
71
|
|
|
|
|
|
|
my $self = shift; |
|
72
|
|
|
|
|
|
|
use bytes; |
|
73
|
|
|
|
|
|
|
return bytes::length($self->body); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $order = 0; |
|
78
|
|
|
|
|
|
|
my $last_time = 0; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
has 'timestamp' => ( |
|
81
|
|
|
|
|
|
|
is => 'ro', |
|
82
|
|
|
|
|
|
|
isa => 'Num', |
|
83
|
|
|
|
|
|
|
default => sub { |
|
84
|
|
|
|
|
|
|
my $time = time; |
|
85
|
|
|
|
|
|
|
$order = 0 if $time != $last_time; |
|
86
|
|
|
|
|
|
|
$last_time = $time; |
|
87
|
|
|
|
|
|
|
return "$time." . sprintf('%05d', $order++); |
|
88
|
|
|
|
|
|
|
}, |
|
89
|
|
|
|
|
|
|
); |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub equals |
|
94
|
|
|
|
|
|
|
{ |
|
95
|
|
|
|
|
|
|
my ($self, $other) = @_; |
|
96
|
|
|
|
|
|
|
# This is a dirty hack, rewriting to use get_attribute_list would be preferred |
|
97
|
|
|
|
|
|
|
#foreach my $ameta (values %{__PACKAGE__->meta->_attribute_map}) |
|
98
|
|
|
|
|
|
|
foreach my $name (__PACKAGE__->meta->get_attribute_list()) |
|
99
|
|
|
|
|
|
|
{ |
|
100
|
|
|
|
|
|
|
my $ameta = __PACKAGE__->meta->get_attribute($name); |
|
101
|
|
|
|
|
|
|
my $reader = $ameta->get_read_method; |
|
102
|
|
|
|
|
|
|
my ($one, $two) = ($self->$reader, $other->$reader); |
|
103
|
|
|
|
|
|
|
next if (!defined $one) && (!defined $two); |
|
104
|
|
|
|
|
|
|
return 0 unless (defined $one) && (defined $two); |
|
105
|
|
|
|
|
|
|
return 0 unless ($one eq $two); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
return 1; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub clone |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
|
|
|
|
|
|
my $self = $_[0]; |
|
113
|
|
|
|
|
|
|
return $self->meta->clone_object($self); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub from_stomp_frame { |
|
117
|
|
|
|
|
|
|
my ($class, $frame) = @_; |
|
118
|
|
|
|
|
|
|
my $persistent = lc($frame->headers->{persistent} || ''); |
|
119
|
|
|
|
|
|
|
my $msg = $class->new( |
|
120
|
|
|
|
|
|
|
id => $frame->headers->{'message-id'}, |
|
121
|
|
|
|
|
|
|
destination => $frame->headers->{destination}, |
|
122
|
|
|
|
|
|
|
persistent => ($persistent eq 'true') || ($persistent eq '1'), |
|
123
|
|
|
|
|
|
|
body => $frame->body, |
|
124
|
|
|
|
|
|
|
); |
|
125
|
|
|
|
|
|
|
if (!$msg->persistent and my $after = $frame->headers->{'expire-after'}) { |
|
126
|
|
|
|
|
|
|
$msg->expire_at(time + $after); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
if (my $after = $frame->headers->{'deliver-after'}) { |
|
129
|
|
|
|
|
|
|
$msg->deliver_at(time + $after); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
return $msg; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub create_stomp_frame |
|
135
|
|
|
|
|
|
|
{ |
|
136
|
|
|
|
|
|
|
my $self = shift; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
return Net::Stomp::Frame->new({ |
|
139
|
|
|
|
|
|
|
command => 'MESSAGE', |
|
140
|
|
|
|
|
|
|
headers => { |
|
141
|
|
|
|
|
|
|
'destination' => $self->destination, |
|
142
|
|
|
|
|
|
|
'message-id' => $self->id, |
|
143
|
|
|
|
|
|
|
'content-length' => $self->size, |
|
144
|
|
|
|
|
|
|
}, |
|
145
|
|
|
|
|
|
|
body => $self->body, |
|
146
|
|
|
|
|
|
|
}); |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
|
150
|
|
|
|
|
|
|
|