~ubuntu-branches/ubuntu/trusty/torrus/trusty-proposed

« back to all changes in this revision

Viewing changes to perllib/Torrus/Scheduler.pm

  • Committer: Bazaar Package Importer
  • Author(s): Marc Haber
  • Date: 2008-03-08 00:18:46 UTC
  • mfrom: (1.2.1 upstream) (3.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080308001846-q3pinwcswe3uf7wj
Tags: 1.0.6-2
Add torrus-common.NEWS advising people to recompile their
configuration upon upgrading to torrus 1.0.6.
Thanks to Joerg Dorchain. Closes: #469274

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#  along with this program; if not, write to the Free Software
15
15
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16
16
 
17
 
# $Id: Scheduler.pm,v 1.4 2005/05/30 09:36:10 ssinyagin Exp $
 
17
# $Id: Scheduler.pm,v 1.6 2007/06/16 16:54:08 ssinyagin Exp $
18
18
# Stanislav Sinyagin <ssinyagin@yahoo.com>
19
19
 
20
20
 
276
276
# Periodic task base class
277
277
# Options:
278
278
#   -Period   => seconds    -- cycle period
279
 
#   -Offset   => seconds   -- time offset from even period moments
 
279
#   -Offset   => seconds    -- time offset from even period moments
280
280
#   -Name     => "string"   -- Symbolic name for log messages
 
281
#   -Instance => N          -- instance number
281
282
 
282
283
package Torrus::Scheduler::PeriodicTask;
283
284
 
291
292
    my %options = @_;
292
293
    bless $self, $class;
293
294
 
 
295
    if( not defined( $options{'-Instance'} ) )
 
296
    {
 
297
        $options{'-Instance'} = 0;
 
298
    }
 
299
 
294
300
    %{$self->{'options'}} = %options;
295
301
 
296
302
    $self->{'options'}{'-Period'} = 0 unless
298
304
 
299
305
    $self->{'options'}{'-Offset'} = 0 unless
300
306
        defined( $self->{'options'}{'-Offset'} );
301
 
 
 
307
        
302
308
    $self->{'options'}{'-Name'} = "PeriodicTask" unless
303
309
        defined( $self->{'options'}{'-Name'} );
304
310
 
305
311
    $self->{'missedPeriods'} = 0;
306
312
 
307
313
    $self->{'options'}{'-Started'} = time();
 
314
 
 
315
    # Array of (Name, Value) pairs for any kind of stats    
 
316
    $self->{'statValues'} = [];
308
317
    
309
318
    Debug("New Periodic Task created: period=" .
310
319
          $self->{'options'}{'-Period'} .
394
403
                                 $self->{'missedPeriods'} );
395
404
        $self->{'missedPeriods'} = 0;
396
405
    }
 
406
 
 
407
    foreach my $pair( @{$self->{'statValues'}} )
 
408
    {
 
409
        $stats->setStatsValues( $self->id(), @{$pair} );
 
410
    }
 
411
    @{$self->{'statValues'}} = [];
397
412
}
398
413
 
399
414
 
431
446
    return $self->{'options'}->{'-Name'};
432
447
}
433
448
 
 
449
sub instance
 
450
{
 
451
    my $self = shift;
 
452
    return $self->{'options'}->{'-Instance'};
 
453
}
 
454
 
 
455
 
434
456
sub whenStarted
435
457
{
436
458
    my $self = shift;
441
463
sub id
442
464
{
443
465
    my $self = shift;
444
 
    return join(':', 'P', $self->name(), $self->period(), $self->offset());
 
466
    return join(':', 'P', $self->name(), $self->instance(),
 
467
                $self->period(), $self->offset());
 
468
}
 
469
 
 
470
sub setStatValue
 
471
{
 
472
    my $self = shift;
 
473
    my $name = shift;
 
474
    my $value = shift;
 
475
 
 
476
    push( @{$self->{'statValues'}}, [$name, $value] );
445
477
}
446
478
 
447
479
1;