The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DB2::Admin::EventParser - Support for processing DB2 event monitor files

SYNOPSIS

  use DB2::Admin::EventParser;

  my $parser = DB2::Admin::EventParser::->new('Directory' => '/tmp/eventdir');
  while (1) {
    my $start = time();

    # Process all events since last time
    my $events = 0;
    while (my $event = $parser->GetEvent()) {
        ... process event ...
        $events++;
    }
    my $elapsed = 0;
    if ($events) {
        # Clean up events fully processed
        $parser->Cleanup();
        my $end = time();
        $elapsed = $end - $start;
    }
    if ($elapsed > $scan) {
        print "Took [$elapsed] seconds, scan rate [$scan]\n";
    } else {
        print "Will sleep [", ($scan - $elapsed), "] seconds\n";
        sleep ($scan - $elapsed);
    }
  }

DESCRIPTION

DB2 event monitors can write to a file, to a named pipe, or to DB2 tables. The DB2::Admin::DataStream class cna be used to parse events written to a file or named pipe.

When events monitors write to a file, DB2 weill switch to a new file if the current file is full; the reading application is responsible to clean up the old file. After a database restart, DB2 continues appending to the latest file.

This class is intended to help process such files. It depends on the DB2::Admin::DataStream module to parse file contents. The value it provides is in switching from file to file, being able to restart reading at a desired point, and deleting files that have been fully processed.

METHODS

new

This method creates a new parser object. It takes a single named parameter, Directory, which is the name of the directory that contains the DB2 event monitor files.

The parser object maintains internal styate for the file currently being processed and the position within that file.

GetEvent

This method retrives the next event from the event file. It returns a DB2::Admin::DataStream object, or undef if all events have been read.

Cleanup

This method cleans up all files that have been fully processed, assuming the parser has swicthed to a the next event file.

This method is not implicit in GetEvent because having a separate method gives the programmer the opportunity to delay file deletion until the events has been archived or acted upon.

InquirePosition

This method returns a hash reference with File and Offset fields describing the current event file and position within the file. It returns undef if the parser has not started reading any event file. The return value can be saved at event monitor shutdown time and later be fed into SetPosition to restart where the event monitor left off.

SetPosition

This method takes two named parameters, File and Offset, as returned by a previous call to InquirePosition. It can be used to resume processing at a position previously inquired and saved.

WARNING: feeding random offsets into this module will cuase the parser to return invalid data and possibly crash.

AUTHOR

Hildo Biersma

SEE ALSO

DB2::Admin(3) DB2::Admin::DataStream(3), DB2::Admin::DataElement(3)