Ignore:
Timestamp:
2015-12-10T12:19:20+13:00 (8 years ago)
Author:
jmt12
Message:

Continuing to refactor driver code to move shared code up to parent classes. Have all the basic drivers done...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/tdb/trunk/perllib/DBDrivers/70HyphenFormat.pm

    r30341 r30347  
    3232#
    3333###############################################################################
     34
     35# Note: This driver may be a candidate for further splitting, maybe into a
     36# PipedExecutableDriver and a 70HyphenFormatDriver... but for now all piped
     37# drivers are 70 hyphen format ones, so, yeah.
    3438
    3539package DBDrivers::70HyphenFormat;
     
    5963    $self->{'read_executable'} = 'error';
    6064    $self->{'write_executable'} = 'error';
     65    $self->{'forced_affinity'} = -1; # Set to processor number for forced affinity
    6166    bless($self, $class);
    6267    return $self;
     
    6873
    6974
    70 ## @function close_infodb_handle(filehandle)
    71 #
    72 sub close_infodb_handle
    73 {
    74     my $self = shift(@_);
    75     my $infodb_handle = shift(@_);
    76     $self->debugPrintFunctionHeader();
    77     close($infodb_handle);
    78 }
    79 ## close_infodb_handle(filehandle) => void ##
    80 
    81 
    8275## @function close_infodb_write_handle(filehandle)
    8376#
     
    8578{
    8679    my $self = shift(@_);
    87     $self->close_infodb_handle(@_);
     80    $self->debugPrintFunctionHeader(@_);
     81    my $handle = shift(@_);
     82    my $force_close = shift(@_); # Undefined most of the time
     83    my $continue_close = $self->removeConnectionIfPersistent($handle, $force_close);
     84    if ($continue_close) {
     85    close($handle);
     86    }
     87    return;
    8888}
    8989## close_infodb_write_handle(filehandle) => void ##
     
    142142{
    143143    my $self = shift(@_);
     144    $self->debugPrintFunctionHeader(@_);
    144145    my $infodb_handle = shift(@_);
    145146    my $infodb_key = shift(@_);
    146 
    147147    # A minus at the end of a key (after the ]) signifies 'delete'
    148     print $infodb_handle "[$infodb_key]-\n";
    149 
     148    print $infodb_handle '[' . $infodb_key . ']-' . "\n";
    150149    # The 70 minus signs are also needed, to help make the parsing by db2txt simple
    151150    print $infodb_handle '-' x 70, "\n";
     
    160159    my $self = shift(@_);
    161160    $self->debugPrintFunctionHeader(@_);
    162     my $infodb_file_handle = $self->openWriteHandle(@_);
     161    my $path = shift(@_);
     162    my $append = shift(@_);
     163    my $infodb_file_handle = $self->retrieveConnectionIfPersistent($path, $append);;
     164    # No available existing connection
     165    if (!defined $infodb_file_handle || !$infodb_file_handle) {
     166        $infodb_file_handle = $self->openWriteHandle($path, $append, @_);
     167    $self->registerConnectionIfPersistent($infodb_file_handle, $path, $append);
     168    }
    163169    return $infodb_file_handle;
    164170}
     
    181187    }
    182188    my $infodb_file_handle = undef;
    183     my $cmd = '"' . $exe . '" ' . $default_args;
     189    my $cmd = '';
     190    if ($self->{'forced_affinity'} >= 0)
     191    {
     192        $cmd = 'taskset -c ' . $self->{'forced_affinity'} . ' ';
     193    }
     194    $cmd .= '"' . $exe . '" ' . $default_args;
    184195    foreach my $open_arg (@_) {
     196    # Special - append is typically missing a hyphen
     197    if ($open_arg eq 'append') {
     198        $open_arg = '-append';
     199    }
    185200    $cmd .= ' ' . $open_arg;
    186201    }
     
    199214
    200215## @function openReadHandle(string, string) => filehandle
     216#
    201217sub openReadHandle
    202218{
     
    207223
    208224
     225## @function openWriteHandle(*) => filehandle
     226#
    209227sub openWriteHandle
    210228{
     
    212230    return $self->openPipedHandle(RWMODE_WRITE, $self->{'write_executable'}, @_);
    213231}
     232## openWriteHandle(*) => filehandle ##
     233
    214234
    215235## @function read_infodb_entry(string, string) => hashmap
     
    232252    my $infodb_file_path = shift(@_);
    233253    my $infodb_map = shift(@_);
     254    $self->debugPrintFunctionHeader($infodb_file_path, $infodb_map);
    234255    my $infodb_file_handle = $self->openReadHandle($infodb_file_path);
    235256    my $infodb_line = "";
     
    250271        }
    251272    }
    252   $self->close_infodb_handle($infodb_file_handle);
     273  $self->close_infodb_write_handle($infodb_file_handle);
    253274}
    254275## read_infodb_file(string, hashmap) => void ##
     
    291312    }
    292313    }
    293     $self->close_infodb_handle($infodb_file_handle);
     314    $self->close_infodb_write_handle($infodb_file_handle);
    294315}
    295316## read_infodb_keys(string, hashmap) => void ##
     
    354375    print $infodb_file_handle "[$infodb_key]\n";
    355376    print $infodb_file_handle "$serialized_infodb_map\n";
    356     $self->close_infodb_handle($infodb_file_handle);
     377    $self->close_infodb_write_handle($infodb_file_handle);
    357378    $status = 0; # as in exit status of cmd OK
    358379    }
Note: See TracChangeset for help on using the changeset viewer.