[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 12 Nov 2003 20:32:04 -0000


matthew		Wed Nov 12 15:32:04 2003 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Added &inc and modified &flushcourselogs to use it.  Added some POD as well.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.448 loncom/lonnet/perl/lonnet.pm:1.449
--- loncom/lonnet/perl/lonnet.pm:1.448	Wed Nov 12 14:51:43 2003
+++ loncom/lonnet/perl/lonnet.pm	Wed Nov 12 15:32:04 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.448 2003/11/12 19:51:43 albertel Exp $
+# $Id: lonnet.pm,v 1.449 2003/11/12 20:32:04 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -51,6 +51,29 @@
 use Time::HiRes();
 my $readit;
 
+=pod
+
+=head1 Package Variables
+
+These are largely undocumented, so if you decipher one please note it here.
+
+=over 4
+
+=item $processmarker
+
+Contains the time this process was started and this servers host id.
+
+=item $dumpcount
+
+Counts the number of times a message log flush has been attempted (regardless
+of success) by this process.  Used as part of the filename when messages are
+delayed.
+
+=back
+
+=cut
+
+
 # --------------------------------------------------------------------- Logging
 
 sub logtouch {
@@ -1311,12 +1334,24 @@
 # File accesses
 # Writes to the dynamic metadata of resources to get hit counts, etc.
 #
-    foreach (keys %accesshash) {
-        my $entry=$_;
-        $entry=~/\_\_\_(\w+)\/(\w+)\/(.*)\_\_\_(\w+)$/;
+    foreach my $entry (keys(%accesshash)) {
+        my ($dom,$name,undef,$type)=($entry=~m:___(\w+)/(\w+)/(.*)___(\w+)$:);
         my %temphash=($entry => $accesshash{$entry});
-        if (&Apache::lonnet::put('nohist_resevaldata',\%temphash,$1,$2) eq 'ok') {
-	    delete $accesshash{$entry};
+        if ($type eq 'count'){
+            my $result = &inc('nohist_accesscount',\%temphash,$dom,$name);
+            if ($result eq 'ok') {
+                delete $accesshash{$entry};
+            } elsif ($result eq 'unknown_cmd') {
+                # Target server has old code running on it.
+                if (&put('nohist_resevaldata',\%temphash,$dom,$name) eq 'ok') {
+                    delete $accesshash{$entry};
+                }
+            }
+ &logthis('incrementing '.$entry.' by '.$accesshash{$entry}.' result is '.$result);
+        } else {
+            if (&put('nohist_resevaldata',\%temphash,$dom,$name) eq 'ok') {
+                delete $accesshash{$entry};
+            }
         }
     }
 #
@@ -2352,6 +2387,30 @@
     return \%returnhash;
 }
 
+# --------------------------------------------------------------- inc interface
+
+sub inc {
+    my ($namespace,$store,$udomain,$uname) = @_;
+    if (!$udomain) { $udomain=$ENV{'user.domain'}; }
+    if (!$uname) { $uname=$ENV{'user.name'}; }
+    my $uhome=&homeserver($uname,$udomain);
+    my $items='';
+    if (! ref($store)) {
+        # got a single value, so use that instead
+        $items = &escape($store).'=&';
+    } elsif (ref($store) eq 'SCALAR') {
+        $items = &escape($$store).'=&';        
+    } elsif (ref($store) eq 'ARRAY') {
+        $items = join('=&',map {&escape($_);} @{$store});
+    } elsif (ref($store) eq 'HASH') {
+        while (my($key,$value) = each(%{$store})) {
+            $items.= &escape($key).'='.&escape($value).'&';
+        }
+    }
+    $items=~s/\&$//;
+    return &reply("inc:$udomain:$uname:$namespace:$items",$uhome);
+}
+
 # --------------------------------------------------------------- put interface
 
 sub put {
@@ -5207,6 +5266,14 @@
 dump($namespace,$udom,$uname,$regexp) : 
 dumps the complete (or key matching regexp) namespace into a hash
 ($udom, $uname and $regexp are optional)
+
+=item *
+
+inc($namespace,$store,$udom,$uname) : increments $store in $namespace.
+$store can be a scalar, an array reference, or if the amount to be 
+incremented is > 1, a hash reference.
+
+($udom and $uname are optional)
 
 =item *