1 use strict; use warnings;
2 package OpenSRF::Utils::SettingsClient;
3 use OpenSRF::Utils::SettingsParser;
5 use OpenSRF::AppSession;
6 use OpenSRF::Utils::Config;
7 use OpenSRF::EX qw(:try);
9 use vars qw/$host_config/;
12 sub new {return bless({},shift());}
19 if(defined($val)) { $we_cache = $val; }
23 if($host_config) { return 1; }
28 # ------------------------------------
29 # utility method for grabbing config info
34 my $bsconfig = OpenSRF::Utils::Config->current;
35 my $host = $bsconfig->env->hostname;
38 if(!$host_config) { grab_host_config($host); }
40 grab_host_config($host);
44 throw OpenSRF::EX::Config ("Unable to retrieve host config for $host" );
47 my $hash = $host_config;
49 # XXX TO DO, check local config 'version',
50 # call out to settings server when necessary....
53 if(!ref($hash) eq 'HASH'){
56 $hash = $hash->{$key};
61 throw OpenSRF::EX::Config ("No Config information for @keys : $e : $@");
69 # XXX make smarter and more robust...
70 sub grab_host_config {
74 warn "Grabbing Host config for $host\n";
75 OpenSRF::System->bootstrap_client(client_name => "system_client");
76 $session = OpenSRF::AppSession->create( "opensrf.settings" ) unless $session;
77 my $bsconfig = OpenSRF::Utils::Config->current;
83 if( ! ($session->connect()) ) {die "Settings Connect timed out\n";}
84 $req = $session->request( "opensrf.settings.host_config.get", $host );
85 $resp = $req->recv( timeout => 10 );
87 } catch OpenSRF::EX with {
90 warn "Connection to Settings Failed $e : $@ ***\n";
95 warn "No Response from settings server...going to sleep\n";
99 if( $resp && UNIVERSAL::isa( $resp, "OpenSRF::EX" ) ) {
103 $host_config = $resp->content();
105 $session->disconnect();