From ce9185d3106dad85345e400b36fa40e4e7cc3f64 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 7 Feb 2005 20:31:23 +0000 Subject: [PATCH] making to work in new environment, added 'system_client' login for system clients git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@20 9efc2488-bf62-4759-914b-345cdb29e865 --- src/perlmods/OpenSRF.pm | 12 +++++------- src/perlmods/OpenSRF/AppSession.pm | 20 +++++++++++++++++--- src/perlmods/OpenSRF/Application/Demo/Math.pm | 1 - src/perlmods/OpenSRF/DOM/Element/domainObject.pm | 6 +++++- src/perlmods/OpenSRF/DomainObject.pm | 5 ----- src/perlmods/OpenSRF/DomainObject/oilsMessage.pm | 4 +++- src/perlmods/OpenSRF/System.pm | 13 +++++++++---- src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm | 14 ++++++++++---- .../OpenSRF/Transport/SlimJabber/PeerConnection.pm | 12 ++++++++++-- src/perlmods/OpenSRF/UnixServer.pm | 2 +- 10 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/perlmods/OpenSRF.pm b/src/perlmods/OpenSRF.pm index 18d157a..e6fa333 100644 --- a/src/perlmods/OpenSRF.pm +++ b/src/perlmods/OpenSRF.pm @@ -1,22 +1,22 @@ -package OpenILS; +package OpenSRF; use strict; use Error; use vars qw/$VERSION $AUTOLOAD/; $VERSION = do { my @r=(q$Revision$=~/\d+/g); sprintf "%d."."%02d"x$#r,@r }; -=head1 OpenILS +=head1 OpenSRF =cut =head2 Overview - Top level class for OpenILS perl modules. + Top level class for OpenSRF perl modules. =cut # Exception base classes #use Exception::Class -# ( OpenILSException => { fields => [ 'errno' ] }); +# ( OpenSRFException => { fields => [ 'errno' ] }); #push @Exception::Class::ISA, 'Error'; =head3 AUTOLOAD() @@ -68,8 +68,6 @@ sub alert_abstract() { die " * Call to abstract method $method at $file, line $line"; } -sub class { - return scalar(caller); -} +sub class { return scalar(caller); } 1; diff --git a/src/perlmods/OpenSRF/AppSession.pm b/src/perlmods/OpenSRF/AppSession.pm index f8b46ee..e0b03a2 100644 --- a/src/perlmods/OpenSRF/AppSession.pm +++ b/src/perlmods/OpenSRF/AppSession.pm @@ -209,6 +209,11 @@ sub create { my $r_id = $conf->$app->transport_target || die("No remote id for $app!"); + my $peer_handle = OpenSRF::Transport::PeerHandle->retrieve("client"); + if( ! $peer_handle ) { + $peer_handle = OpenSRF::Transport::PeerHandle->retrieve("system_client"); + } + my $self = bless { app_name => $app, #client_auth => $auth, #recv_queue => [], @@ -218,8 +223,7 @@ sub create { session_id => $sess_id, remote_id => $r_id, orig_remote_id => $r_id, - # peer_handle => OpenSRF::Transport::PeerHandle->retrieve($app), - peer_handle => OpenSRF::Transport::PeerHandle->retrieve("client"), + peer_handle => $peer_handle, session_threadTrace => 0, } => $class; @@ -253,6 +257,11 @@ sub connect { my $self = shift; my $class = ref($self) || $self; + if ( ref( $self ) and $self->state && $self->state == CONNECTED ) { + $logger->transport("ABC AppSession already connected", DEBUG ); + } else { + $logger->transport("ABC AppSession not connected, connecting..", DEBUG ); + } return $self if ( ref( $self ) and $self->state && $self->state == CONNECTED ); my $app = shift; @@ -281,6 +290,9 @@ sub connect { sub finish { my $self = shift; + if( ! $self->session_id ) { + return 0; + } #$self->disconnect if ($self->endpoint == CLIENT); for my $ses ( @_CLIENT_CACHE ) { if ($ses->[2]->session_id eq $self->session_id) { @@ -758,7 +770,9 @@ sub resend { my $self = shift; OpenSRF::Utils::Logger->debug( "I'm resending the request for threadTrace ". $self->threadTrace, DEBUG); - OpenSRF::Utils::Logger->debug($self->payload->toString,INTERNAL); + if($self->payload) { + OpenSRF::Utils::Logger->debug($self->payload->toString,INTERNAL); + } return $self->session->send('REQUEST', $self->payload, $self->threadTrace ); } diff --git a/src/perlmods/OpenSRF/Application/Demo/Math.pm b/src/perlmods/OpenSRF/Application/Demo/Math.pm index 2e240b8..fe1717c 100644 --- a/src/perlmods/OpenSRF/Application/Demo/Math.pm +++ b/src/perlmods/OpenSRF/Application/Demo/Math.pm @@ -74,7 +74,6 @@ sub send_request { $e->throw(); }; - $log->error("response is $resp"); if ( defined($resp) and $resp and $resp->class->isa('OpenSRF::DomainObject::oilsResult') ){ $log->debug( "Math server returned " . $resp->toString(1), INTERNAL ); diff --git a/src/perlmods/OpenSRF/DOM/Element/domainObject.pm b/src/perlmods/OpenSRF/DOM/Element/domainObject.pm index 4d9fd2a..f08e041 100644 --- a/src/perlmods/OpenSRF/DOM/Element/domainObject.pm +++ b/src/perlmods/OpenSRF/DOM/Element/domainObject.pm @@ -43,7 +43,11 @@ sub AUTOLOAD { return $self->$meth(@args); } catch Error with { my $e = shift; - OpenSRF::Utils::Logger->error( $@ . $e); + if( $e ) { + OpenSRF::Utils::Logger->error( $@ . $e); + } else { + OpenSRF::Utils::Logger->error( $@ ); + } die $@; }; diff --git a/src/perlmods/OpenSRF/DomainObject.pm b/src/perlmods/OpenSRF/DomainObject.pm index 9e7d960..4dc4258 100644 --- a/src/perlmods/OpenSRF/DomainObject.pm +++ b/src/perlmods/OpenSRF/DomainObject.pm @@ -66,13 +66,8 @@ sub _attr_get_set { my $self = shift; my $part = shift; - $logger->debug( "DomainObject:_attr_get_set: ". $self->toString, INTERNAL ); - my $node = $self->attrNode($part); - $logger->debug( "DomainObject:_attr_get_set " . $node->toString(), INTERNAL ) if ($node); - - if (defined(my $new_value = shift)) { if (defined $node) { my $old_val = $node->getAttribute( "value" ); diff --git a/src/perlmods/OpenSRF/DomainObject/oilsMessage.pm b/src/perlmods/OpenSRF/DomainObject/oilsMessage.pm index a77fd9c..268141c 100644 --- a/src/perlmods/OpenSRF/DomainObject/oilsMessage.pm +++ b/src/perlmods/OpenSRF/DomainObject/oilsMessage.pm @@ -334,7 +334,9 @@ sub do_client { $self->payload->throw(); } - $log->debug("Passing to OpenSRF::Application::handler()\n" . $self->payload->toString(1), INTERNAL); + if( $self->payload ) { + $log->debug("Passing to OpenSRF::Application::handler()\n" . $self->payload->toString(1), INTERNAL); + } $log->debug("oilsMessage passing to Application: " . $self->type." : ".$session->remote_id, INFO ); return 1; diff --git a/src/perlmods/OpenSRF/System.pm b/src/perlmods/OpenSRF/System.pm index e746c8d..cf2d2d8 100644 --- a/src/perlmods/OpenSRF/System.pm +++ b/src/perlmods/OpenSRF/System.pm @@ -10,7 +10,7 @@ use OpenSRF::Utils::LogServer; use OpenSRF::DOM; use OpenSRF::EX qw/:try/; use POSIX ":sys_wait_h"; -use OpenSRF::Utils::Config; +use OpenSRF::Utils::Config; use strict; =head2 Name/Description @@ -62,8 +62,6 @@ sub set_config { my $config = OpenSRF::Utils::Config->load( config_file => "/pines/conf/opensrf.conf" ); - warn "Setting config " . $config->transport->implementation ."\n"; - if( ! $config ) { throw OpenSRF::EX::Config "System could not load config"; } my $tran = $config->transport->implementation; @@ -194,7 +192,14 @@ sub bootstrap_client { my $self = __PACKAGE__->instance(); my $config = OpenSRF::Utils::Config->current; - my $app = "client"; + my $client_type = shift; + my $app; + + if( defined($client_type) and $client_type ) { + $app = $client_type; + } else { + $app = "client"; + } OpenSRF::Transport::PeerHandle->construct( $app ); diff --git a/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm b/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm index fc1afb8..ddbd231 100644 --- a/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm +++ b/src/perlmods/OpenSRF/Transport/SlimJabber/Client.pm @@ -16,7 +16,7 @@ OpenSRF::Transport::SlimJabber::Client Home-brewed slimmed down jabber connection agent. Supports SSL connections with a config file options: - transport->server->port # the ssl port + transport->server->sslport # the ssl port transport->server->ssl # is this ssl? =cut @@ -58,14 +58,20 @@ sub new { my $conf = OpenSRF::Utils::Config->current; - my $host = $conf->transport->server->primary; + my $host; + my $port = $conf->transport->server->port; my $username = $params{'username'} || return undef; my $resource = $params{'resource'} || return undef; my $password = $params{'password'} || return undef; - my $jid = "$username\@$host\/$resource"; + if( $params{host} ) { + $host = $params{host}; + } else { + $host = $conf->transport->server->system_primary; + } + my $jid = "$username\@$host\/$resource"; my $self = bless {} => $class; @@ -501,7 +507,7 @@ sub initialize { sub construct { my( $class, $app ) = @_; - $logger->transport("Constructing new Jabber connection for $app", INTERNAL ); + $logger->transport("Constructing new Jabber connection for $app, my class $class", INTERNAL ); $class->peer_handle( $class->new( $app )->initialize() ); } diff --git a/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm b/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm index b65ab35..db969e2 100644 --- a/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm +++ b/src/perlmods/OpenSRF/Transport/SlimJabber/PeerConnection.pm @@ -29,7 +29,7 @@ sub retrieve { my( $class, $app ) = @_; my @keys = keys %apps_hash; OpenSRF::Utils::Logger->transport( - "Requesting peer for $app and we have @keys", INTERNAL ); + "Requesting peer for $app and we have @keys", INFO ); return $apps_hash{$app}; } @@ -47,15 +47,23 @@ sub new { my $username = $config->transport->users->$app; my $password = $config->transport->auth->password; my $resource = $config->env->hostname . "_$$"; + my $server; + + my $host; + if( $app eq "client" ) { + $host = $config->transport->server->client_primary; + } else { + $host = ""; + } OpenSRF::EX::Config->throw( "JPeer could not load all necesarry values from config" ) unless ( $username and $password and $resource ); - my $self = __PACKAGE__->SUPER::new( username => $username, resource => $resource, password => $password, + host => $host, ); bless( $self, $class ); diff --git a/src/perlmods/OpenSRF/UnixServer.pm b/src/perlmods/OpenSRF/UnixServer.pm index 8164974..18ad380 100644 --- a/src/perlmods/OpenSRF/UnixServer.pm +++ b/src/perlmods/OpenSRF/UnixServer.pm @@ -149,7 +149,7 @@ sub child_init_hook { $logger->transport( "Creating PeerHandle from UnixServer child_init_hook", INTERNAL ); OpenSRF::Transport::PeerHandle->construct( $self->app() ); - my $peer_handle = OpenSRF::System::bootstrap_client(); + my $peer_handle = OpenSRF::System::bootstrap_client("system_client"); OpenSRF::Application->application_implementation->child_init if (OpenSRF::Application->application_implementation->can('child_init')); return $peer_handle; -- 2.11.0