| 1 | #!/usr/bin/perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | JMX::Jmx4Perl::Response - A jmx4perl response | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | my $jmx_response = $jmx_agent->request($jmx_request); | ||||||||||||||||||||
| 10 | my $value = $jmx_response->value(); | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | A L<JMX::Jmx4Perl::Response> is the result of an JMX request and encapsulates | ||||||||||||||||||||
| 15 | the answer as returned by a L<JMX::Jmx4Perl> backend. Depending on the | ||||||||||||||||||||
| 16 | C<status> it either contains the result of a valid request or a error message. | ||||||||||||||||||||
| 17 | The status is modelled after HTTP response codes (see | ||||||||||||||||||||
| 18 | L<http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>). For now, only the | ||||||||||||||||||||
| 19 | codes C<200> and C<400 .. 599> codes are used to specified successful request | ||||||||||||||||||||
| 20 | and errors respectively. | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =head1 METHODS | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | =over | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | package JMX::Jmx4Perl::Response; | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 4 | ▶ | use vars qw(@EXPORT); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | =item $response = JMX::Jmx4Perl::Response->new($status,$request,$value,$error,$stacktrace) | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | Internal constructor for creating a response which is use withing requesting | ||||||||||||||||||||
| 36 | the backend. C<$error> and C<$stacktrace> are optional and should only provided | ||||||||||||||||||||
| 37 | when C<$status != 200>. | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 42 | 0 | my $class = shift; | |||||||||||||||||||
| 43 | 0 | my $self = { @_ }; | |||||||||||||||||||
| 44 | 0 | ▶ | return bless $self,(ref($class) || $class); | ||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =item $status = $response->status() | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | Return the status code of this response. Status codes are modelled after HTTP | ||||||||||||||||||||
| 50 | return codes. C<200> is the code for a suceeded request. Any code in the range | ||||||||||||||||||||
| 51 | 500 - 599 specifies an error. | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | =cut | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | sub status { | ||||||||||||||||||
|
Subroutine
status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 56 | 0 | return shift->{status}; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =item $timestamp = $response->timestamp() | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | Get the timestamp (i.e. epoch seconds) when the request was executed on the | ||||||||||||||||||||
| 62 | serverside. | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | ▶ | sub timestamp { | ||||||||||||||||||
|
Subroutine
timestamp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 67 | 0 | return shift->{timestamp}; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =item $history = $response->history() | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | Get the history if history tracking is switched on. History tracking is | ||||||||||||||||||||
| 73 | switchen on by executing a certain JMX operation on the C<jolokia:type=Config> | ||||||||||||||||||||
| 74 | MBean. See the alias C<JMX4PERL_HISTORY_MAX_ATTRIBUTE> and L<jmx4perl/"HISTORY | ||||||||||||||||||||
| 75 | TRACKING"> for details. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | The returned arrayref (if any) contains hashes with two values: C<value> | ||||||||||||||||||||
| 78 | contains the historical value and C<timestamp> the timestamp when this value | ||||||||||||||||||||
| 79 | was recorded. | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | ▶ | sub history { | ||||||||||||||||||
|
Subroutine
history: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 84 | 0 | return shift->{history}; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =item $ok = $response->is_ok() | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | Return true if this object contains a valid response (i.e. the status code is | ||||||||||||||||||||
| 90 | equal 200) | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | ▶ | sub is_ok { | ||||||||||||||||||
|
Subroutine
is_ok: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 95 | 0 | return shift->{status} == 200; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =item $fault = $response->is_error() | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | Opposite of C<is_ok>, i.e. return true if the status code is B<not> equal to | ||||||||||||||||||||
| 101 | 200 | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | ▶ | sub is_error { | ||||||||||||||||||
|
Subroutine
is_error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 106 | 0 | return shift->{status} != 200;; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =item $error = $response->error_text() | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | Return the error text. Set only if C<is_error> is C<true> | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | ▶ | sub error_text { | ||||||||||||||||||
|
Subroutine
error_text: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 116 | 0 | return shift->{error}; | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | =item $error = $response->stacktrace() | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | Returns the stacktrace of an Java error if any. This is only set when | ||||||||||||||||||||
| 122 | C<is_error> is C<true> B<and> and Java exception occured on the Java agent's | ||||||||||||||||||||
| 123 | side. | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =cut | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 0 | ▶ | sub stacktrace { return shift->{stacktrace}; } | ||||||||||||||||||
|
Subroutine
stacktrace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =item $content = $response->value() | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | Return the content of this response, which is a represents the JSON response as | ||||||||||||||||||||
| 132 | returned by the Java agent as a hash reference value. This is set only when C<is_ok> is | ||||||||||||||||||||
| 133 | true. | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | =cut | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 0 | ▶ | sub value { | ||||||||||||||||||
|
Subroutine
value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 138 | 0 | return shift->{value}; | |||||||||||||||||||
| 139 | } | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | =item $request = $response->request() | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | Return the L<JMX::Jmx4Perl::Request> which lead to this response | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 0 | ▶ | sub request { | ||||||||||||||||||
|
Subroutine
request: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 148 | 0 | return shift->{request}; | |||||||||||||||||||
| 149 | } | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | =back | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =head1 LICENSE | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | This file is part of jmx4perl. | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | Jmx4perl is free software: you can redistribute it and/or modify | ||||||||||||||||||||
| 158 | it under the terms of the GNU General Public License as published by | ||||||||||||||||||||
| 159 | the Free Software Foundation, either version 2 of the License, or | ||||||||||||||||||||
| 160 | (at your option) any later version. | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | jmx4perl is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 163 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 164 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||
| 165 | GNU General Public License for more details. | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | You should have received a copy of the GNU General Public License | ||||||||||||||||||||
| 168 | along with jmx4perl. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | A commercial license is available as well. Please contact roland@cpan.org for | ||||||||||||||||||||
| 171 | further details. | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | =head1 AUTHOR | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | roland@cpan.org | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | 4 | 1; | |||||||||||||||||||