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

raeburn raeburn at source.lon-capa.org
Sun Jul 31 18:55:54 EDT 2011


raeburn		Sun Jul 31 22:55:54 2011 EDT

  Modified files:              
    /loncom	lond 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - New routine in lonnet.pm: &get_remote_globals() 
    to retrieve contents of package globals for lonnet.pm on a remote server.
    - Corresponding handler in lond: &read_lonnet_global(). 
  
  
Index: loncom/lond
diff -u loncom/lond:1.476 loncom/lond:1.477
--- loncom/lond:1.476	Thu Jul 28 15:12:03 2011
+++ loncom/lond	Sun Jul 31 22:55:48 2011
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.476 2011/07/28 15:12:03 raeburn Exp $
+# $Id: lond,v 1.477 2011/07/31 22:55:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -60,7 +60,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.476 $'; #' stupid emacs
+my $VERSION='$Revision: 1.477 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -1641,6 +1641,35 @@
 }
 &register_handler("ls3", \&ls3_handler, 0, 1, 0);
 
+sub read_lonnet_global {
+    my ($cmd,$tail,$client) = @_;
+    my $userinput = "$cmd:$tail";
+    my $requested = &Apache::lonnet::thaw_unescape($tail);
+    my $result;
+    if (ref($requested) eq 'HASH') {
+        foreach my $what (keys(%{$requested})) {
+            my $type = $requested->{$what};
+            my $lonnetglobal = 'Apache::lonnet::'.$what;
+            my $response;
+            if ($type eq 'HASH') {
+                if (defined(%{$lonnetglobal})) {
+                    my $hashref = \%{$lonnetglobal};
+                    $response = &Apache::lonnet::freeze_escape($hashref);
+                }
+            } else {
+                if (defined(${$lonnetglobal})) {
+                    $response = &escape(${$item});
+                }
+            }
+        }
+        $result .= &escape($what).'='.$response.'&';
+    }
+    $result =~ s/\&$//;
+    &Reply($client,\$result,$userinput);
+    return 1;
+}
+&register_handler("readlonnetglobal", \&read_lonnet_global, 0, 1, 0);
+
 sub server_timezone_handler {
     my ($cmd,$tail,$client) = @_;
     my $userinput = "$cmd:$tail";
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1120 loncom/lonnet/perl/lonnet.pm:1.1121
--- loncom/lonnet/perl/lonnet.pm:1.1120	Thu Jul 28 18:22:44 2011
+++ loncom/lonnet/perl/lonnet.pm	Sun Jul 31 22:55:53 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1120 2011/07/28 18:22:44 raeburn Exp $
+# $Id: lonnet.pm,v 1.1121 2011/07/31 22:55:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -306,6 +306,44 @@
     return &do_cache_new('serverhomeID',$hostname,$serverhomeID,$cachetime);
 }
 
+sub get_remote_globals {
+    my ($lonhost,$whathash,$ignore_cache) = @_;
+    my (%returnhash,%whatneeded);
+    if (ref($whathash) eq 'ARRAY') {
+        foreach my $what (sort(keys(%{$whathash}))) {
+            my $type = $whathash->{$what};
+            my $hashid = $lonhost.'-'.$what;
+            my ($result,$cached); 
+            unless ($ignore_cache) {
+                ($result,$cached)=&is_cached_new('lonnetglobal',$hashid);
+                $returnhash{$what} = $result;
+            }
+            if (defined($cached)) {
+                $returnhash{$what} = $result;
+            } else {
+                $whatneeded{$what} = $type;
+            }
+        }
+        if (keys(%whatneeded) > 0) {
+            my $requested = &freeze_escape(\%whatneeded);
+            my $rep=&reply('readlonnetglobal:'.$requested,$lonhost);
+            unless (($rep=~/^refused/) || ($rep=~/^rejected/) || $rep eq 'con_lost')) {
+                my @pairs=split(/\&/,$rep);
+                if ($rep !~ /^error/) {
+                    foreach my $item (@pairs) {
+                        my ($key,$value)=split(/=/,$item,2);
+                        my $what = &unescape($key);
+                        my $hashid = $lonhost.'-'.$what;
+                        $returnhash{$what}=&thaw_unescape($value);
+                        &do_cache_new('lonnetglobal',$hashid,$returnhash{$what},600);
+                    }
+                }
+            }
+        }
+    }
+    return %returnhash;
+}
+
 # -------------------------------------------------- Non-critical communication
 sub subreply {
     my ($cmd,$server)=@_;




More information about the LON-CAPA-cvs mailing list