20. State

The IDM_State module offers loadable modules a means of keeping state between invocations — this is necessary should Cheesewire be run periodically via cron rather than by its own daemon. State-related data is stored in DBM files via Perl ties.

20.1. New Instance of a Loadable Module

Creation of an instance of a loadable module calls upon IDM_State:

    sub IDM_Template::new_template() {
        .
        .
        my $state = IDM_State->new(STATEMODE => $self->{SIDSCONFIG}->daemon_mode(),
                                   DBMFILE   => $self->{CLASS});

        $self->{STATE} = $state;
        $self->{STATE}->init_state(FIELD           => "LAST_RUN_TIME", 
                                   DEFLT_FIELD_VAL => $args{LAST_RUN_TIME});

        $self->{LOG} = Log->new(PREFIX    => $self->{CLASS}, 
                                MODULE    => $self->{CLASS},
                                STATE     => $self->{STATE}, 
                                .
                                .
      }
A reference to the loadable module's state object is passed to the module's instance of the Log class.

20.2. New Instance of the Log Class

Instance of the Log class need to know when to rotate:

    sub Log::new() {
        .
        .
        $self->{STATE}->init_state(FIELD => "LOG_LASTTIME", DEFLT_FIELD_VAL => time);
        .        
        .        
      }
and
    sub Log::append() {
        .
        .
        if (time > $self->{STATE}->get_state(FIELD => "LOG_LASTTIME") 
                 + $self->{MODSCFG}->module_rot_prd($self->{MODULE})) {

            $self->{STATE}->set_state(FIELD => "LOG_LASTTIME", FIELDVALUE => time);
            $self->rotate_log();
          }
        .
        .
      }



...previousup (conts)next...



About this document:

Produced from the SGML: /home/isd/public_html/_cheesewire/_reml_grp/index.reml
On: 4/9/2006 at 17:35:44
Options: reml2 -i noindex -l long -o html -p multiple