| 1 | package Proc::BackOff::Linear; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Inheritance | ||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use base qw( Proc::BackOff ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # Set up get/set fields | ||||||||||||||||||||||||||||
| 7 | 2 | __PACKAGE__->mk_accessors( 'slope', | |||||||||||||||||||||||||||
| 8 | 'x', | ||||||||||||||||||||||||||||
| 9 | 'b', | ||||||||||||||||||||||||||||
| 10 | ); | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # standard pragmas | ||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # standard perl modules | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # CPAN & others | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 NAME | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Proc::BackOff::Linear | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | Usage: | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | use Proc::BackOff::Linear; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | my $obj = Proc::BackOff::Linear->new( { slope => 5, x => 'count', b => 0 ); | ||||||||||||||||||||||||||||
| 33 | # On N'th failure delay would be set to: | ||||||||||||||||||||||||||||
| 34 | # y = slope * x + b; | ||||||||||||||||||||||||||||
| 35 | # 1st failure : 5 * count + b = 5 * 1 + 0 = 5 | ||||||||||||||||||||||||||||
| 36 | # 2nd failure : 5 * 2 + 0 = 10 | ||||||||||||||||||||||||||||
| 37 | # 3rd failure : 5 * 3 + 0 = 15 | ||||||||||||||||||||||||||||
| 38 | # 4th failure : 5 * 4 + 0 = 20 | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | See L<Proc::BackOff> for further documentation. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head1 Overloaded Methods | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head2 new() | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Check for variables being set: | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Required: slope | ||||||||||||||||||||||||||||
| 49 | b defaults to 0 | ||||||||||||||||||||||||||||
| 50 | x defaults to 'count' | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=39.7
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 2 | my $proto = shift; | |||||||||||||||||||||||||||
| 56 | 2 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 57 | 2 | my $obj = $class->SUPER::new(@_); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | ▶ | if ( ! defined $obj->slope() || ! $obj->valid_number_check($obj->slope())) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $obj->slope and $obj->valid_number_check($obj->slope)
MC/DC0%0/2
defined $obj->slope and $obj->valid_number_check($obj->slope)
defined $obj->slope
$obj->valid_number_check($obj->slope)
Truth table33%1/3
A and B
A= defined $obj->slopeB= $obj->valid_number_check($obj->slope)
| |||||||||||||||||||||||||||||
| 60 | 0 | warn "$proto: Slope value not set"; | |||||||||||||||||||||||||||
| 61 | 0 | return undef; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | if ( ! defined $obj->b() || ! $obj->valid_number_check($obj->b())) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $obj->b and $obj->valid_number_check($obj->b)
MC/DC0%0/2
defined $obj->b and $obj->valid_number_check($obj->b)
defined $obj->b
$obj->valid_number_check($obj->b)
Truth table33%1/3
A and B
A= defined $obj->bB= $obj->valid_number_check($obj->b)
| |||||||||||||||||||||||||||||
| 65 | 0 | warn "$proto: b value not set"; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | $obj->b(0) unless defined $obj->b(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return undef unless $obj->valid_number_check($obj->b()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | ▶ | if ( ! defined $obj->x() || ! $obj->valid_number_check($obj->x())) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $obj->x and $obj->valid_number_check($obj->x)
MC/DC0%0/2
defined $obj->x and $obj->valid_number_check($obj->x)
defined $obj->x
$obj->valid_number_check($obj->x)
Truth table33%1/3
A and B
A= defined $obj->xB= $obj->valid_number_check($obj->x)
| |||||||||||||||||||||||||||||
| 71 | 0 | warn "$proto: x value not set"; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | $obj->x(0) unless defined $obj->x(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return undef unless $obj->valid_number_check($obj->x()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | return $obj; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head2 calculate_back_off() | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Returns the new back off value. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 20 | ▶ | sub calculate_back_off { | ||||||||||||||||||||||||||
|
Subroutine
calculate_back_off: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 20 | my $self = shift; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # this is a linear back off | ||||||||||||||||||||||||||||
| 89 | # y = slope * x + b; | ||||||||||||||||||||||||||||
| 90 | # b = 0 | ||||||||||||||||||||||||||||
| 91 | # y = slope * x ; | ||||||||||||||||||||||||||||
| 92 | # x = failure_count | ||||||||||||||||||||||||||||
| 93 | # y = timeout | ||||||||||||||||||||||||||||
| 94 | # slope = add_timeout | ||||||||||||||||||||||||||||
| 95 | # timeout = add_timeout * failure_count | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 20 | my $slope = $self->slope(); | |||||||||||||||||||||||||||
| 98 | 20 | my $x = $self->x(); | |||||||||||||||||||||||||||
| 99 | 20 | my $b = $self->b(); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 20 | ▶ | $slope = $self->failure_count() if $slope eq 'count'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 20 | ▶ | $x = $self->failure_count() if $x eq 'count'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 20 | ▶ | $b = $self->failure_count() if $b eq 'count'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 20 | return $slope * $x + $b; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | 1; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head1 Changes | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0.02 2007-08-12 -- Daniel Lo | ||||||||||||||||||||||||||||
| 113 | - Documentation fixes. No code changes. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0.01 2007-04-17 -- Daniel Lo | ||||||||||||||||||||||||||||
| 116 | - Initial Version | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Daniel Lo <daniel_lo@picturetrail.com> | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | Copyright (C) PictureTrail Inc. 1999-2007 | ||||||||||||||||||||||||||||
| 125 | Santa Clara, California, United States of America. | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | This code is released to the public for public use under Perl's Artisitic | ||||||||||||||||||||||||||||
| 128 | licence. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||