Show
Ignore:
Timestamp:
05/22/08 19:36:52 (6 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1211485012 +0000
git-parent:

[7b9e8bc8986e3f6e1e20051d23be0f664abb46dd]

git-author:
Mark Harrison <mark@omniti.com> 1211485012 +0000
Message:

Added a purge method to status that will remove any status information for
modules that are no longer loaded (due to them being removed from the config
file and resmon being reloaded). This required $status to become global so it
was accessible from the reload_modules command.

git-svn-id: https://labs.omniti.com/resmon/trunk@109 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/Resmon/Status.pm

    r3af30fc ra3ac157  
    405405  } 
    406406} 
     407sub purge { 
     408    # This removes status information for modules that are no longer loaded 
     409 
     410    # Generate list of current modules 
     411    my %loaded = (); 
     412    my ($self, $config) = @_; 
     413    while (my ($type, $mods) = each(%{$config->{Module}}) ) { 
     414        $loaded{$type} = (); 
     415        foreach (@$mods) { 
     416            $loaded{$type}{$_->{'object'}} = 1; 
     417        } 
     418    } 
     419 
     420    # Debugging 
     421    #while (my ($key, $value) = each(%loaded) ) { 
     422    #    print STDERR "$key: "; 
     423    #    while (my ($mod, $dummy) = each (%$value) ) { 
     424    #        print STDERR "$mod "; 
     425    #    } 
     426    #    print "\n"; 
     427    #} 
     428 
     429    # Compare $self->{store} with list of loaded modules 
     430    while (my ($type, $value) = each (%{$self->{store}})) { 
     431        while (my ($name, $value2) = each (%$value)) { 
     432            if (!exists($loaded{$type}) || !exists($loaded{$type}{$name})) { 
     433                print STDERR "$type $name\n"; 
     434                delete $self->{store}->{$type}->{$name}; 
     435                if (scalar(keys %{$self->{store}->{$type}}) == 0) { 
     436                    print STDERR "$type has no more objects, deleting\n"; 
     437                    delete $self->{store}->{$type}; 
     438                } 
     439            } 
     440        } 
     441    } 
     442} 
    407443sub close { 
    408444  my $self = shift;